static void winch() { int oldLI = LI, oldCO = CO, i; register struct WinDesc *cw; getwindowsz(); 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(flags.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); } } } }
int process_command(Point mouse) { button *bp = buttons; while (bp && (bp->state == Hidden || !ptinrect(mouse, bp->r))) bp = bp->next; if (!bp) return 0; if (bp == undo_button) { if (nhist > 0) { nhist--; show_hist(); } } else if (bp == startover_button) { unfreeze(); nhist = 0; show_hist(); } else if (bp == freeze_button) { switch (state) { case Live: state = Frozen; freeze_button->state = On; paint_fancy_button(freeze_button); break; case Frozen: unfreeze(); break; default: break; } flush_screen(); } else if (bp == primary_buttons[Cat_change_color].b || bp == primary_buttons[Cat_change_look].b || bp == primary_buttons[Cat_change_shape].b) { set_category(bp); } else { if (bp && nhist < MAXHIST) { history[nhist++] = bp; show_hist(); } } flush_screen(); return 1; }
/* * Draw the current screen. */ void draw_screen(void) { button *bp = buttons; clear_screen_to_background(); while (bp) { if (bp->state != Hidden && bp->category == Cat_none) { paint_fancy_button(bp); flush_screen(); } bp = bp->next; } set_category(current_primary_button); show_hist(); write_video_frame_zoom(video_r.min, &frames[nhist], VIDEO_ZOOM); show_cursor(); flush_screen(); }
void doflashscreen (void) { #if 0 flashscreen = 10; init_colors (); picasso_refresh (); reset_drawing (); flush_screen (gfxvidinfo.outbuffer, 0, 0); #endif }
/** * Display inventory items. */ void inventory () { int old_fg, old_bg; int n; /* screen is white with black text */ old_fg = game.color_fg; old_bg = game.color_bg; game.color_fg = 0; game.color_bg = 15; clear_screen (game.color_bg); print_text (YOUHAVE_MSG, 0, YOUHAVE_X, YOUHAVE_Y, 40, STATUS_FG, STATUS_BG); /* FIXME: doesn't check if objects overflow off screen... */ intobj = malloc (4 + game.num_objects); memset(intobj, 0, (4 + game.num_objects)); n = show_items (); if (getflag (F_status_selects_items)) { print_text (SELECT_MSG, 0, SELECT_X, SELECT_Y, 40, STATUS_FG, STATUS_BG); } else { print_text (ANY_KEY_MSG, 0, ANY_KEY_X, ANY_KEY_Y, 40, STATUS_FG, STATUS_BG); } flush_screen (); /* If flag 13 is set, we want to highlight & select an item. * opon selection, put objnum in var 25. Then on esc put in * var 25 = 0xff. */ if (getflag (F_status_selects_items)) select_items (n); free (intobj); if (!getflag (F_status_selects_items)) wait_any_key(); clear_screen (0); write_status (); show_pic (); game.color_fg = old_fg; game.color_bg = old_bg; game.has_prompt = 0; flush_lines (game.line_user_input, 24); }
void hsyncstuff (void) //only generate Interrupts when //writebuffer is complete flushed //check state of lwin rwin { //static int keycheck = 0; #if 0 // DISABLED -- OLD AHI VERSION? #ifdef AHI { //begin ahi_sound static int count; if (ahi_on) { count++; //15625/count freebuffer check if(count > ahi_pollrate) { ahi_updatesound (1); count = 0; } } } //end ahi_sound #endif #endif #if 0 // DISABLED FOR NOW #ifdef PARALLEL_PORT keycheck++; if(keycheck >= 1000) { if (prtopen) flushprtbuf (); { if (flashscreen > 0) { flashscreen--; if (flashscreen == 0) { init_colors (); reset_drawing (); picasso_refresh (); flush_screen (gfxvidinfo.outbuffer, 0, 0); } } } keycheck = 0; } if (currprefs.parallel_autoflush_time && !currprefs.parallel_postscript_detection) { parflush++; if (parflush / ((currprefs.ntscmode ? MAXVPOS_NTSC : MAXVPOS_PAL) * MAXHPOS_PAL / maxhpos) >= currprefs.parallel_autoflush_time * 50) { flushprinter (); parflush = 0; } } #endif #endif }
static void vpline(boolean nonblocking, boolean norepeat, const char *line, va_list the_args) { const char *pbuf; boolean repeated; int lastline; lastline = curline - 1; if (lastline < 0) lastline += MSGCOUNT; if (!line || !*line) return; pbuf = msgvprintf(line, the_args, TRUE); /* Remove all tabs from the string and replace them with spaces. Some messages generated from menu use will have formatting tabs in them, but these look ugly in the message buffer (and also mess with the wrapping logic). */ char *untabber = (char*)pbuf; while (*untabber != '\0') { if (*untabber == '\t') *untabber = ' '; untabber++; } line = pbuf; repeated = !strcmp(line, toplines[lastline]); if (norepeat && repeated) return; if (turnstate.vision_full_recalc) vision_recalc(0); if (u.ux) flush_screen(); if (repeated) { toplines_count[lastline]++; } else { strcpy(toplines[curline], line); toplines_count[curline] = 1; curline++; curline %= MSGCOUNT; } if (nonblocking) (*windowprocs.win_print_message_nonblocking) (moves, line); else print_message(moves, line); }
/* * Draw the current screen. */ void draw_screen(void) { button *bp = buttons; while (bp) { paint_button(bp); bp = bp->next; } set_font(title_font); write_centered_string(title_r, White, title); set_font(subtitle_font); write_centered_string(subtitle_r, White, subtitle); set_font(text_font); show_cursor(); flush_screen(); }
int getpos(coord *cc, boolean force, const char *goal) { int rv = -1, x, y; x = cc->x; y = cc->y; flush_screen(); do { rv = (*windowprocs.win_getpos)(&x, &y, force, goal); } while (force && (rv == -1 || x < 1 || y < 1 || x > COLNO || y > ROWNO)); log_getpos(rv, x, y); cc->x = x; cc->y = y; return rv; }
void cibyl_set_screen_size (display_zoom zoom) { switch (zoom) { case NORMAL: x_corr = (screen_width - GFX_WIDTH) / 2; y_corr = (screen_height - (GFX_HEIGHT + 20)) / 2; // +20 => input row gfx_cibyl.put_block = cibyl_put_block; gfx_cibyl.put_pixels = cibyl_put_pixels; break; case STRETCHED_VERTICALLY: x_corr = (screen_width - (GFX_WIDTH + GFX_WIDTH / 2)) / 2; y_corr = (screen_height - (GFX_HEIGHT * 2 + 20)) / 2; gfx_cibyl.put_block = cibyl_put_block_x1_5; gfx_cibyl.put_pixels = cibyl_put_pixels_x1_5; break; case DOUBLE_SIZE: x_corr = (screen_width - GFX_WIDTH * 2) / 2; y_corr = (screen_height - (GFX_HEIGHT * 2 + 20)) / 2; gfx_cibyl.put_block = cibyl_put_block_x2; gfx_cibyl.put_pixels = cibyl_put_pixels_x2; break; default: /* Should never happen */ break; } if (x_corr < 0) x_corr = 0; if (y_corr < 0) y_corr = 0; NOPH_Graphics_setColor_int(graphics, 0xff666666); NOPH_Graphics_fillRect(graphics, 0, 0, screen_width, screen_height); flush_screen(); put_screen(); cur_zoom = zoom; }
void show_fps(void) { struct timeval now; long long nowms; int ms; float fps; char buf[30]; gettimeofday(&now, 0); nowms = now.tv_sec*1000 + now.tv_usec/1000; if (times_valid) { ms = nowms - times[next_time]; fps = 1000.0/((float)ms/10.0); snprintf(buf, sizeof(buf), "%5.1f frames/sec.", fps); set_font(big_button_font); write_string(fps_r, White, buf); flush_screen(); } times[next_time] = nowms; next_time = (next_time + 1) % NFRAME; if (next_time == 0) times_valid = 1; }
/* * Adjust the top-level button layouts for a new category. */ static void set_category(button *b) { button *bp; int cat; int pb, sb, rb; clear_to_background(button_field_r); current_primary_button = b; for (bp = buttons; bp; bp = bp->next) { if (bp->category == Cat_none) continue; if (bp->category == current_primary_button->category) bp->state = Off; else bp->state = Hidden; } /* * set the primary button positions for this primary selection. */ for (cat=Cat_change_color; cat <= Cat_change_shape; cat++) { button *b = primary_buttons[cat].b; b->r.min.x = PRIMARY_X; b->r.max.x = b->r.min.x + DX(b->pm[On].r); b->r.min.y = primary_buttons[cat].primary_bottom[current_primary_button->category]; b->r.max.y = b->r.min.y + DY(b->pm[On].r); b->state = Off; paint_fancy_button(b); flush_screen(); } current_primary_button->state = On; cat = current_primary_button->category; for (bp = buttons; bp; bp = bp->next) { if (bp->category != cat) continue; paint_fancy_button(bp); flush_screen(); } /* draw lines */ #define LSC_RED (SETRGB(252,62,50)) pb = primary_buttons[cat].primary_bottom[cat]; sb = primary_buttons[cat].secondary_bottom + BUTTON_SEP; rb = PRIMARY_X+DX(current_primary_button->pm[On].r) - 2; fill_rect((Rectangle){{PRIMARY_X, sb+10}, {PRIMARY_X+2, pb}}, LSC_RED); fill_rect((Rectangle){{rb, sb+10}, {rb+2, pb}}, LSC_RED); fill_rect((Rectangle){{PRIMARY_X+10, sb}, {rb-10, sb+2}}, LSC_RED); /* * Add a rounded corner to the lower left of the secondary area. We * Simply steal the lower 10x10 pixels of a secondary button, a kludge. */ write_pixmap((Point){PRIMARY_X, sb}, (Rectangle){{0,0}, {10,10}}, sample_secondary_button->pm[Off]); flush_screen(); }
/* * Make the mail daemon run through the dungeon. The daemon will run over * any monsters that are in its path, but will replace them later. Return * FALSE if the md gets stuck in a position where there is a monster. Return * TRUE otherwise. */ STATIC_OVL boolean md_rush(struct monst *md, register int tx, register int 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 */ /* * 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); } /* * At the beginning and exit of this loop, md is not placed in the * 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; } } /* 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; /* 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 */ verbalize("%s", 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 */ /* 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); } /* * Check for a monster at our stopping position (this is possible, but * 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."); 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; } place_monster(md, fx, fy); /* place at final spot */ newsym(fx, fy); flush_screen(0); delay_output(); /* wait a little bit */ return TRUE; }
enum nh_restore_status nh_restore_game(int fd, struct nh_window_procs *rwinprocs, boolean force_replay) { int playmode, irole, irace, igend, ialign; char namebuf[PL_NSIZ]; /* some compilers can't cope with the fact that all subsequent stores to error * are not dead, but become important if the error handler longjumps back * volatile is required to prevent invalid optimization based on that wrong * assumption. */ volatile enum nh_restore_status error = GAME_RESTORED; if (fd == -1) return ERR_BAD_ARGS; switch (nh_get_savegame_status(fd, NULL)) { case LS_INVALID: return ERR_BAD_FILE; case LS_DONE: return ERR_GAME_OVER; case LS_CRASHED: force_replay = TRUE; break; case LS_IN_PROGRESS: return ERR_IN_PROGRESS; case LS_SAVED: break; /* default, everything is A-OK */ } if (!api_entry_checkpoint()) goto error_out; error = ERR_BAD_FILE; replay_set_logfile(fd); /* store the fd and try to get a lock or exit */ replay_begin(); program_state.restoring = TRUE; iflags.disable_log = TRUE; /* don't log any of the commands, they're already in the log */ /* Read the log header for this game. */ replay_read_newgame(&turntime, &playmode, namebuf, &irole, &irace, &igend, &ialign); /* set special windowprocs which will autofill requests for user input * with data from the log file */ replay_setup_windowprocs(rwinprocs); startup_common(namebuf, playmode); u.initrole = irole; u.initrace = irace; u.initgend = igend; u.initalign = ialign; if (!force_replay) { error = ERR_RESTORE_FAILED; replay_run_cmdloop(TRUE, FALSE, TRUE); replay_jump_to_endpos(); if (!dorecover_fd(fd)) { replay_undo_jump_to_endpos(); goto error_out2; } replay_undo_jump_to_endpos(); wd_message(); program_state.game_running = 1; post_init_tasks(); } else { replay_run_cmdloop(TRUE, TRUE, FALSE); /* option setup only */ newgame(); /* try replaying instead */ error = ERR_REPLAY_FAILED; replay_run_cmdloop(FALSE, FALSE, TRUE); replay_sync_save(); } /* restore standard window procs */ replay_restore_windowprocs(); program_state.restoring = FALSE; iflags.disable_log = FALSE; /* clean up data used for replay */ replay_end(); log_truncate(); log_init(); /* must be called before we start writing to the log */ /* info might not have reached the ui while alternate window procs were set */ doredraw(); /* nh_start_game() does this via newgame(), but since this function doesn't * call newgame(), we have to do it here instead. */ notify_levelchange(NULL); bot(); flush_screen(); was_on_elbereth = !sengr_at("Elbereth", u.ux, u.uy); /* force botl update later */ welcome(FALSE); realtime_messages(TRUE, TRUE); update_inventory(); api_exit(); return GAME_RESTORED; error_out2: api_exit(); error_out: replay_restore_windowprocs(); program_state.restoring = FALSE; iflags.disable_log = FALSE; replay_end(); unlock_fd(fd); if (error == ERR_RESTORE_FAILED) { raw_printf("Restore failed. Attempting to replay instead.\n"); error = nh_restore_game(fd, rwinprocs, TRUE); } return error; }
void newgame() { int i; #ifdef MFLOPPY gameDiskPrompt(); #endif flags.ident = 1; for (i = 0; i < NUMMONS; i++) mvitals[i].mvflags = mons[i].geno & G_NOCORPSE; init_objects(); /* must be before u_init() */ flags.pantheon = -1; /* role_init() will reset this */ role_init(); /* must be before init_dungeons(), u_init(), * and init_artifacts() */ init_dungeons(); /* must be before u_init() to avoid rndmonst() * creating odd monsters for any tins and eggs * in hero's initial inventory */ init_artifacts(); /* before u_init() in case $WIZKIT specifies * any artifacts */ u_init(); #ifndef NO_SIGNAL (void) signal(SIGINT, (SIG_RET_TYPE) done1); #endif #ifdef NEWS if(iflags.news) display_file(NEWS, FALSE); #endif load_qtlist(); /* load up the quest text info */ /* quest_init();*/ /* Now part of role_init() */ mklev(); u_on_upstairs(); vision_reset(); /* set up internals for level (after mklev) */ check_special_room(FALSE); flags.botlx = 1; /* Move the monster from under you or else * makedog() will fail when it calls makemon(). * - ucsfcgl!kneller */ 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); } #ifdef INSURANCE save_currentstate(); #endif program_state.something_worth_saving++; /* useful data now exists */ #if defined(RECORD_REALTIME) || defined(REALTIME_ON_BOTL) /* Start the timer here */ realtime_data.realtime = (time_t)0L; #if defined(BSD) && !defined(POSIX_TYPES) (void) time((long *)&realtime_data.restoretime); #else (void) time(&realtime_data.restoretime); #endif #endif /* RECORD_REALTIME || REALTIME_ON_BOTL */ /* Success! */ welcome(TRUE); return; }
/* perform the command given by cmdidx (in index into cmdlist in cmd.c) * returns -1 if the command completes */ int command_input(int cmdidx, int rep, struct nh_cmd_arg *arg) { boolean didmove = FALSE; if (multi >= 0 && occupation) handle_occupation(); else if (multi == 0 || (multi > 0 && cmdidx != -1)) { saved_cmd = cmdidx; do_command(cmdidx, rep, TRUE, arg); } else if (multi > 0) { /* allow interruption of multi-turn commands */ if (rep == -1) { nomul(0, NULL); return READY_FOR_INPUT; } if (flags.mv) { if (multi < COLNO && !--multi) flags.travel = iflags.travel1 = flags.mv = flags.run = 0; if (!domove(u.dx, u.dy, 0)) { /* Don't use a move when travelling into an obstacle. */ flags.move = FALSE; nomul(0, NULL); } } else do_command(saved_cmd, multi, FALSE, arg); } /* no need to do anything here for multi < 0 */ if (u.utotype) /* change dungeon level */ deferred_goto(); /* after rhack() */ /* !flags.move here: multiple movement command stopped */ else if (!flags.move || !flags.mv) iflags.botl = 1; if (vision_full_recalc) vision_recalc(0); /* vision! */ /* when running in non-tport mode, this gets done through domove() */ if ((!flags.run || iflags.runmode == RUN_TPORT) && (multi && (!flags.travel ? !(multi % 7) : !(moves % 7L)))) { if (flags.run) iflags.botl = 1; flush_screen(); } didmove = flags.move; if (didmove) { you_moved(); } /* actual time passed */ /****************************************/ /* once-per-player-input things go here */ /****************************************/ xmalloc_cleanup(); iflags.next_msg_nonblocking = FALSE; /* prepare for the next move */ flags.move = 1; pre_move_tasks(didmove); do_delay_msg(); if (multi == 0 && !occupation) { flush_screen(); /* Flush screen buffer */ maybe_tutorial(); } return -1; }
void missclick_pause(void) { flush_screen(); usleep(200*1000); /* leave button on for 200 ms */ }
/* 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. * Wand types get complex because they must be converted to adtyps for * determining such things as fire resistance. Adtyps get complex in that * they don't supply enough information--was it a player or a monster that * did it, and with a wand, spell, or breath weapon? Object types share both * these disadvantages.... * * The descr argument should be used to describe the explosion. It should be * a string suitable for use with an(). * raylevel is used for explosions caused by skilled wand usage (0=no wand) */ void explode(int x, int y, int type, /* the same as in zap.c */ int dam, char olet, int expltype, const char *descr, int raylevel) { int i, j, k, damu = dam; boolean visible, any_shield, resist_death; resist_death = FALSE; int uhurt = 0; /* 0=unhurt, 1=items damaged, 2=you and items damaged */ const char *str; const char *dispbuf = ""; /* lint suppression; I think the code's OK */ boolean expl_needs_the = TRUE; int idamres, idamnonres; struct monst *mtmp; uchar adtyp; int explmask[3][3]; /* 0=normal explosion, 1=do shieldeff, 2=do nothing */ boolean shopdamage = FALSE; #if 0 /* Damage reduction from wand explosions */ if (olet == WAND_CLASS) /* retributive strike */ 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; } #endif if (olet == MON_EXPLODE) { str = descr; adtyp = AD_PHYS; if (Hallucination) { int name = rndmonidx(); dispbuf = msgcat(s_suffix(monnam_for_index(name)), " explosion"); expl_needs_the = !monnam_is_pname(name); } else { dispbuf = str; } } else { int whattype = abs(type) % 10; adtyp = whattype + 1; boolean done = FALSE, hallu = Hallucination; if (hallu) { do { whattype = rn2(8); } while (whattype == 3); } tryagain: switch (whattype) { case 0: str = "magical blast"; break; case 1: str = olet == BURNING_OIL ? "burning oil" : olet == SCROLL_CLASS ? "tower of flame" : "fireball"; break; case 2: str = "ball of cold"; break; case 3: str = "sleeping gas"; break; case 4: str = (olet == WAND_CLASS) ? "death field" : "disintegration field"; break; case 5: str = "ball of lightning"; break; case 6: str = "poison gas cloud"; break; case 7: str = "splash of acid"; break; default: impossible("explosion base type %d?", type); return; } if (!done) { dispbuf = str; done = TRUE; if (hallu) { whattype = adtyp - 1; goto tryagain; } } } 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] = !!(raylevel >= P_EXPERT || Antimagic); break; case AD_FIRE: explmask[i][j] = !!Fire_resistance; break; case AD_COLD: explmask[i][j] = !!Cold_resistance; break; case AD_SLEE: explmask[i][j] = !!Sleep_resistance; break; case AD_DISN: if (raylevel == P_UNSKILLED && Drain_resistance) resist_death = TRUE; /* why MR doesn't resist general deathfields is beyond me, but... */ if (nonliving(youmonst.data) || is_demon(youmonst.data)) resist_death = TRUE; if (raylevel && Antimagic) resist_death = TRUE; if (raylevel >= P_EXPERT && !Drain_resistance) resist_death = FALSE; explmask[i][j] = (olet == WAND_CLASS) ? !!resist_death : !!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; break; default: impossible("explosion type %d?", adtyp); break; } } /* can be both you and mtmp if you're swallowed */ mtmp = m_at(level, 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] |= (raylevel >= 4 || 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_SLEE: explmask[i][j] |= resists_sleep(mtmp); case AD_DISN: if (raylevel == P_UNSKILLED && resists_drli(mtmp)) resist_death = TRUE; if (nonliving(mtmp->data) || is_demon(mtmp->data)) resist_death = TRUE; if (raylevel && resists_magm(mtmp)) resist_death = TRUE; if (raylevel >= P_EXPERT && !resists_drli(mtmp)) resist_death = FALSE; explmask[i][j] |= (olet == WAND_CLASS) ? resist_death : 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; } } reveal_monster_at(i + x - 1, j + y - 1, TRUE); if (cansee(i + x - 1, j + y - 1)) visible = TRUE; if (explmask[i][j] == 1) any_shield = TRUE; } if (visible) { struct tmp_sym *tsym = tmpsym_init(DISP_BEAM, 0); /* Start the explosion */ for (i = 0; i < 3; i++) for (j = 0; j < 3; j++) { if (explmask[i][j] == 2) continue; tmpsym_change(tsym, dbuf_explosion(expltype, explosion[i][j])); tmpsym_at(tsym, i + x - 1, j + y - 1); } flush_screen(); /* 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 tmpsym_at() and send the shield glyphs * directly to the buffered screen. tmpsym_at() * will clean up the location for us later. */ dbuf_set_effect(i + x - 1, j + y - 1, dbuf_effect(E_MISC, shield_static[k])); } flush_screen(); /* will flush screen and output */ win_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) dbuf_set_effect(i + x - 1, j + y - 1, dbuf_explosion(expltype, explosion[i][j])); } } else { /* delay a little bit. */ win_delay_output(); win_delay_output(); } tmpsym_end(tsym); /* clear the explosion */ } else { if (olet == MON_EXPLODE) { str = "explosion"; } 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; idamres = idamnonres = 0; if (type >= 0) zap_over_floor((xchar) (i + x - 1), (xchar) (j + y - 1), type, &shopdamage); mtmp = m_at(level, 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 (Engulfed && 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 %s%s!", Monnam(mtmp), expl_needs_the ? "the " : "", dispbuf); } 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 (resist(mtmp, olet, 0, FALSE)) { if (cansee(i + x - 1, j + y - 1)) pline("%s resists %s%s!", Monnam(mtmp), expl_needs_the ? "the " : "", dispbuf); mdam = dam / 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; if (adtyp == AD_MAGM && raylevel >= P_EXPERT && resists_magm(mtmp)) mdam = (mdam + 1) / 2; if (adtyp == AD_SLEE && raylevel) { sleep_monst(mtmp, mdam, WAND_CLASS); mdam = 0; } if (adtyp == AD_DISN && raylevel) { if (nonliving(mtmp->data) || is_demon(mtmp->data) || resists_magm(mtmp) || raylevel == P_UNSKILLED) { /* monster is deathresistant or raylevel==unskilled, since monster apparently failed to resist earlier, monster must be vulnerable to drli */ /* FIXME: make a generic losexp() for monsters */ mdam = dice(2, 6); if (cansee(i + x - 1, j + y - 1)) pline("%s suddenly seems weaker!", Monnam(mtmp)); mtmp->mhpmax -= mdam; if (mtmp->m_lev == 0) mdam = mtmp->mhp; else mtmp->m_lev--; } else mdam = mtmp->mhp; /* instadeath */ } mtmp->mhp -= mdam; mtmp->mhp -= (idamres + idamnonres); } if (mtmp->mhp <= 0) { /* KMH -- Don't blame the player for pets killing gas spores */ if (!flags.mon_moving) killed(mtmp); else monkilled(mtmp, "", (int)adtyp); } else if (!flags.mon_moving) setmangry(mtmp); } /* Do your injury last */ if (uhurt) { if ((type >= 0 || adtyp == AD_PHYS) && /* gas spores */ flags.verbose && olet != SCROLL_CLASS) pline("You are caught in %s%s!", expl_needs_the ? "the " : "", dispbuf); /* do property damage first, in case we end up leaving bones */ if (adtyp == AD_FIRE) burn_away_slime(); if (u.uinvulnerable) { damu = 0; pline("You are unharmed!"); } else if (Half_physical_damage && adtyp == AD_PHYS) damu = (damu + 1) / 2; else if (raylevel) { if (adtyp == AD_MAGM && Antimagic) damu = (damu + 1) / 2; if (adtyp == AD_SLEE) { helpless(damu, hr_asleep, "sleeping", NULL); damu = 0; } if (adtyp == AD_DISN) { if (nonliving(youmonst.data) || is_demon(youmonst.data) || Antimagic || raylevel == P_UNSKILLED) { losexp("drained by a death field",FALSE); damu = 0; } else { done(DIED, "killed by a death field"); damu = 0; /* lifesaved */ } } } if (adtyp == AD_FIRE) { burnarmor(&youmonst); set_candles_afire(); } 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; } if (u.uhp <= 0 || (Upolyd && u.mh <= 0)) { int death = adtyp == AD_FIRE ? BURNING : DIED; const char *killer; if (olet == MON_EXPLODE) { killer = killer_msg(death, an(str)); } else if (type >= 0 && olet != SCROLL_CLASS) { /* check whether or not we were the source of the explosion */ if (!flags.mon_moving) killer = msgprintf("caught %sself in %s own %s", uhim(), uhis(), str); else killer = msgprintf("killed by a %s", str); } else if (!strcmp(str, "burning oil")) { /* This manual check hack really sucks */ killer = killer_msg(death, str); } else { killer = killer_msg(death, an(str)); } /* Known BUG: BURNING suppresses corpse in bones data, but done does not handle killer reason correctly */ if (Upolyd) { rehumanize(death, killer); } else { done(death, killer); } } exercise(A_STR, 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 */ wake_nearto(x, y, i); }
void pline VA_DECL(const char *, line) #endif /* USE_STDARG | USE_VARARG */ { /* start of vpline() or of nested block in USE_OLDARG's pline() */ char pbuf[3 * BUFSZ]; int ln; xchar msgtyp; /* Do NOT use VA_START and VA_END in here... see above */ if (!line || !*line) return; #ifdef HANGUPHANDLING if (program_state.done_hup) return; #endif 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; } #ifndef MAC if (no_repeat && !strcmp(line, toplines)) return; #endif /* MAC */ if (vision_full_recalc) vision_recalc(0); if (u.ux) flush_screen(1); /* %% */ msgtyp = msgtype_type(line); if (msgtyp == MSGTYP_NOSHOW) return; if (msgtyp == MSGTYP_NOREP && !strcmp(line, prevmsg)) return; putstr(WIN_MESSAGE, 0, line); /* this gets cleared after every pline message */ iflags.last_msg = PLNMSG_UNKNOWN; strncpy(prevmsg, line, BUFSZ); if (msgtyp == MSGTYP_STOP) display_nhwindow(WIN_MESSAGE, TRUE); /* --more-- */ #if !(defined(USE_STDARG) || defined(USE_VARARGS)) /* provide closing brace for the nested block which immediately follows USE_OLDARGS's VA_DECL() */ VA_END(); #endif }
static void newgame(void) { int i; flags.ident = 1; for (i = 0; i < NUMMONS; i++) mvitals[i].mvflags = mons[i].geno & G_NOCORPSE; init_objects(); /* must be before u_init() */ flags.pantheon = -1;/* role_init() will reset this */ role_init(); /* must be before init_dungeons(), u_init(), * and init_artifacts() */ init_dungeons(); /* must be before u_init() to avoid rndmonst() * creating odd monsters for any tins and eggs * in hero's initial inventory */ init_artifacts(); u_init(); /* struct you must have some basic data for mklev to work right */ load_qtlist(); /* load up the quest text info */ level = mklev(&u.uz); u_init_inv_skills();/* level must be valid to create items */ u_on_upstairs(); vision_reset(); /* set up internals for level (after mklev) */ check_special_room(FALSE); iflags.botl = 1; /* Move the monster from under you or else * makedog() will fail when it calls makemon(). * - ucsfcgl!kneller */ if (MON_AT(level, u.ux, u.uy)) mnexto(m_at(level, u.ux, u.uy)); makedog(); doredraw(); if (Role_if(PM_CONVICT)) { setworn(mkobj(level, CHAIN_CLASS, TRUE), W_CHAIN); setworn(mkobj(level, BALL_CLASS, TRUE), W_BALL); uball->spe = 1; /* attach the ball to the hero */ placebc(); } /* help the window port get it's display charset/tiles sorted out */ notify_levelchange(NULL); if (flags.legacy) { flush_screen(); com_pager(Role_if(PM_CONVICT) ? 199 : 1); } /* Stop autoexplore revisiting the entrance stairs (or position). */ level->locations[u.ux][u.uy].mem_stepped = 1; program_state.something_worth_saving++; /* useful data now exists */ historic_event(FALSE, "entered the Dungeons of Doom to retrieve the Amulet of Yendor!"); /* Success! */ welcome(TRUE); maybe_tutorial(); /* Prepare for the first move. */ flags.move = 0; set_wear(); pickup(1); log_command_result(); program_state.game_running = TRUE; youmonst.movement = NORMAL_SPEED; /* give the hero some movement points */ realtime_tasks(); post_init_tasks(); return; }