Changeset 819

Show
Ignore:
Timestamp:
03/26/08 12:57:49 (2 years ago)
Author:
ajps
Message:

Revised the way mouse click targetting works to fix #326 and #327 - it
should now actually be possible to target and look around using clicks.

New behaviour is that first click moves the cursor and 'looks', another
click in the place highlighted carries out the action (setting target,
launching projectile, whatever). Clicks on monsters target monsters,
otherwise the grid is targetted.

Location:
trunk/src
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/cmd3.c

    r789 r819  
    489489{ 
    490490        /* Target set */ 
    491         if (target_set_interactive(TARGET_KILL)) 
     491        if (target_set_interactive(TARGET_KILL, -1, -1)) 
    492492        { 
    493493                msg_print("Target Selected."); 
     
    509509{ 
    510510        /* Look around */ 
    511         if (target_set_interactive(TARGET_LOOK)) 
     511        if (target_set_interactive(TARGET_LOOK, -1, -1)) 
    512512        { 
    513513                msg_print("Target Selected."); 
  • trunk/src/externs.h

    r816 r819  
    570570void target_set_monster(int m_idx); 
    571571void target_set_location(int y, int x); 
    572 bool target_set_interactive(int mode); 
     572bool target_set_interactive(int mode, int x, int y); 
    573573bool get_aim_dir(int *dp); 
    574574void target_get(s16b *col, s16b *row); 
  • trunk/src/target.c

    r789 r819  
    495495 
    496496        char out_val[256]; 
    497  
    498497 
    499498        /* Repeat forever */ 
     
    920919 * This command will cancel any old target, even if used from 
    921920 * inside the "look" command. 
    922  */ 
    923 bool target_set_interactive(int mode) 
     921 * 
     922 * 
     923 * 'mode' is one of TARGET_LOOK or TARGET_KILL. 
     924 * 'x' and 'y' are the initial position of the target to be highlighted, 
     925 * or -1 if no location is specified. 
     926 * Returns TRUE if a target has been successfully set, FALSE otherwise. 
     927 */ 
     928bool target_set_interactive(int mode, int x, int y) 
    924929{ 
    925         int py = p_ptr->py; 
    926         int px = p_ptr->px; 
    927  
    928930        int i, d, m, t, bd; 
    929931 
    930         int y = py; 
    931         int x = px; 
    932  
    933932        bool done = FALSE; 
    934933 
     
    939938        char info[80]; 
    940939 
     940        /* If we haven't been given an initial location, start on the 
     941           player. */ 
     942        if (x == -1 || y == -1) 
     943        { 
     944                x = p_ptr->px; 
     945                y = p_ptr->py; 
     946        } 
     947    /* If we /have/ been given an initial location, make sure we 
     948           honour it by going into "free targetting" mode. */ 
     949        else 
     950        { 
     951                flag = FALSE; 
     952        } 
    941953 
    942954        /* Cancel target */ 
     
    10271039                                        handle_stuff(); 
    10281040 
    1029                                         y = py; 
    1030                                         x = px; 
     1041                                        y = p_ptr->py; 
     1042                                        x = p_ptr->px; 
    10311043                                } 
    10321044 
     
    10421054                                } 
    10431055 
     1056                                /* If we click, move the target location to the click and 
     1057                                   switch to "free targetting" mode by unsetting 'flag'. 
     1058                                   This means we get some info about wherever we've picked. */ 
    10441059                                case '\xff': 
    10451060                                { 
    1046                                         x = query.mousex + Term->offset_x; 
    1047                                         y = query.mousey + Term->offset_y; 
    1048                                         target_set_location(y, x); 
    1049                                         done = TRUE; 
     1061                                        x = KEY_GRID_X(query); 
     1062                                        y = KEY_GRID_Y(query); 
     1063                                        flag = FALSE; 
    10501064                                        break; 
    10511065                                } 
     
    11711185                                        handle_stuff(); 
    11721186 
    1173                                         y = py; 
    1174                                         x = px; 
     1187                                        y = p_ptr->py; 
     1188                                        x = p_ptr->px; 
    11751189                                } 
    11761190 
     
    12081222                                case '\xff': 
    12091223                                { 
    1210                                         x = query.mousex + Term->offset_x; 
    1211                                         y = query.mousey + Term->offset_y; 
     1224                                        /* We only target if we click somewhere where the cursor 
     1225                                           is already (i.e. a double-click without a time limit) */ 
     1226                                        if (KEY_GRID_X(query) == x && KEY_GRID_Y(query) == y) 
     1227                                        { 
     1228                                                /* Make an attempt to target the monster on the given 
     1229                                                   square rather than the square itself (it seems this 
     1230                                                   is the more likely intention of clicking on a  
     1231                                                   monster). */ 
     1232                                                int m_idx = cave_m_idx[y][x]; 
     1233 
     1234                                                if ((m_idx > 0) && target_able(m_idx)) 
     1235                                                { 
     1236                                                        health_track(m_idx); 
     1237                                                        target_set_monster(m_idx); 
     1238                                                } 
     1239                                                else 
     1240                                                { 
     1241                                                        /* There is no monster, or it isn't targettable, 
     1242                                                           so target the location instead. */ 
     1243                                                        target_set_location(y, x); 
     1244                                                } 
     1245 
     1246                                                done = TRUE; 
     1247                                        } 
     1248                                        else 
     1249                                        { 
     1250                                                /* Just move the cursor for now - another click will 
     1251                                                   target. */ 
     1252                                                x = KEY_GRID_X(query); 
     1253                                                y = KEY_GRID_Y(query); 
     1254                                        } 
     1255                                        break; 
    12121256                                } 
    12131257                                case 't': 
  • trunk/src/xtra2.c

    r816 r819  
    19611961                else 
    19621962                { 
    1963                         p = "Direction ('5' or <click> for target, '*' to re-target, Escape to cancel)? "; 
     1963                        p = "Direction ('5' for target, '*' or <click> to re-target, Escape to cancel)? "; 
    19641964                } 
    19651965 
     
    19731973                        case '\xff': 
    19741974                        { 
    1975                                 target_set_location(ke.mousey + Term->offset_y, ke.mousex + Term->offset_x); 
    1976                                 dir = 5; 
     1975                                if (target_set_interactive(TARGET_KILL, KEY_GRID_X(ke), KEY_GRID_Y(ke))) 
     1976                                        dir = 5; 
     1977 
    19771978                                break; 
    19781979                        } 
     
    19811982                        case '*': 
    19821983                        { 
    1983                                 if (target_set_interactive(TARGET_KILL)) dir = 5; 
     1984                                if (target_set_interactive(TARGET_KILL, -1, -1)) dir = 5; 
    19841985                                break; 
    19851986                        }