/* 15.6.2.2531 [ELSE] “bracket-else” TOOLS EXT Compilation: Perform the execution semantics given below. Execution: ( “hspacesiname ...” -- ) Skipping leading spaces, parse and discard space-delimited words from the parse area, including nested occurrences of [IF] ... [THEN] and [IF] ... [ELSE] ... [THEN], until the word [THEN] has been parsed and discarded. If the parse area be- comes exhausted, it is refilled as with REFILL. [ELSE] is an immediate word. See: 3.4.1 Parsing, A.15.6.2.2531 [ELSE]. 15.6.2.2532 [IF] “bracket-if” TOOLS EXT */ static void do_bracket_else(void) { /* : [else] 1 ( initialize [if]/[else]/[then] nesting level) begin bl word count dup 0= ( refill input buffer) if drop drop refill 0= if ( refill failed) drop ( drop nesting level) ." error: input exhausted" cr exit then [ over ] ( continue loop) again then 0 if 2dup ." found word: " type cr then 2dup s" [if]" compare 0= if ( increase nesting level) rot 1+ rot rot then 2dup s" [else]" compare 0= if ( special-case for the nesting level) rot dup 1 = if 1- then rot rot then s" [then]" compare 0= if ( decrease nesting level) 1- then dup 0= until drop ; immediate : [if] 0= if postpone [else] then ; immediate : [then] ; immediate */ /* initialize [if]/[else]/[then] nesting level */ sf_push(1); do { do_bl(); do_word(); do_count(); if (!sf_top()) { /* input exhausted, refill input buffer */ do_drop(); do_drop(); do_refill(); if (!sf_pop()) { /* 'refill' failed */ /* drop nesting level */ do_drop(); print_str(__func__); print_str("(): input exhausted; aborting\n"); do_abort(); } continue; } do_two_to_r(); do_two_r_fetch(); //sf_push((cell) "\04[if]"); do_count(); sf_push((cell) compare_word_xt); do_execute(); if (sf_pop() == 4) { if (!xmemcmp((void *) sf_pop(), "[if]", 4)) /* increase nesting level */ do_one_plus(); } else do_drop(); do_two_r_fetch(); //sf_push((cell) "\06[else]"); do_count(); sf_push((cell) compare_word_xt); do_execute(); if (sf_pop() == 6) { if (!xmemcmp((void *) sf_pop(), "[else]", 6)) /* see if an [if] block should be terminated */ if (sf_top() == 1) do_one_minus(); } else do_drop(); do_two_r_from(); //sf_push((cell) "\06[then]"); do_count(); sf_push((cell) compare_word_xt); do_execute(); if (sf_pop() == 6) { if (!xmemcmp((void *) sf_pop(), "[then]", 6)) /* decrease nesting level */ do_one_minus(); } else do_drop(); } while (sf_top()); /* drop nesting level */ do_drop(); }
/** * Creates a veh_interact window based on the given parameters. * @param v The vehicle the player is interacting with. * @param x The x-coordinate of the square the player is 'e'xamining. * @param y The y-coordinate of the square the player is 'e'xamining. */ void veh_interact::exec (game *gm, vehicle *v, int x, int y) { g = gm; veh = v; // x1 x2 // y1 ----+------+-- // | | // y2 ----+------+ // | // | winw1 = 12; winw2 = 35; winh1 = 3; winh2 = 12; winw12 = winw1 + winw2 + 1; winw3 = FULL_SCREEN_WIDTH - winw1 - winw2 - 2; winh3 = FULL_SCREEN_HEIGHT - winh1 - winh2 - 2; winh23 = winh2 + winh3 + 1; winx1 = winw1; winx2 = winw1 + winw2 + 1; winy1 = winh1; winy2 = winh1 + winh2 + 1; // changed FALSE value to 1, to keep w_border from starting at a negative x,y const int iOffsetX = (TERMX > FULL_SCREEN_WIDTH) ? (TERMX-FULL_SCREEN_WIDTH)/2 : 1; const int iOffsetY = (TERMY > FULL_SCREEN_HEIGHT) ? (TERMY-FULL_SCREEN_HEIGHT)/2 : 1; page_size = winh23; // h w y x WINDOW *w_border= newwin(FULL_SCREEN_HEIGHT, FULL_SCREEN_WIDTH, -1 + iOffsetY, -1 + iOffsetX); w_grid = newwin(FULL_SCREEN_HEIGHT -2, FULL_SCREEN_WIDTH-2, iOffsetY, iOffsetX); w_mode = newwin(1, FULL_SCREEN_WIDTH-2, iOffsetY, iOffsetX); w_msg = newwin(winh1 - 1, FULL_SCREEN_WIDTH-2, 1 + iOffsetY, iOffsetX); w_disp = newwin(winh2-1, winw1, winy1 + 1 + iOffsetY, iOffsetX); w_parts = newwin(winh2-1, winw2, winy1 + 1 + iOffsetY, winx1 + 1 + iOffsetX); w_stats = newwin(winh3-1, winw12, winy2 + iOffsetY, iOffsetX); w_list = newwin(winh23, winw3, winy1 + 1 + iOffsetY, winx2 + 1 + iOffsetX); wborder(w_border, LINE_XOXO, LINE_XOXO, LINE_OXOX, LINE_OXOX, LINE_OXXO, LINE_OOXX, LINE_XXOO, LINE_XOOX ); mvwputch(w_border, 16, 0, c_ltgray, LINE_XXXO); // |- mvwputch(w_border, 4, 0, c_ltgray, LINE_XXXO); // |- mvwputch(w_border, 4, FULL_SCREEN_WIDTH-1, c_ltgray, LINE_XOXX); // -| mvwputch(w_border, 24, 49, c_ltgray, LINE_XXOX); wrefresh(w_border); for (int i = 0; i < FULL_SCREEN_HEIGHT; i++) { mvwputch(w_grid, i, winx2, c_ltgray, i == winy1 || i == winy2-1? LINE_XOXX : LINE_XOXO); if (i >= winy1 && i < winy2) { mvwputch(w_grid, i, winx1, c_ltgray, LINE_XOXO); } } for (int i = 0; i < FULL_SCREEN_WIDTH; i++) { mvwputch(w_grid, winy1, i, c_ltgray, i == winx1? LINE_OXXX : (i == winx2? LINE_OXXX : LINE_OXOX)); if (i < winx2) { mvwputch(w_grid, winy2-1, i, c_ltgray, i == winx1? LINE_XXOX : LINE_OXOX); } } wrefresh(w_grid); crafting_inv = gm->crafting_inventory(&gm->u); int charges = static_cast<it_tool *>(g->itypes["welder"])->charges_per_use; int charges_crude = static_cast<it_tool *>(g->itypes["welder_crude"])->charges_per_use; has_wrench = crafting_inv.has_amount("wrench", 1) || crafting_inv.has_amount("toolset", 1); has_hacksaw = crafting_inv.has_amount("hacksaw", 1) || crafting_inv.has_amount("toolset", 1); has_welder = (crafting_inv.has_amount("welder", 1) && crafting_inv.has_charges("welder", charges)) || (crafting_inv.has_amount("welder_crude", 1) && crafting_inv.has_charges("welder_crude", charges_crude)) || (crafting_inv.has_amount("toolset", 1) && crafting_inv.has_charges("toolset", charges/20)); has_jack = crafting_inv.has_amount("jack", 1); has_siphon = crafting_inv.has_amount("hose", 1); has_wheel = crafting_inv.has_amount( "wheel", 1 ) || crafting_inv.has_amount( "wheel_wide", 1 ) || crafting_inv.has_amount( "wheel_bicycle", 1 ) || crafting_inv.has_amount( "wheel_motorbike", 1 ) || crafting_inv.has_amount( "wheel_small", 1 ); display_stats (); display_veh (); move_cursor (0, 0); bool finish = false; while (!finish) { char ch = input(); // See keypress.h int dx, dy; get_direction (dx, dy, ch); if (ch == KEY_ESCAPE || ch == 'q' ) { finish = true; } else { if (dx != -2 && (dx || dy) && cursor_x + dx >= -6 && cursor_x + dx < 6 && cursor_y + dy >= -6 && cursor_y + dy < 6) { move_cursor(dx, dy); } else { int mval = cant_do(ch); display_mode (ch); switch (ch) { case 'i': do_install(mval); break; case 'r': do_repair(mval); break; case 'f': do_refill(mval); break; case 'o': do_remove(mval); break; case 'e': do_rename(mval); break; case 's': do_siphon(mval); break; case 'c': do_tirechange(mval); break; case 'd': do_drain(mval); break; } if (sel_cmd != ' ') { finish = true; } display_mode (' '); } } } werase(w_grid); werase(w_mode); werase(w_msg); werase(w_disp); werase(w_parts); werase(w_stats); werase(w_list); delwin(w_grid); delwin(w_mode); delwin(w_msg); delwin(w_disp); delwin(w_parts); delwin(w_stats); delwin(w_list); erase(); }
void veh_interact::exec (game *gm, vehicle *v, int x, int y) { g = gm; veh = v; ex = x; ey = y; // x1 x2 // y1 ----+------+-- // | | // y2 ----+------+ // | // | winw1 = 12; winw2 = 35; winh1 = 3; winh2 = 12; winw12 = winw1 + winw2 + 1; winw3 = 80 - winw1 - winw2 - 2; winh3 = 25 - winh1 - winh2 - 2; winh23 = winh2 + winh3 + 1; winx1 = winw1; winx2 = winw1 + winw2 + 1; winy1 = winh1; winy2 = winh1 + winh2 + 1; page_size = winh23; // h w y x w_grid = newwin(25, 80, 0, 0); w_mode = newwin(1, 80, 0, 0); w_msg = newwin(winh1 - 1, 80, 1, 0); w_disp = newwin(winh2, winw1, winy1 + 1, 0); w_parts = newwin(winh2, winw2, winy1 + 1, winx1 + 1); w_stats = newwin(winh3, winw12, winy2 + 1, 0); w_list = newwin(winh23, winw3, winy1 + 1, winx2 + 1); for (int i = 0; i < 25; i++) { mvwputch(w_grid, i, winx2, c_ltgray, i == winy1 || i == winy2? LINE_XOXX : LINE_XOXO); if (i >= winy1 && i < winy2) mvwputch(w_grid, i, winx1, c_ltgray, LINE_XOXO); } for (int i = 0; i < 80; i++) { mvwputch(w_grid, winy1, i, c_ltgray, i == winx1? LINE_OXXX : (i == winx2? LINE_OXXX : LINE_OXOX)); if (i < winx2) mvwputch(w_grid, winy2, i, c_ltgray, i == winx1? LINE_XXOX : LINE_OXOX); } wrefresh(w_grid); crafting_inv = gm->crafting_inventory(); int charges = ((it_tool *) g->itypes["welder"])->charges_per_use; has_wrench = crafting_inv.has_amount("wrench", 1) || crafting_inv.has_amount("toolset", 1); has_hacksaw = crafting_inv.has_amount("hacksaw", 1) || crafting_inv.has_amount("toolset", 1); has_welder = (crafting_inv.has_amount("welder", 1) && crafting_inv.has_charges("welder", charges)) || (crafting_inv.has_amount("toolset", 1) && crafting_inv.has_charges("toolset", charges/5)); display_stats (); display_veh (); move_cursor (0, 0); bool finish = false; while (!finish) { char ch = input(); // See keypress.h int dx, dy; get_direction (gm, dx, dy, ch); if (ch == KEY_ESCAPE) finish = true; else if (dx != -2 && (dx || dy) && cx + dx >= -6 && cx + dx < 6 && cy + dy >= -6 && cy + dy < 6) move_cursor(dx, dy); else { int mval = cant_do(ch); display_mode (ch); switch (ch) { case 'i': do_install(mval); break; case 'r': do_repair(mval); break; case 'f': do_refill(mval); break; case 'o': do_remove(mval); break; case 'e': do_rename(mval); break; default:; } if (sel_cmd != ' ') finish = true; display_mode (' '); } } werase(w_grid); werase(w_mode); werase(w_msg); werase(w_disp); werase(w_parts); werase(w_stats); werase(w_list); delwin(w_grid); delwin(w_mode); delwin(w_msg); delwin(w_disp); delwin(w_parts); delwin(w_stats); delwin(w_list); erase(); }
/** * Creates a veh_interact window based on the given parameters. * @param v The vehicle the player is interacting with. * @param x The x-coordinate of the square the player is 'e'xamining. * @param y The y-coordinate of the square the player is 'e'xamining. */ void veh_interact::exec (game *gm, vehicle *v, int x, int y) { veh = v; // winw1 winw2 winw3 // winh1 | | // ------+-------+------ // winh2 | | // ------+-------+------ // winh3 | | // // +-------------------------+ // | w_mode | // | w_msg | // +-------+---------+-------+ // |w_disp | w_parts | w_list| // +-------+---------+-------+ // | w_stats | // +-------------------------+ int winw1 = 12; int winw2 = 35; int winh1 = 3; int winh2 = 13; int winw3 = FULL_SCREEN_WIDTH - winw1 - winw2 - 4; int winh3 = FULL_SCREEN_HEIGHT - winh1 - winh2 - 2; int winx1 = winw1; int winx2 = winw1 + winw2 + 1; int winy1 = winh1; int winy2 = winh1 + winh2 + 1; mode_h = 1; mode_w = FULL_SCREEN_WIDTH - 2; msg_h = winh1 - 1; msg_w = FULL_SCREEN_WIDTH - 2; disp_h = winh2 - 1; disp_w = winw1; parts_h = winh2 - 1; parts_w = winw2; stats_h = winh3 - 1; stats_w = FULL_SCREEN_WIDTH - 2; list_h = winh2 - 1; list_w = winw3; const int iOffsetX = 1 + ((TERMX > FULL_SCREEN_WIDTH) ? (TERMX-FULL_SCREEN_WIDTH)/2 : 0); const int iOffsetY = 1 + ((TERMY > FULL_SCREEN_HEIGHT) ? (TERMY-FULL_SCREEN_HEIGHT)/2 : 0); page_size = list_h; // h w y x WINDOW *w_border = newwin( FULL_SCREEN_HEIGHT, FULL_SCREEN_WIDTH, -1 + iOffsetY, -1 + iOffsetX ); w_grid = newwin( FULL_SCREEN_HEIGHT - 2, FULL_SCREEN_WIDTH - 2, iOffsetY, iOffsetX ); w_mode = newwin( mode_h, mode_w, iOffsetY, iOffsetX ); w_msg = newwin( msg_h, msg_w, mode_h + iOffsetY, iOffsetX ); w_disp = newwin( disp_h, disp_w, mode_h + msg_h + 1 + iOffsetY, iOffsetX ); w_parts = newwin( parts_h, parts_w, mode_h + msg_h + 1 + iOffsetY, disp_w + 1 + iOffsetX ); w_list = newwin( list_h, list_w, mode_h + msg_h + 1 + iOffsetY, disp_w + 1 + parts_w + 1 + iOffsetX ); w_stats = newwin( stats_h, stats_w, mode_h + msg_h + 1 + disp_h + 1 + iOffsetY, iOffsetX ); wborder(w_border, LINE_XOXO, LINE_XOXO, LINE_OXOX, LINE_OXOX, LINE_OXXO, LINE_OOXX, LINE_XXOO, LINE_XOOX ); mvwputch(w_border, mode_h + msg_h + 1 + disp_h + 1, 0, c_ltgray, LINE_XXXO); // |- mvwputch(w_border, mode_h + msg_h + 1, 0, c_ltgray, LINE_XXXO); // |- mvwputch(w_border, mode_h + msg_h + 1 + disp_h + 1, FULL_SCREEN_WIDTH - 1, c_ltgray, LINE_XOXX); mvwputch(w_border, mode_h + msg_h + 1, FULL_SCREEN_WIDTH - 1, c_ltgray, LINE_XOXX); wrefresh(w_border); // Two lines dividing the three middle sections. for (int i = winy1; i < winy2; i++) { mvwputch(w_grid, i, winx2, c_ltgray, LINE_XOXO); mvwputch(w_grid, i, winx1, c_ltgray, LINE_XOXO); } // Two lines dividing the vertical menu sections. for (int i = 0; i < FULL_SCREEN_WIDTH; i++) { mvwputch( w_grid, winy1, i, c_ltgray, LINE_OXOX ); mvwputch( w_grid, winy2-1, i, c_ltgray, LINE_OXOX ); } // Fix up the line intersections. mvwputch( w_grid, winy1, winx1, c_ltgray, LINE_OXXX ); mvwputch( w_grid, winy1, winx2, c_ltgray, LINE_OXXX ); mvwputch( w_grid, winy2 - 1, winx1, c_ltgray, LINE_XXOX ); mvwputch( w_grid, winy2 - 1, winx2, c_ltgray, LINE_XXOX ); wrefresh(w_grid); crafting_inv = g->crafting_inventory(&g->u); int charges = static_cast<it_tool *>(g->itypes["welder"])->charges_per_use; int charges_crude = static_cast<it_tool *>(g->itypes["welder_crude"])->charges_per_use; has_wrench = crafting_inv.has_amount("wrench", 1) || crafting_inv.has_amount("toolset", 1); has_hacksaw = crafting_inv.has_amount("hacksaw", 1) || crafting_inv.has_amount("toolset", 1); has_welder = (crafting_inv.has_amount("welder", 1) && crafting_inv.has_charges("welder", charges)) || (crafting_inv.has_amount("welder_crude", 1) && crafting_inv.has_charges("welder_crude", charges_crude)) || (crafting_inv.has_amount("toolset", 1) && crafting_inv.has_charges("toolset", charges/20)); has_jack = crafting_inv.has_amount("jack", 1); has_siphon = crafting_inv.has_amount("hose", 1); has_wheel = crafting_inv.has_amount( "wheel", 1 ) || crafting_inv.has_amount( "wheel_wide", 1 ) || crafting_inv.has_amount( "wheel_bicycle", 1 ) || crafting_inv.has_amount( "wheel_motorbike", 1 ) || crafting_inv.has_amount( "wheel_small", 1 ); display_stats (); display_veh (); move_cursor (0, 0); bool finish = false; while (!finish) { char ch = input(); // See keypress.h int dx, dy; get_direction (dx, dy, ch); if (ch == KEY_ESCAPE || ch == 'q' ) { finish = true; } else { if (dx != -2 && (dx || dy) && cursor_x + dx >= -6 && cursor_x + dx < 6 && cursor_y + dy >= -6 && cursor_y + dy < 6) { move_cursor(dx, dy); } else { int mval = cant_do(ch); display_mode (ch); switch (ch) { case 'i': do_install(mval); break; case 'r': do_repair(mval); break; case 'f': do_refill(mval); break; case 'o': do_remove(mval); break; case 'e': do_rename(mval); break; case 's': do_siphon(mval); break; case 'c': do_tirechange(mval); break; case 'd': do_drain(mval); break; } if (sel_cmd != ' ') { finish = true; } display_mode (' '); } } } werase(w_grid); werase(w_mode); werase(w_msg); werase(w_disp); werase(w_parts); werase(w_stats); werase(w_list); delwin(w_grid); delwin(w_mode); delwin(w_msg); delwin(w_disp); delwin(w_parts); delwin(w_stats); delwin(w_list); erase(); }