void Screen::PrintInv(WINDOW * const window, Inventory * const inv) const { werase(window); wstandend(window); switch ( inv->Kind() ) { case DWARF: mvwaddstr(window, 2, 7, "Head\n Right hand\n "); waddstr(window, "Left hand\n Body\n "); waddstr(window, "Legs"); break; case WORKBENCH: mvwaddstr(window, 2, 4, "Product"); break; } mvwprintw(window, 2+inv->Size(), 40, "All weight: %6hu mz", inv->Weight()); QString str; for (ushort i=0; i<inv->Size(); ++i) { mvwprintw(window, 2+i, 12, "%c)", 'a'+i); if ( inv->Number(i) ) { wcolor_set(window, Color(inv->GetInvKind(i), inv->GetInvSub(i)), NULL); wprintw(window, "[%c]%s", CharName( inv->GetInvKind(i), inv->GetInvSub(i) ), qPrintable(inv->InvFullName(str, i)) ); if ( 1<inv->Number(i) ) { waddstr(window, qPrintable(inv->NumStr(str, i))); } if ( ""!=inv->GetInvNote(str, i) ) { waddstr(window, qPrintable((" ~:"+(( str.size()<24 ) ? str : str.left(13)+"...")))); } wstandend(window); mvwprintw(window, 2+i, 53, "%5hu mz", inv->GetInvWeight(i)); } } wcolor_set(window, Color(inv->Kind(), inv->Sub()), NULL); box(window, 0, 0); (void)wmove(window, 0, 1); if ( player->PlayerInventory()==inv ) { wprintw(window, "[%c]Your inventory", CharName(inv->Kind(), inv->Sub())); } else { wprintw(window, "[%c]%s", CharName(inv->Kind(), inv->Sub()), qPrintable(inv->FullName(str))); } wnoutrefresh(window); }
static void print_footer (const char *fn) { char *footer_str = NULL; int i = 0; footer_str = (char *) malloc (sizeof (char) * (COLS + 2)); for (i = 0; i < COLS; i++) { footer_str[i] = '-'; } /* * ("---[ editing: %s ]---\n", fn); */ footer_str[COLS] = '\n'; footer_str[COLS + 1] = '\0'; wattron (win, A_REVERSE); mvwprintw (win, LINES - 2, 0, footer_str); wstandend (win); free (footer_str); }
int standend(void) { (void) wstandend(stdscr); return (1); }
static int addstr4(SCR *sp, const void *str, size_t len, int wide) { WINDOW *win; size_t y, x; int iv; win = CLSP(sp) ? CLSP(sp) : stdscr; /* * If ex isn't in control, it's the last line of the screen and * it's a split screen, use inverse video. */ iv = 0; getyx(win, y, x); __USE(x); if (!F_ISSET(sp, SC_SCR_EXWROTE) && y == RLNO(sp, LASTLINE(sp)) && IS_SPLIT(sp)) { iv = 1; (void)wstandout(win); } #ifdef USE_WIDECHAR if (wide) { if (waddnwstr(win, str, len) == ERR) return (1); } else #endif if (waddnstr(win, str, len) == ERR) return (1); if (iv) (void)wstandend(win); return (0); }
/* Display a register in a window. If hilite is TRUE, then the value will be displayed in reverse video. */ static void tui_display_register (struct tui_data_element *data, struct tui_gen_win_info *win_info) { if (win_info->handle != (WINDOW *) NULL) { int i; if (data->highlight) /* We ignore the return value, casting it to void in order to avoid a compiler warning. The warning itself was introduced by a patch to ncurses 5.7 dated 2009-08-29, changing this macro to expand to code that causes the compiler to generate an unused-value warning. */ (void) wstandout (win_info->handle); wmove (win_info->handle, 0, 0); for (i = 1; i < win_info->width; i++) waddch (win_info->handle, ' '); wmove (win_info->handle, 0, 0); if (data->content) waddstr (win_info->handle, data->content); if (data->highlight) /* We ignore the return value, casting it to void in order to avoid a compiler warning. The warning itself was introduced by a patch to ncurses 5.7 dated 2009-08-29, changing this macro to expand to code that causes the compiler to generate an unused-value warning. */ (void) wstandend (win_info->handle); tui_refresh_win (win_info); } }
/* ** tuiShowLocatorContent() */ void tuiShowLocatorContent (void) { char *string; TuiGenWinInfoPtr locator; locator = locatorWinInfoPtr (); if (m_genWinPtrNotNull (locator) && locator->handle != (WINDOW *) NULL) { string = displayableWinContentAt (locator, 0); if (string != (char *) NULL) { wmove (locator->handle, 0, 0); wstandout (locator->handle); waddstr (locator->handle, string); wstandend (locator->handle); tuiRefreshWin (locator); wmove (locator->handle, 0, 0); if (string != nullStr ()) tuiFree (string); locator->contentInUse = TRUE; } } return; } /* tuiShowLocatorContent */
void tui_show_locator_content (void) { char *string; struct tui_gen_win_info *locator; locator = tui_locator_win_info_ptr (); if (locator != NULL && locator->handle != (WINDOW *) NULL) { struct tui_win_element *element; element = (struct tui_win_element *) locator->content[0]; string = tui_make_status_line (&element->which_element.locator); wmove (locator->handle, 0, 0); wstandout (locator->handle); waddstr (locator->handle, string); wclrtoeol (locator->handle); wstandend (locator->handle); tui_refresh_win (locator); wmove (locator->handle, 0, 0); xfree (string); locator->content_in_use = TRUE; } }
void tui_show_locator_content (void) { char *string; struct tui_gen_win_info *locator; locator = tui_locator_win_info_ptr (); if (locator != NULL && locator->handle != (WINDOW *) NULL) { struct tui_win_element *element; element = locator->content[0]; string = tui_make_status_line (&element->which_element.locator); wmove (locator->handle, 0, 0); /* We ignore the return value from wstandout and wstandend, casting them to void in order to avoid a compiler warning. The warning itself was introduced by a patch to ncurses 5.7 dated 2009-08-29, changing these macro to expand to code that causes the compiler to generate an unused-value warning. */ (void) wstandout (locator->handle); waddstr (locator->handle, string); wclrtoeol (locator->handle); (void) wstandend (locator->handle); tui_refresh_win (locator); wmove (locator->handle, 0, 0); xfree (string); locator->content_in_use = TRUE; } }
static void print_list_line(int item, int line, int highlight) { struct index_elem *cur; int x_pos = 1; scrollok(list, FALSE); if(highlight) highlight_line(list, line); if(selected[item]) mvwaddch(list, line, 0, '*' ); for(cur = index_elements; cur; cur = cur->next) switch(cur->type) { case INDEX_TEXT: mvwaddstr(list, line, x_pos, cur->d.text); x_pos += strwidth(cur->d.text); break; case INDEX_FIELD: print_list_field(item, line, &x_pos, cur); break; default: assert(0); } scrollok(list, TRUE); if(highlight) wstandend(list); }
void Screen::PrintNormal(WINDOW * const window) const { const int dir=player->Dir(); const ushort k_start=( UP!=dir ) ? (( DOWN==dir ) ? player->Z()-1 : player->Z()) : player->Z()+1; const short k_step=( UP!=dir ) ? (-1) : 1; (void)wmove(window, 1, 1); const ushort start_x=( player->X()/SHRED_WIDTH )*SHRED_WIDTH + ( SHRED_WIDTH-SCREEN_SIZE )/2; const ushort start_y=( player->Y()/SHRED_WIDTH )*SHRED_WIDTH + ( SHRED_WIDTH-SCREEN_SIZE )/2; const int block_side=( dir==UP ) ? DOWN : UP; ushort i, j; for ( j=start_y; j<SCREEN_SIZE+start_y; ++j, waddstr(window, "\n_") ) for ( i=start_x; i<SCREEN_SIZE+start_x; ++i ) { ushort k; for (k=k_start; INVISIBLE==w->Transparent(i, j, k); k+=k_step); if ( (w->Enlightened(i, j, k, block_side) && player->Visible(i, j, k)) || player->GetCreativeMode() ) { PrintBlock(i, j, k, window); waddch(window, CharNumber(i, j, k)); } else { wstandend(window); waddch(window, OBSCURE_BLOCK); waddch(window, ' '); } } wstandend(window); box(window, 0, 0); if ( UP==dir || DOWN==dir ) { mvwaddstr(window, 0, 1, ( UP==dir ) ? "Up view" : "Ground view"); Arrows(window, (player->X()-start_x)*2+1, player->Y()-start_y+1); } else { mvwaddstr(window, 0, 1, "Down view"); if ( player->GetCreativeMode() ) { Arrows(window, (player->X()-start_x)*2+1, player->Y()-start_y+1); } } wnoutrefresh(window); }
static void show_keyword(WINDOW *stswin, int cell, int active, const char *name) { to_keyword(stswin, cell); if (active == cell) (void) wstandout(stswin); wprintw(stswin, "%s:", name); if (active == cell) (void) wstandend(stswin); }
star() { wstandout(treescrn2); mvwaddch(treescrn2, 0, 12, (chtype)'*'); wstandend(treescrn2); wrefresh(treescrn2); wrefresh(w_del_msg); return( 0 ); }
Point CursesWindow::putCh(int ch, const Point & pos, int color, int attr, bool preserveOldLoc) { int x = pos.x(), y = pos.y(); wstandend(m_win); if (!color) color = defaultColor(); if (color) wcolor_set(m_win, color, 0); if (attr) wattr_on(m_win, attr, 0); int oldy, oldx; getyx(m_win, oldy, oldx); if (pos.isNull()) y = oldy; if (pos.isNull()) x = oldx; if (y < 0) y = oldy+y; if (x < 0) x = oldx+x; wmove(m_win, y, x); waddch(m_win, ch); if (preserveOldLoc) wmove(m_win, oldy, oldx); wstandend(m_win); return curs(); }
void putstring(int row, int col, int attr, char const *msg) { int so = 0; if (row != -1) g_text_row = row; if (col != -1) g_text_col = col; if (attr & INVERSE || attr & BRIGHT) { wstandout(curwin); so = 1; } wmove(curwin, g_text_row + g_text_rbase, g_text_col + g_text_cbase); while (1) { if (*msg == '\0') break; if (*msg == '\n') { g_text_col = 0; g_text_row++; wmove(curwin, g_text_row + g_text_rbase, g_text_col + g_text_cbase); } else { char const *ptr; ptr = std::strchr(msg, '\n'); if (ptr == nullptr) { waddstr(curwin, msg); break; } else { waddch(curwin, *msg); } } msg++; } if (so) { wstandend(curwin); } wrefresh(curwin); fflush(stdout); getyx(curwin, g_text_row, g_text_col); g_text_row -= g_text_rbase; g_text_col -= g_text_cbase; }
int move_slot(int oldslot, int newslot, int maxslot) { if ((newslot >= 0) && (newslot < maxslot)){ wmove(Showline[oldslot],0,0); waddstr(Showline[oldslot],"--"); wrefresh(Showline[oldslot]); wmove(Showline[newslot],0,0); wstandout(Showline[newslot]); waddstr(Showline[newslot],">>"); wstandend(Showline[newslot]); wrefresh(Showline[newslot]); return(newslot); } else return(oldslot); }
static void view_tel () { vc_component *vc = NULL; char *val = NULL; int x = 0; int y = 0; int i = 0; g_mode = VIEW_TEL; werase (sub); x = (COLS - strlen (HEADING_TEL_STRING)) / 2; y = 1; wattron (sub, A_UNDERLINE); mvwprintw (sub, y, x, HEADING_TEL_STRING); wstandend (sub); wmove (sub, 3, 0); for (i = 1, vc = g_v; i <= 5; i++) { vc = vc_get_next_by_name (vc, VC_TELEPHONE); val = vc_get_value (vc); wprintw (sub, "Telephone #%i : %s\n", i, val ? val : ""); } wprintw (sub, "\n"); for (i = 1, vc = g_v; i <= 5; i++) { vc = vc_get_next_by_name (vc, VC_EMAIL); val = vc_get_value (vc); wprintw (sub, "Email Address #%i : %s\n", i, val ? val : ""); } wprintw (sub, "\n"); vc = vc_get_next_by_name (g_v, VC_MAILER); val = vc_get_value (vc); wprintw (sub, "Email Mailer : %s\n", val ? val : ""); touchwin (win); wrefresh (sub); wrefresh (win); }
/* * drawGauge() draws a progress bar */ void drawGauge(void *o, void* w) { Obj *obj = OBJ(o); int percent; int fillwidth; int rc; WINDOW *win = Window(w); int x = WX(w), y = WY(w); char bfr[5]; if (obj == 0 || obj->Class != O_GAUGE) return; percent = obj->content ? *((int*)(obj->content)) : 0; fillwidth = (obj->width * percent) / 100; rc = _nd_drawObjCommon(o, w); _nd_adjustXY(rc, o, &x, &y); /* clear the gauge area */ wmove(win, y, x); setcolor(win, WINDOW_COLOR); waddnstr(win, rillyrillylongblankstring, obj->width); if (obj->width > 4) { /* draw the percentage in the middle of the progress bar, * appropriately shaded */ sprintf(bfr, "%d%%", percent); wmove(win, y, x + ((obj->width-strlen(bfr))/2) ); waddstr(win, bfr); } #if WITH_NCURSES /* highlight the progress bar as appropriate */ mvwchgat(win, y, x, fillwidth, A_REVERSE, PAIR_NUMBER(WINDOW_COLOR), 0); #else wstandout(win); for (rc = 0; rc < fillwidth; rc++) mvwaddch(win, y, x+rc, mvwinch(win, y, x+rc)); wstandend(win); #endif } /* drawGauge */
QString & Screen::PassString(QString & str) const { static const ushort note_length=144; echo(); werase(notifyWin); wcolor_set(notifyWin, BLACK_WHITE, NULL); mvwaddch(notifyWin, 0, 0, ':'); wstandend(notifyWin); char temp_str[note_length+1]; wgetnstr(notifyWin, temp_str, note_length); str=temp_str; fputs(qPrintable(QString::number(w->Time())+": Command: "+str+'\n'), notifyLog); werase(notifyWin); wnoutrefresh(notifyWin); noecho(); return str; }
draw_all() { PLANE *pp; for (pp = air.head; pp != NULL; pp = pp->next) { if (pp->status == S_MARKED) wstandout(radar); wmove(radar, pp->ypos, pp->xpos * 2); waddch(radar, name(pp)); waddch(radar, '0' + pp->altitude); if (pp->status == S_MARKED) wstandend(radar); } wrefresh(radar); planewin(); wrefresh(input); /* return cursor */ fflush(stdout); }
void initialize_curses() { // start curses initscr(); if ( ! has_colors() || (start_color() != OK) || COLORS != 256 ) error("colors"); // Define three horizontally-stacked windows: // // 1 - board window // 2 - CLI output window // 3 - CLI input window // int half_height = LINES / 2; // newwin( height, width, begin_height, begin_width ); w1 = newwin( half_height, COLS, 0, 0 ); w2 = newwin( half_height - 1, COLS, half_height, 0 ); w3 = newwin( 1, COLS, LINES - 1, 0 ); if (w1 == NULL || w2 == NULL || w3 == NULL) { waddstr(stdscr, "newwin"); endwin(); } echo(); scrollok(w2, TRUE); // initialize color tuples // see http://www.calmar.ws/vim/256-xterm-24bit-rgb-color-chart.html // FG, BG init_pair( LIGHT_SQUARE, 0, 229 ); init_pair( DARK_SQUARE, 0, 209 ); init_pair( BLUISH, 111, 233 ); init_pair( TERMINAL, 252, 232 ); init_pair( GREENISH, 107, 233 ); init_pair( CLI_INPUT, 253, 232 ); init_pair( GRAY_ON_BLACK, 245, 233 ); init_pair( RED, 1, 52 ); wbkgd( w1, COLOR_PAIR( TERMINAL ) ); wbkgd( w2, COLOR_PAIR( TERMINAL ) ); wbkgd( w3, COLOR_PAIR( CLI_INPUT ) ); wattron(w1, COLOR_PAIR( BLUISH) ); mvwaddstr(w1, 0, centered(TITLE), TITLE); wstandend(w1); wrefresh(stdscr); wrefresh(w1); wrefresh(w2); wrefresh(w3); touchwin(stdscr); touchwin(w1); touchwin(w2); touchwin(w3); }
void cur_display_cycle() { if (displayLevel) if ((int) (W - warrior) % 2) wstandout(corewin); else { wstandend(corewin); if (!--refreshCounter) { refreshCounter = refreshInterval; update_statusline(round); wrefresh(corewin); } } #if defined(SYSV) && defined(KEYPRESS) /* PAK */ if (wgetch(corewin) != ERR) debugState = STEP; #endif }
void showhelp(void) { size_t length = 0; int lines; int x, y; int i; const char *cp; WINDOW *helpwin; const char *cont_msg = " Hit any key to continue "; for (lines = 0; (cp = helpmsg[lines]) != (char *) 0; lines++) if (strlen(cp) > length) length = strlen(cp); x = ((COLS - length - 2) + 1) / 2; y = ((LINES - lines - 2) + 1) / 2; if (x < 0 || y < 0) { fprintf(stderr, "\007"); return; } helpwin = newwin(lines + 2, length + 2, y, x); wclear(helpwin); box(helpwin, '|', '-'); for (i = 0; i < lines; i++) { wmove(helpwin, i + 1, 1); waddstr(helpwin, helpmsg[i]); } wmove(helpwin, lines + 1, length + 1 - strlen(cont_msg)); wstandout(helpwin); waddstr(helpwin, cont_msg); wstandend(helpwin); wrefresh(helpwin); (void) wgetch(helpwin); werase(helpwin); wrefresh(helpwin); delwin(helpwin); }
/* if display, displays monsters, otherwise erases them */ void drawmonsters(int display) { pml ml; for (ml=Level->mlist;ml!=NULL;ml=ml->next) { if (ml->m->hp > 0) { if (display) { if (view_los_p(Player.x,Player.y,ml->m->x,ml->m->y)) { if (Player.status[TRUESIGHT] || (! m_statusp(ml->m,M_INVISIBLE))) { if (!optionp(SHOW_COLOUR) && (ml->m->level > 5) && ((ml->m->monchar&0xff) != '@') && ((ml->m->monchar&0xff) != '|')) wstandout(Levelw); putspot(ml->m->x,ml->m->y,ml->m->monchar); if (!optionp(SHOW_COLOUR)) wstandend(Levelw); } } } else erase_monster(ml->m); } } }
void cb_write_response(WINDOW *w, void *data) { // match strings with these prefixes static char *highlight_prefixes[] = { "{Game ", "Game ", " **ANNOUNCEMENT**", "Removing game ", "Notification: ", "Creating: ", "No ratings adjustment done.", "Your seek matches one", "You are now observing", "(told ", "% " }; // match strings containing these substrings static char *highlight_contains[] = { " tells you: ", " kibitzes: ", "(U)(", "(TD)(", "(C)(", }; char *line = (char *) data; // highlight matches for (int i=0; i < LEN(highlight_prefixes); i++) if ( begins_with(line, highlight_prefixes[i]) ) wattron(w, COLOR_PAIR( GREENISH )); for (int i=0; i < LEN(highlight_contains); i++) if ( contains(line, highlight_contains[i]) ) wattron(w, COLOR_PAIR( GRAY_ON_BLACK )); waddstr(w, line); wstandend(w); wrefresh(w); }
static void print_header () { char *header_str = NULL; int i = 0; header_str = (char *) malloc (sizeof (char) * (COLS + 2)); strncpy (header_str, MENU_BAR_STRING, COLS); for (i = strlen (MENU_BAR_STRING); i < COLS; i++) { header_str[i] = ' '; } header_str[COLS] = '\n'; header_str[COLS + 1] = '\0'; wattron (win, A_REVERSE); wprintw (win, header_str); wstandend (win); free (header_str); }
/* Display a register in a window. If hilite is TRUE, then the value will be displayed in reverse video */ static void tui_display_register (struct tui_data_element *data, struct tui_gen_win_info *win_info) { if (win_info->handle != (WINDOW *) NULL) { int i; if (data->highlight) wstandout (win_info->handle); wmove (win_info->handle, 0, 0); for (i = 1; i < win_info->width; i++) waddch (win_info->handle, ' '); wmove (win_info->handle, 0, 0); if (data->content) waddstr (win_info->handle, data->content); if (data->highlight) wstandend (win_info->handle); tui_refresh_win (win_info); } }
static void view_misc () { vc_component *vc = NULL; char *str = NULL; char *val = NULL; int x = 0; int y = 0; g_mode = VIEW_MISC; werase (sub); x = (COLS - strlen (HEADING_MISC_STRING)) / 2; y = 1; wattron (sub, A_UNDERLINE); mvwprintw (sub, y, x, HEADING_MISC_STRING); wstandend (sub); wmove (sub, 3, 0); vc = vc_get_next_by_name (g_v, VC_SORT_STRING); val = vc_get_value (vc); wprintw (sub, "Sort String : %s\n", val ? val : ""); vc = vc_get_next_by_name (g_v, VC_CLASS); val = vc_get_value (vc); wprintw (sub, "Class : %s\n", val ? val : ""); vc = vc_get_next_by_name (g_v, VC_KEY); val = vc_get_value (vc); wprintw (sub, "Public Key : %s\n", val ? val : ""); touchwin (win); wrefresh (sub); wrefresh (win); }
/* ** scrollWinForward */ void scrollWinForward (TuiGenWinInfoPtr winInfo, int numLines) { if (winInfo->content != (OpaquePtr) NULL && winInfo->lastVisibleLine < winInfo->contentSize - 1) { int i, firstLine, newLastLine; firstLine = winInfo->lastVisibleLine - winInfo->viewportHeight + 1; if (winInfo->lastVisibleLine + numLines > winInfo->contentSize) newLastLine = winInfo->contentSize - 1; else newLastLine = winInfo->lastVisibleLine + numLines - 1; for (i = (newLastLine - winInfo->viewportHeight); (i <= newLastLine); i++) { TuiWinElementPtr line; int lineHeight; line = (TuiWinElementPtr) winInfo->content[i]; if (line->highlight) wstandout (winInfo->handle); mvwaddstr (winInfo->handle, i - (newLastLine - winInfo->viewportHeight), 1, displayableWinContentOf (winInfo, line)); if (line->highlight) wstandend (winInfo->handle); lineHeight = winElementHeight (winInfo, line); newLastLine += (lineHeight - 1); } winInfo->lastVisibleLine = newLastLine; } return; } /* scrollWinForward */
/* ** tuiClearLocatorDisplay() */ void tuiClearLocatorDisplay (void) { TuiGenWinInfoPtr locator = locatorWinInfoPtr (); int i; if (locator->handle != (WINDOW *) NULL) { /* No need to werase, since writing a line of * blanks which we do below, is equivalent. */ /* werase(locator->handle); */ wmove (locator->handle, 0, 0); wstandout (locator->handle); for (i = 0; i < locator->width; i++) waddch (locator->handle, ' '); wstandend (locator->handle); tuiRefreshWin (locator); wmove (locator->handle, 0, 0); locator->contentInUse = FALSE; } return; } /* tuiClearLocatorDisplay */
void sell(struct thing *tp) { struct linked_list *item; int i, j, min_worth, nitems, chance, which_item, w; char goods; struct object *obj; char buffer[2 * LINELEN]; char dbuf[2 * LINELEN]; struct { int which; int plus1, plus2; int count; int worth; int flags; char *name; } selection[SELL_ITEMS]; int effective_purse = ((player.t_ctype == C_PALADIN) ? (9 * purse / 10) : purse); min_worth = -1; /* hope item is never worth less than this */ item = find_mons(tp->t_pos.y, tp->t_pos.x); /* Get pointer to monster */ /* Select the items */ nitems = rnd(6) + 5; switch (rnd(6)) { /* Armor */ case 0: case 1: goods = ARMOR; for (i = 0; i < nitems; i++) { chance = rnd(100); for (j = 0; j < maxarmors; j++) if (chance < armors[j].a_prob) break; if (j == maxarmors) { debug("Picked a bad armor %d", chance); j = 0; } selection[i].which = j; selection[i].count = 1; if (rnd(100) < 40) selection[i].plus1 = rnd(5) + 1; else selection[i].plus1 = 0; selection[i].name = armors[j].a_name; switch (luck) { case 0: break; case 1: if (rnd(3) == 0) { selection[i].flags |= ISCURSED; selection[i].plus1 = -1 - rnd(5); } break; default: if (rnd(luck)) { selection[i].flags |= ISCURSED; selection[i].plus1 = -1 - rnd(5); } break; } /* Calculate price */ w = armors[j].a_worth; w *= (1 + luck + (10 * selection[i].plus1)); w = (w / 2) + (roll(6, w) / 6); selection[i].worth = max(w, 25); if (min_worth > selection[i].worth || i == 1) min_worth = selection[i].worth; } break; /* Weapon */ case 2: case 3: goods = WEAPON; for (i = 0; i < nitems; i++) { selection[i].which = rnd(maxweapons); selection[i].count = 1; if (rnd(100) < 35) { selection[i].plus1 = rnd(3); selection[i].plus2 = rnd(3); } else { selection[i].plus1 = 0; selection[i].plus2 = 0; } if (weaps[selection[i].which].w_flags & ISMANY) selection[i].count = rnd(15) + 8; selection[i].name = weaps[selection[i].which].w_name; switch (luck) { case 0: break; case 1: if (rnd(3) == 0) { selection[i].flags |= ISCURSED; selection[i].plus1 = -rnd(3); selection[i].plus2 = -rnd(3); } break; default: if (rnd(luck)) { selection[i].flags |= ISCURSED; selection[i].plus1 = -rnd(3); selection[i].plus2 = -rnd(3); } break; } w = weaps[selection[i].which].w_worth * selection[i].count; w *= (1 + luck + (10 * selection[i].plus1 + 10 * selection[i].plus2)); w = (w / 2) + (roll(6, w) / 6); selection[i].worth = max(w, 25); if (min_worth > selection[i].worth || i == 1) min_worth = selection[i].worth; } break; /* Staff or wand */ case 4: goods = STICK; for (i = 0; i < nitems; i++) { selection[i].which = pick_one(ws_magic, maxsticks); selection[i].plus1 = rnd(11) + 5; selection[i].count = 1; selection[i].name = ws_magic[selection[i].which].mi_name; switch (luck) { case 0: break; case 1: if (rnd(3) == 0) { selection[i].flags |= ISCURSED; selection[i].plus1 = 1; } break; default: if (rnd(luck)) { selection[i].flags |= ISCURSED; selection[i].plus1 = 1; } } w = ws_magic[selection[i].which].mi_worth; w += (luck + 1) * 20 * selection[i].plus1; w = (w / 2) + (roll(6, w) / 6); selection[i].worth = max(w, 25); if (min_worth > selection[i].worth || i == 1) min_worth = selection[i].worth; } break; /* Ring */ case 5: goods = RING; for (i = 0; i < nitems; i++) { selection[i].which = pick_one(r_magic, maxrings); selection[i].plus1 = rnd(2) + 1; selection[i].count = 1; if (rnd(100) < r_magic[selection[i].which].mi_bless + 10) selection[i].plus1 += rnd(2) + 1; selection[i].name = r_magic[selection[i].which].mi_name; switch (luck) { case 0: break; case 1: if (rnd(3) == 0) { selection[i].flags |= ISCURSED; selection[i].plus1 = -1 - rnd(2); } break; default: if (rnd(luck)) { selection[i].flags |= ISCURSED; selection[i].plus1 = -1 - rnd(2); } } w = r_magic[selection[i].which].mi_worth; switch(selection[i].which) { case R_DIGEST: if (selection[i].plus1 > 2) selection[i].plus1 = 2; else if (selection[i].plus1 < 1) selection[i].plus1 = 1; /* fall thru here to other cases */ case R_ADDSTR: case R_ADDDAM: case R_PROTECT: case R_ADDHIT: case R_ADDINTEL: case R_ADDWISDOM: if (selection[i].plus1 > 0) w += selection[i].plus1 * 50; } w *= (1 + luck); w = (w / 2) + (roll(6, w) / 6); selection[i].worth = max(w, 25); if (min_worth > selection[i].worth * selection[i].count) min_worth = selection[i].worth; } } /* See if player can afford an item */ if (min_worth > effective_purse) { msg("The %s eyes your small purse and departs.", monsters[nummonst].m_name); /* Get rid of the monster */ killed(NULL, item, NOMESSAGE, NOPOINTS); return; } /* Display the goods */ msg("The %s shows you his wares.", monsters[nummonst].m_name); wstandout(cw); mvwaddstr(cw, 0, mpos, morestr); wstandend(cw); wrefresh(cw); wait_for(' '); msg(""); clearok(cw, TRUE); touchwin(cw); wclear(hw); touchwin(hw); for (i = 0; i < nitems; i++) { if (selection[i].worth > effective_purse) continue; wmove(hw, i + 2, 0); sprintf(dbuf, "[%c] ", ('a' + i)); switch(goods) { case ARMOR: strcat(dbuf, "Some "); break; case WEAPON: if (selection[i].count == 1) strcat(dbuf, "A "); else { sprintf(buffer, "%2d ", selection[i].count); strcat(dbuf, buffer); } break; case STICK: strcat(dbuf, "A "); strcat(dbuf, ws_type[selection[i].which]); strcat(dbuf, " of "); break; case RING: strcat(dbuf, "A ring of "); break; } strcat(dbuf, selection[i].name); if (selection[i].count > 1) strcat(dbuf, "s"); sprintf(buffer, "%-50s Price: %d", dbuf, selection[i].worth); waddstr(hw, buffer); } sprintf(buffer, "Purse: %d", purse); mvwaddstr(hw, nitems + 3, 0, buffer); mvwaddstr(hw, 0, 0, "How about one of the following goods? "); wrefresh(hw); /* Get rid of the monster */ killed(NULL, item, NOMESSAGE, NOPOINTS); which_item = (short) ((readchar() & 0177) - 'a'); while (which_item < 0 || which_item >= nitems || selection[which_item].worth > effective_purse) { if (which_item == (short) ESCAPE - (short) 'a') return; mvwaddstr(hw, 0, 0, "Please enter one of the listed items: "); wrefresh(hw); which_item = (short) ((readchar() & 0177) - 'a'); } if (purse > selection[which_item].worth) purse -= selection[which_item].worth; else purse = 0L; item = spec_item(goods, selection[which_item].which, selection[which_item].plus1, selection[which_item].plus2); obj = OBJPTR(item); if (selection[which_item].count > 1) { obj->o_count = selection[which_item].count; obj->o_group = ++group; } /* If a stick or ring, let player know the type */ switch (goods) { case STICK: know_items[TYP_STICK][selection[which_item].which] = TRUE; break; case RING: know_items[TYP_RING][selection[which_item].which] = TRUE; break; } if (add_pack(item, MESSAGE) == FALSE) { obj->o_pos = hero; fall(&player, item, TRUE, FALSE); } }