Changeset 69

Show
Ignore:
Timestamp:
04/23/07 17:53:20 (1 year ago)
Author:
takkaria
Message:

Commit the remainder of the mouse patch code. Closes #93.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/Makefile.inc

    r42 r69  
    3232  object2 \ 
    3333  obj-info \ 
     34  pathfind \ 
    3435  randart \ 
    3536  randname \ 
  • trunk/src/cmd1.c

    r48 r69  
    21112111void run_step(int dir) 
    21122112{ 
     2113        int x, y; 
     2114 
    21132115        /* Start run */ 
    21142116        if (dir) 
     
    21272129        else 
    21282130        { 
    2129                 /* Update run */ 
    2130                 if (run_test()) 
    2131                 { 
    2132                         /* Disturb */ 
    2133                         disturb(0, 0); 
    2134  
    2135                         /* Done */ 
    2136                         return; 
     2131                if (!p_ptr->running_withpathfind) 
     2132                { 
     2133                        /* Update run */ 
     2134                        if (run_test()) 
     2135                        { 
     2136                                /* Disturb */ 
     2137                                disturb(0, 0); 
     2138         
     2139                                /* Done */ 
     2140                                return; 
     2141                        } 
     2142                } 
     2143                else 
     2144                { 
     2145                        if (pf_result_index < 0) 
     2146                        { 
     2147                                disturb(0, 0); 
     2148                                p_ptr->running_withpathfind = 0; 
     2149                                return; 
     2150                        } 
     2151                        p_ptr->run_cur_dir = pf_result[pf_result_index--] - '0'; 
     2152                        x = p_ptr->px + ddx[p_ptr->run_cur_dir]; 
     2153                        y = p_ptr->py + ddy[p_ptr->run_cur_dir]; 
     2154                        if (!do_cmd_walk_test(y, x)) return; 
    21372155                } 
    21382156        } 
  • trunk/src/cmd2.c

    r24 r69  
    20012001 * Determine if a given grid may be "walked" 
    20022002 */ 
    2003 static bool do_cmd_walk_test(int y, int x) 
     2003bool do_cmd_walk_test(int y, int x) 
    20042004{ 
    20052005        /* Hack -- walking obtains knowledge XXX XXX */ 
     
    21542154        /* Start run */ 
    21552155        run_step(dir); 
     2156} 
     2157 
     2158/* 
     2159 * Start running with pathfinder. 
     2160 * 
     2161 * Note that running while confused is not allowed. 
     2162 */ 
     2163void do_cmd_pathfind(int y, int x) 
     2164{ 
     2165        /* Hack XXX XXX XXX */ 
     2166        if (p_ptr->timed[TMD_CONFUSED]) 
     2167        { 
     2168                msg_print("You are too confused!"); 
     2169                return; 
     2170        } 
     2171 
     2172        if (findpath(y, x)) 
     2173        { 
     2174                p_ptr->running = 1000; 
     2175                /* Calculate torch radius */ 
     2176                p_ptr->update |= (PU_TORCH); 
     2177                p_ptr->running_withpathfind = TRUE; 
     2178                run_step(0); 
     2179        } 
    21562180} 
    21572181 
  • trunk/src/dungeon.c

    r59 r69  
    12381238static void process_command(void) 
    12391239{ 
    1240  
     1240        int x, y; 
     1241         
    12411242#ifdef ALLOW_REPEAT 
    12421243 
     
    18111812                { 
    18121813                        do_cmd_save_screen(); 
     1814                        break; 
     1815                } 
     1816 
     1817                /* Mouse click */ 
     1818                case '\xff': 
     1819                { 
     1820                        x = p_ptr->command_cmd_ex.mousex + Term->offset_x; 
     1821                        y = p_ptr->command_cmd_ex.mousey + Term->offset_y; 
     1822                        do_cmd_pathfind(y, x); 
    18131823                        break; 
    18141824                } 
  • trunk/src/externs.h

    r38 r69  
    2626extern cptr macro_trigger_name[MAX_MACRO_TRIGGER]; 
    2727extern cptr macro_trigger_keycode[2][MAX_MACRO_TRIGGER]; 
     28 
     29/* pathfind.c */ 
     30extern char pf_result[]; 
     31extern int pf_result_index; 
    2832 
    2933/* tables.c */ 
     
    304308extern void move_player(int dir, int jumping); 
    305309extern void run_step(int dir); 
     310bool do_cmd_walk_test(int y, int x); 
    306311 
    307312/* cmd2.c */ 
     
    320325extern void do_cmd_jump(void); 
    321326extern void do_cmd_run(void); 
     327extern void do_cmd_pathfind(int y, int x); 
    322328extern void do_cmd_hold(void); 
    323329extern void do_cmd_stay(void); 
     
    547553extern void print_spells(const byte *spells, int num, int y, int x); 
    548554extern void display_koff(int k_idx); 
     555 
     556/* pathfind.c */ 
     557extern bool findpath(int y, int x); 
    549558 
    550559/* save.c */ 
     
    721730extern bool get_check(cptr prompt); 
    722731extern bool get_com(cptr prompt, char *command); 
     732extern bool get_com_ex(cptr prompt, event_type *command); 
    723733extern void pause_line(int row); 
    724734extern void request_command(bool shopping); 
  • trunk/src/main-win.c

    r63 r69  
    246246 */ 
    247247#include <windows.h> 
     248#include <windowsx.h> 
    248249 
    249250#ifdef USE_SOUND 
     
    39363937        int i; 
    39373938 
     3939        int xPos, yPos, button; 
     3940 
    39383941#ifdef USE_SAVER 
    39393942        static int iMouse = 0; 
     
    40514054                } 
    40524055 
    4053 #ifdef USE_SAVER 
    4054  
    40554056                case WM_MBUTTONDOWN: 
    40564057                case WM_RBUTTONDOWN: 
    40574058                case WM_LBUTTONDOWN: 
    40584059                { 
     4060#ifdef USE_SAVER 
    40594061                        if (screensaver_active) 
    40604062                        { 
     
    40624064                                return 0; 
    40634065                        } 
    4064  
    40654066                        break; 
    4066                 } 
    4067  
     4067#else 
     4068                        xPos = GET_X_LPARAM(lParam); 
     4069                        yPos = GET_Y_LPARAM(lParam); 
     4070                        xPos = (xPos - 13 * td->font_wid) / td->tile_wid; 
     4071                        if (use_bigtile) 
     4072                                xPos /= 2; 
     4073                        yPos = yPos / td->tile_hgt - 1; 
     4074                        if (uMsg == WM_LBUTTONDOWN) 
     4075                                button = 1; 
     4076                        else if (uMsg == WM_RBUTTONDOWN) 
     4077                                button = 2; 
     4078                        else 
     4079                                button = 3; 
     4080                        Term_mousepress(xPos,yPos,button); 
     4081                        break; 
     4082#endif /* USE_SAVER */ 
     4083                } 
     4084 
     4085#ifdef USE_SAVER 
    40684086                case WM_MOUSEMOVE: 
    40694087                { 
     
    44474465                } 
    44484466 
     4467 
    44494468#ifdef USE_SAVER 
    4450  
    44514469                case WM_MBUTTONDOWN: 
    44524470                case WM_RBUTTONDOWN: 
     
    44584476                                return 0; 
    44594477                        } 
    4460  
    44614478                        break; 
    44624479                } 
  • trunk/src/main-x11.c

    r41 r69  
    16721672        term_data *td = (term_data*)(Term->data); 
    16731673 
    1674         (*x) = (ox - Infowin->ox) / td->tile_wid; 
    1675         (*y) = (oy - Infowin->oy) / td->tile_hgt
     1674        (*x) = (ox - Infowin->ox - 13 * Infofnt->wid) / td->tile_wid; 
     1675        (*y) = (oy - Infowin->oy) / td->tile_hgt - 1
    16761676} 
    16771677 
     
    19431943        pixel_to_square(&x, &y, x, y); 
    19441944 
     1945#if 0 
    19451946        if (press && button == 1) copy_x11_start(x, y); 
    19461947        if (!press && button == 1) copy_x11_end(time); 
     1948#endif 
     1949         
     1950        if (press) Term_mousepress(x,y,button); 
    19471951} 
    19481952 
     
    20462050                        pixel_to_square(&x, &y, x, y); 
    20472051 
     2052#if 0 
    20482053                        /* Alter the selection if appropriate. */ 
    20492054                        copy_x11_cont(x, y, z); 
    2050  
     2055#endif 
     2056                         
    20512057                        break; 
    20522058                } 
  • trunk/src/types.h

    r48 r69  
    935935        s16b resting;                   /* Resting counter */ 
    936936        s16b running;                   /* Running counter */ 
     937        bool running_withpathfind;      /* Are we using the pathfinder ? */ 
    937938 
    938939        s16b run_cur_dir;               /* Direction we are running */ 
     
    947948        s16b command_rep;               /* Gives repetition of current command */ 
    948949        s16b command_dir;               /* Gives direction of current command */ 
     950        event_type command_cmd_ex; /* Gives additional information of current command */ 
    949951 
    950952        s16b command_see;               /* See "cmd1.c" */ 
  • trunk/src/util.c

    r48 r69  
    30683068bool get_com(cptr prompt, char *command) 
    30693069{ 
    3070         char ch; 
     3070        event_type ke; 
     3071        bool result; 
     3072 
     3073        result = get_com_ex(prompt, &ke); 
     3074        *command = ke.key; 
     3075 
     3076        return result; 
     3077
     3078 
     3079bool get_com_ex(cptr prompt, event_type *command) 
     3080
     3081        event_type ke; 
    30713082 
    30723083        /* Paranoia XXX XXX XXX */ 
     
    30773088 
    30783089        /* Get a key */ 
    3079         ch = inkey(); 
     3090        ke = inkey_ex(); 
    30803091 
    30813092        /* Clear the prompt */ 
     
    30833094 
    30843095        /* Save the command */ 
    3085         *command = ch
     3096        *command = ke
    30863097 
    30873098        /* Done */ 
    3088         return (ch != ESCAPE); 
     3099        return (ke.key != ESCAPE); 
    30893100} 
    30903101 
     
    31353146        int i; 
    31363147 
    3137         char ch
     3148        event_type ke
    31383149 
    31393150        int mode; 
     
    31753186 
    31763187                        /* Use auto-command */ 
    3177                         ch = (char)p_ptr->command_new; 
     3188                        ke.key = (char)p_ptr->command_new; 
    31783189 
    31793190                        /* Forget it */ 
     
    31913202 
    31923203                        /* Get a command */ 
    3193                         ch = inkey(); 
     3204                        ke = inkey_ex(); 
    31943205                } 
    31953206 
     
    31993210 
    32003211                /* Command Count */ 
    3201                 if (ch == '0') 
     3212                if (ke.key == '0') 
    32023213                { 
    32033214                        int old_arg = p_ptr->command_arg; 
     
    32133224                        { 
    32143225                                /* Get a new keypress */ 
    3215                                 ch = inkey(); 
     3226                                ke.key = inkey(); 
    32163227 
    32173228                                /* Simple editing (delete or backspace) */ 
    3218                                 if ((ch == 0x7F) || (ch == KTRL('H'))) 
     3229                                if ((ke.key == 0x7F) || (ke.key == KTRL('H'))) 
    32193230                                { 
    32203231                                        /* Delete a digit */ 
     
    32263237 
    32273238                                /* Actual numeric data */ 
    3228                                 else if (isdigit((unsigned char)ch)) 
     3239                                else if (isdigit((unsigned char)ke.key)) 
    32293240                                { 
    32303241                                        /* Stop count at 9999 */ 
     
    32423253                                        { 
    32433254                                                /* Incorporate that digit */ 
    3244                                                 p_ptr->command_arg = p_ptr->command_arg * 10 + D2I(ch); 
     3255                                                p_ptr->command_arg = p_ptr->command_arg * 10 + D2I(ke.key); 
    32453256                                        } 
    32463257 
     
    32773288 
    32783289                        /* Hack -- white-space means "enter command now" */ 
    3279                         if ((ch == ' ') || (ch == '\n') || (ch == '\r')) 
     3290                        if ((ke.key == ' ') || (ke.key == '\n') || (ke.key == '\r')) 
    32803291                        { 
    32813292                                /* Get a real command */ 
    3282                                 if (!get_com("Command: ", &ch)) 
     3293                                if (!get_com("Command: ", &ke.key)) 
    32833294                                { 
    32843295                                        /* Clear count */ 
     
    32933304 
    32943305                /* Special case for the arrow keys */ 
    3295                 if (isarrow(ch)) 
    3296                 { 
    3297                         switch (ch
     3306                if (isarrow(ke.key)) 
     3307                { 
     3308                        switch (ke.key
    32983309                        { 
    3299                                 case ARROW_DOWN:    ch = '2'; break; 
    3300                                 case ARROW_LEFT:    ch = '4'; break; 
    3301                                 case ARROW_RIGHT:   ch = '6'; break; 
    3302                                 case ARROW_UP:      ch = '8'; break; 
     3310                                case ARROW_DOWN:    ke.key = '2'; break; 
     3311                                case ARROW_LEFT:    ke.key = '4'; break; 
     3312                                case ARROW_RIGHT:   ke.key = '6'; break; 
     3313                                case ARROW_UP:      ke.key = '8'; break; 
    33033314                        } 
    33043315                } 
     
    33063317 
    33073318                /* Allow "keymaps" to be bypassed */ 
    3308                 if (ch == '\\') 
     3319                if (ke.key == '\\') 
    33093320                { 
    33103321                        /* Get a real command */ 
    3311                         (void)get_com("Command: ", &ch); 
     3322                        (void)get_com("Command: ", &ke.key); 
    33123323 
    33133324                        /* Hack -- bypass keymaps */ 
     
    33173328 
    33183329                /* Allow "control chars" to be entered */ 
    3319                 if (ch == '^') 
     3330                if (ke.key == '^') 
    33203331                { 
    33213332                        /* Get a new command and controlify it */ 
    3322                         if (get_com("Control: ", &ch)) ch = KTRL(ch); 
     3333                        if (get_com("Control: ", &ke.key)) ke.key = KTRL(ke.key); 
    33233334                } 
    33243335 
    33253336 
    33263337                /* Look up applicable keymap */ 
    3327                 act = keymap_act[mode][(byte)(ch)]; 
     3338                act = keymap_act[mode][(byte)(ke.key)]; 
    33283339 
    33293340                /* Apply keymap if not inside a keymap already */ 
     
    33433354 
    33443355                /* Paranoia */ 
    3345                 if (ch == '\0') continue; 
     3356                if (ke.key == '\0') continue; 
    33463357 
    33473358 
    33483359                /* Use command */ 
    3349                 p_ptr->command_cmd = ch; 
     3360                p_ptr->command_cmd = ke.key; 
     3361                p_ptr->command_cmd_ex = ke; 
    33503362 
    33513363                /* Done */ 
     
    34213433        /* Hack -- erase the message line. */ 
    34223434        prt("", 0, 0); 
     3435 
     3436        /* Hack again -- apply the modified key command */ 
     3437        p_ptr->command_cmd_ex.key = p_ptr->command_cmd; 
    34233438} 
    34243439 
  • trunk/src/xtra2.c

    r48 r69  
    23842384 * This function must handle blindness/hallucination. 
    23852385 */ 
    2386 static int target_set_interactive_aux(int y, int x, int mode, cptr info) 
     2386static event_type target_set_interactive_aux(int y, int x, int mode, cptr info) 
    23872387{ 
    23882388        s16b this_o_idx, next_o_idx = 0; 
     
    23962396        int feat; 
    23972397 
    2398         int query; 
     2398        event_type query; 
    23992399 
    24002400        char out_val[256]; 
     
    24052405        { 
    24062406                /* Paranoia */ 
    2407                 query = ' '; 
     2407                query.key = ' '; 
    24082408 
    24092409                /* Assume boring */ 
     
    24462446                        prt(out_val, 0, 0); 
    24472447                        move_cursor_relative(y, x); 
    2448                         query = inkey(); 
     2448                        query = inkey_ex(); 
    24492449 
    24502450                        /* Stop on everything but "return" */ 
    2451                         if ((query != '\n') && (query != '\r')) break; 
     2451                        if ((query.key != '\n') && (query.key != '\r')) break; 
    24522452 
    24532453                        /* Repeat forever */ 
     
    25002500 
    25012501                                                /* Command */ 
    2502                                                 query = inkey(); 
     2502                                                query = inkey_ex(); 
    25032503 
    25042504                                                /* Load screen */ 
     
    25342534 
    25352535                                                /* Command */ 
    2536                                                 query = inkey(); 
     2536                                                query = inkey_ex(); 
    25372537                                        } 
    25382538 
    25392539                                        /* Normal commands */ 
    2540                                         if (query != 'r') break; 
     2540                                        if (query.key != 'r') break; 
    25412541 
    25422542                                        /* Toggle recall */ 
     
    25452545 
    25462546                                /* Stop on everything but "return"/"space" */ 
    2547                                 if ((query != '\n') && (query != '\r') && (query != ' ')) break; 
     2547                                if ((query.key != '\n') && (query.key != '\r') && (query.key != ' ')) break; 
    25482548 
    25492549                                /* Sometimes stop at "space" key */ 
    2550                                 if ((query == ' ') && !(mode & (TARGET_LOOK))) break; 
     2550                                if ((query.key == ' ') && !(mode & (TARGET_LOOK))) break; 
    25512551 
    25522552                                /* Change the intro */ 
     
    25912591                                        prt(out_val, 0, 0); 
    25922592                                        move_cursor_relative(y, x); 
    2593                                         query = inkey(); 
     2593                                        query = inkey_ex(); 
    25942594 
    25952595                                        /* Stop on everything but "return"/"space" */ 
    2596                                         if ((query != '\n') && (query != '\r') && (query != ' ')) break; 
     2596                                        if ((query.key != '\n') && (query.key != '\r') && (query.key != ' ')) break; 
    25972597 
    25982598                                        /* Sometimes stop at "space" key */ 
    2599                                         if ((query == ' ') && !(mode & (TARGET_LOOK))) break; 
     2599                                        if ((query.key == ' ') && !(mode & (TARGET_LOOK))) break; 
    26002600 
    26012601                                        /* Change the intro */ 
     
    26522652                                        prt(out_val, 0, 0); 
    26532653                                        move_cursor_relative(y, x); 
    2654                                         query = inkey(); 
     2654                                        query = inkey_ex(); 
    26552655 
    26562656                                        /* Display objects */ 
    2657                                         if (query == 'r') 
     2657                                        if (query.key == 'r') 
    26582658                                        { 
    26592659                                                /* Save screen */ 
     
    26652665                                                /* Describe the pile */ 
    26662666                                                prt(out_val, 0, 0); 
    2667                                                 query = inkey(); 
     2667                                                query = inkey_ex(); 
    26682668 
    26692669                                                /* Load screen */ 
     
    26712671 
    26722672                                                /* Continue on 'r' only */ 
    2673                                                 if (query == 'r') continue; 
     2673                                                if (query.key == 'r') continue; 
    26742674                                        } 
    26752675 
     
    26792679 
    26802680                                /* Stop on everything but "return"/"space" */ 
    2681                                 if ((query != '\n') && (query != '\r') && (query != ' ')) break; 
     2681                                if ((query.key != '\n') && (query.key != '\r') && (query.key != ' ')) break; 
    26822682 
    26832683                                /* Sometimes stop at "space" key */ 
    2684                                 if ((query == ' ') && !(mode & (TARGET_LOOK))) break; 
     2684                                if ((query.key == ' ') && !(mode & (TARGET_LOOK))) break; 
    26852685 
    26862686                                /* Change the intro */ 
     
    27322732                                prt(out_val, 0, 0); 
    27332733                                move_cursor_relative(y, x); 
    2734                                 query = inkey(); 
     2734                                query = inkey_ex(); 
    27352735 
    27362736                                /* Stop on everything but "return"/"space" */ 
    2737                                 if ((query != '\n') && (query != '\r') && (query != ' ')) break; 
     2737                                if ((query.key != '\n') && (query.key != '\r') && (query.key != ' ')) break; 
    27382738 
    27392739                                /* Sometimes stop at "space" key */ 
    2740                                 if ((query == ' ') && !(mode & (TARGET_LOOK))) break; 
     2740                                if ((query.key == ' ') && !(mode & (TARGET_LOOK))) break; 
    27412741 
    27422742                                /* Change the intro */ 
     
    27992799                        prt(out_val, 0, 0); 
    28002800                        move_cursor_relative(y, x); 
    2801                         query = inkey(); 
     2801                        query = inkey_ex(); 
    28022802 
    28032803                        /* Stop on everything but "return"/"space" */ 
    2804                         if ((query != '\n') && (query != '\r') && (query != ' ')) break; 
     2804                        if ((query.key != '\n') && (query.key != '\r') && (query.key != ' ')) break; 
    28052805                } 
    28062806 
    28072807                /* Stop on everything but "return" */ 
    2808                 if ((query != '\n') && (query != '\r')) break; 
     2808                if ((query.key != '\n') && (query.key != '\r')) break; 
    28092809        } 
    28102810 
     
    28712871        bool flag = TRUE; 
    28722872 
    2873         char query; 
     2873        event_type query; 
    28742874 
    28752875        char info[80]; 
     
    29282928 
    29292929                        /* Analyze */ 
    2930                         switch (query
     2930                        switch (query.key
    29312931                        { 
    29322932                                case ESCAPE: 
     
    29782978                                } 
    29792979 
     2980                                case '\xff': 
     2981                                { 
     2982                                        x = query.mousex + Term->offset_x; 
     2983                                        y = query.mousey + Term->offset_y; 
     2984                                        target_set_location(y, x); 
     2985                                        done = TRUE; 
     2986                                        break; 
     2987                                } 
    29802988                                case 't': 
    29812989                                case '5': 
     
    29983006                                } 
    29993007 
     3008                                case 'g': 
     3009                                { 
     3010                                        do_cmd_pathfind(y,x); 
     3011                                        done = TRUE; 
     3012                                        break; 
     3013                                } 
     3014 
    30003015                                default: 
    30013016                                { 
    30023017                                        /* Extract direction */ 
    3003                                         d = target_dir(query); 
     3018                                        d = target_dir(query.key); 
    30043019 
    30053020                                        /* Oops */ 
     
    30673082 
    30683083                        /* Analyze the keypress */ 
    3069                         switch (query
     3084                        switch (query.key
    30703085                        { 
    30713086                                case ESCAPE: 
     
    31273142                                } 
    31283143 
     3144                                case '\xff': 
     3145                                { 
     3146                                        x = query.mousex + Term->offset_x; 
     3147                                        y = query.mousey + Term->offset_y; 
     3148                                } 
    31293149                                case 't': 
    31303150                                case '5': 
     
    31373157                                } 
    31383158 
     3159                                case 'g': 
     3160                                { 
     3161                                        do_cmd_pathfind(y,x); 
     3162                                        done = TRUE; 
     3163                                        break; 
     3164                                } 
     3165 
    31393166                                default: 
    31403167                                { 
    31413168                                        /* Extract a direction */ 
    3142                                         d = target_dir(query); 
     3169                                        d = target_dir(query.key); 
    31433170 
    31443171                                        /* Oops */ 
     
    32203247        int dir; 
    32213248 
    3222         char ch
     3249        event_type ke
    32233250 
    32243251        cptr p; 
     
    32653292 
    32663293                /* Get a command (or Cancel) */ 
    3267                 if (!get_com(p, &ch)) break; 
     3294                if (!get_com_ex(p, &ke)) break; 
    32683295 
    32693296                /* Analyze */ 
    3270                 switch (ch) 
    3271                 { 
     3297                switch (ke.key) 
     3298                { 
     3299                        /* Mouse aiming */ 
     3300                        case '\xff': 
     3301                        { 
     3302                                target_set_location(ke.mousey + Term->offset_y, ke.mousex + Term->offset_x); 
     3303                                dir = 5; 
     3304                                break; 
     3305                        } 
     3306                         
    32723307                        /* Set new target, use target if legal */ 
    32733308                        case '*': 
     
    32903325                        default: 
    32913326                        { 
    3292                                 dir = target_dir(ch); 
     3327                                dir = target_dir(ke.key); 
    32933328                                break; 
    32943329                        }