Changeset 638

Show
Ignore:
Timestamp:
12/23/07 19:18:51 (9 months ago)
Author:
takkaria
Message:

Another try and sorting out the issue behind #263:

  • Move map_area() to the same place as the detection spells in spells2.c.
  • Try a different approach at detection: make all of magic mapping & detect trap/door/stair/monster/item/treasure use the same width&height rectangular area around the player.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/cave.c

    r633 r638  
    31543154 
    31553155/* 
    3156  * Map a radius 30 area around the player. 
    3157  * 
    3158  * We must never attempt to map the outer dungeon walls, or we 
    3159  * might induce illegal cave grid references. 
    3160  */ 
    3161 void map_area(void) 
    3162 { 
    3163         int i, x, y; 
    3164  
    3165         /* Scan the dungeon */ 
    3166         for (y = 1; y < DUNGEON_HGT - 1; y++) 
    3167         { 
    3168                 for (x = 1; x < DUNGEON_WID - 1; x++) 
    3169                 { 
    3170                         /* All non-walls are "checked" */ 
    3171                         if (cave_feat[y][x] < FEAT_SECRET) 
    3172                         { 
    3173                                 if (!in_bounds_fully(y, x)) continue; 
    3174  
    3175                                 /* Restrict to being in a certain radius */ 
    3176                                 if (distance(p_ptr->py, p_ptr->px, y, x) > 30) continue; 
    3177  
    3178                                 /* Memorize normal features */ 
    3179                                 if (cave_feat[y][x] > FEAT_INVIS) 
    3180                                 { 
    3181                                         /* Memorize the object */ 
    3182                                         cave_info[y][x] |= (CAVE_MARK); 
    3183                                         lite_spot(y, x); 
    3184                                 } 
    3185  
    3186                                 /* Memorize known walls */ 
    3187                                 for (i = 0; i < 8; i++) 
    3188                                 { 
    3189                                         int yy = y + ddy_ddd[i]; 
    3190                                         int xx = x + ddx_ddd[i]; 
    3191  
    3192                                         /* Memorize walls (etc) */ 
    3193                                         if (cave_feat[yy][xx] >= FEAT_SECRET) 
    3194                                         { 
    3195                                                 /* Memorize the walls */ 
    3196                                                 cave_info[yy][xx] |= (CAVE_MARK); 
    3197                                                 lite_spot(yy, xx); 
    3198                                         } 
    3199                                 } 
    3200                         } 
    3201                 } 
    3202         } 
    3203 } 
    3204  
    3205  
    3206  
    3207 /* 
    32083156 * Light up the dungeon using "claravoyance" 
    32093157 * 
  • trunk/src/spells2.c

    r636 r638  
    943943 
    944944 
    945 /* 
    946  * Old covered area on a 80x24 screen was around 66*22 = 1452 
    947  * New covered area from circular detection 3.14*22*22 = 1962 
     945/*** Detection spells ***/ 
     946 
     947/* 
     948 * Useful constants for the area around the player to detect. 
     949 * This is instead of using circular detection spells. 
     950 */ 
     951#define DETECT_DIST_X   26      /* Detect 26 grids to the left & right */ 
     952#define DETECT_DIST_Y   55      /* Detect 55 grids to the top & bottom */ 
     953 
     954 
     955 
     956/* 
     957 * Map an area around the player. 
    948958 * 
    949  * A slight gain, but I think an OK one. 
    950  */ 
    951 #define DET_RADIUS   22 
    952  
    953  
    954 /* 
    955  * Detect all traps inside radius 22. 
     959 * We must never attempt to map the outer dungeon walls, or we 
     960 * might induce illegal cave grid references. 
     961 */ 
     962void map_area(void) 
     963
     964        int i, x, y; 
     965        int x1, x2, y1, y2; 
     966 
     967        /* Pick an area to map */ 
     968        y1 = p_ptr->py - DETECT_DIST_Y; 
     969        y2 = p_ptr->py + DETECT_DIST_Y; 
     970        x1 = p_ptr->px - DETECT_DIST_X; 
     971        x2 = p_ptr->px + DETECT_DIST_X; 
     972 
     973        if (y1 < 0) y1 = 0; 
     974        if (x1 < 0) x1 = 0; 
     975 
     976        /* Scan the dungeon */ 
     977        for (y = y1; y < y2; y++) 
     978        { 
     979                for (x = x1; x < x2; x++) 
     980                { 
     981                        /* All non-walls are "checked" */ 
     982                        if (cave_feat[y][x] < FEAT_SECRET) 
     983                        { 
     984                                if (!in_bounds_fully(y, x)) continue; 
     985 
     986                                /* Memorize normal features */ 
     987                                if (cave_feat[y][x] > FEAT_INVIS) 
     988                                { 
     989                                        /* Memorize the object */ 
     990                                        cave_info[y][x] |= (CAVE_MARK); 
     991                                        lite_spot(y, x); 
     992                                } 
     993 
     994                                /* Memorize known walls */ 
     995                                for (i = 0; i < 8; i++) 
     996                                { 
     997                                        int yy = y + ddy_ddd[i]; 
     998                                        int xx = x + ddx_ddd[i]; 
     999 
     1000                                        /* Memorize walls (etc) */ 
     1001                                        if (cave_feat[yy][xx] >= FEAT_SECRET) 
     1002                                        { 
     1003                                                /* Memorize the walls */ 
     1004                                                cave_info[yy][xx] |= (CAVE_MARK); 
     1005                                                lite_spot(yy, xx); 
     1006                                        } 
     1007                                } 
     1008                        } 
     1009                } 
     1010        } 
     1011
     1012 
     1013 
     1014 
     1015/* 
     1016 * Detect traps around the player. 
    9561017 */ 
    9571018bool detect_traps(void) 
    9581019{ 
    9591020        int y, x; 
     1021        int x1, x2, y1, y2; 
    9601022 
    9611023        bool detect = FALSE; 
    9621024 
     1025        /* Pick an area to map */ 
     1026        y1 = p_ptr->py - DETECT_DIST_Y; 
     1027        y2 = p_ptr->py + DETECT_DIST_Y; 
     1028        x1 = p_ptr->px - DETECT_DIST_X; 
     1029        x2 = p_ptr->px + DETECT_DIST_X; 
     1030 
     1031        if (y1 < 0) y1 = 0; 
     1032        if (x1 < 0) x1 = 0; 
     1033 
    9631034 
    9641035        /* Scan the dungeon */ 
    965         for (y = 1; y < DUNGEON_HGT - 1; y++) 
    966         { 
    967                 for (x = 1; x < DUNGEON_WID - 1; x++) 
     1036        for (y = y1; y < y2; y++) 
     1037        { 
     1038                for (x = x1; x < x2; x++) 
    9681039                { 
    9691040                        if (!in_bounds_fully(y, x)) continue; 
    970  
    971                         /* Restrict to being in a certain radius */ 
    972                         if (distance(p_ptr->py, p_ptr->px, y, x) > DET_RADIUS) continue; 
    9731041 
    9741042                        /* Detect invisible traps */ 
     
    10121080 
    10131081/* 
    1014  * Detect all doors and stairs
     1082 * Detect doors and stairs around the player
    10151083 */ 
    10161084bool detect_doorstairs(void) 
    10171085{ 
    10181086        int y, x; 
     1087        int x1, x2, y1, y2; 
     1088 
    10191089        bool doors = FALSE, stairs = FALSE; 
    10201090 
    10211091 
     1092        /* Pick an area to map */ 
     1093        y1 = p_ptr->py - DETECT_DIST_Y; 
     1094        y2 = p_ptr->py + DETECT_DIST_Y; 
     1095        x1 = p_ptr->px - DETECT_DIST_X; 
     1096        x2 = p_ptr->px + DETECT_DIST_X; 
     1097 
     1098        if (y1 < 0) y1 = 0; 
     1099        if (x1 < 0) x1 = 0; 
     1100 
     1101 
    10221102        /* Scan the dungeon */ 
    1023         for (y = 1; y < DUNGEON_HGT - 1; y++) 
    1024         { 
    1025                 for (x = 1; x < DUNGEON_WID - 1; x++) 
     1103        for (y = y1; y < y2; y++) 
     1104        { 
     1105                for (x = x1; x < x2; x++) 
    10261106                { 
    10271107                        if (!in_bounds_fully(y, x)) continue; 
     
    10751155 
    10761156/* 
    1077  * Detect any treasure inside radius 22
     1157 * Detect all treasure around the player
    10781158 */ 
    10791159bool detect_treasure(void) 
     
    10811161        int i; 
    10821162        int y, x; 
     1163        int x1, x2, y1, y2; 
    10831164 
    10841165        bool gold_buried = FALSE; 
     
    10871168 
    10881169 
     1170        /* Pick an area to map */ 
     1171        y1 = p_ptr->py - DETECT_DIST_Y; 
     1172        y2 = p_ptr->py + DETECT_DIST_Y; 
     1173        x1 = p_ptr->px - DETECT_DIST_X; 
     1174        x2 = p_ptr->px + DETECT_DIST_X; 
     1175 
     1176        if (y1 < 0) y1 = 0; 
     1177        if (x1 < 0) x1 = 0; 
     1178 
     1179 
    10891180        /* Scan the dungeon */ 
    1090         for (y = 1; y < DUNGEON_HGT - 1; y++) 
    1091         { 
    1092                 for (x = 1; x < DUNGEON_WID - 1; x++) 
     1181        for (y = y1; y < y2; y++) 
     1182        { 
     1183                for (x = x1; x < x2; x++) 
    10931184                { 
    10941185                        if (!in_bounds_fully(y, x)) continue; 
     
    11331224                x = o_ptr->ix; 
    11341225 
     1226                /* Only detect nearby objects */ 
     1227                if (x < x1 || y < y1 || x > x2 || y > y2) continue; 
     1228 
    11351229                /* Hack -- memorize it */ 
    11361230                o_ptr->marked = TRUE; 
     
    11581252 
    11591253/* 
    1160  * Detect all "magic" objects inside radius 22
     1254 * Detect "magic" objects around the player
    11611255 * 
    11621256 * This will light up all spaces with "magic" items, including artifacts, 
     
    11691263{ 
    11701264        int i, y, x, tv; 
     1265        int x1, x2, y1, y2; 
    11711266 
    11721267        bool detect = FALSE; 
     1268 
     1269 
     1270        /* Pick an area to map */ 
     1271        y1 = p_ptr->py - DETECT_DIST_Y; 
     1272        y2 = p_ptr->py + DETECT_DIST_Y; 
     1273        x1 = p_ptr->px - DETECT_DIST_X; 
     1274        x2 = p_ptr->px + DETECT_DIST_X; 
     1275 
     1276        if (y1 < 0) y1 = 0; 
     1277        if (x1 < 0) x1 = 0; 
    11731278 
    11741279 
     
    11881293                x = o_ptr->ix; 
    11891294 
     1295 
    11901296                /* Only detect nearby objects */ 
    1191                 if (distance(p_ptr->py, p_ptr->px, y, x) > DET_RADIUS) continue; 
     1297                if (x < x1 || y < y1 || x > x2 || y > y2) continue; 
    11921298 
    11931299                /* Examine the tval */ 
     
    12221328 
    12231329/* 
    1224  * Detect all "normal" monsters inside radius 22
     1330 * Detect "normal" monsters around the player
    12251331 */ 
    12261332bool detect_monsters_normal(void) 
    12271333{ 
    12281334        int i, y, x; 
     1335        int x1, x2, y1, y2; 
    12291336 
    12301337        bool flag = FALSE; 
     1338 
     1339 
     1340        /* Pick an area to map */ 
     1341        y1 = p_ptr->py - DETECT_DIST_Y; 
     1342        y2 = p_ptr->py + DETECT_DIST_Y; 
     1343        x1 = p_ptr->px - DETECT_DIST_X; 
     1344        x2 = p_ptr->px + DETECT_DIST_X; 
     1345 
     1346        if (y1 < 0) y1 = 0; 
     1347        if (x1 < 0) x1 = 0; 
     1348 
    12311349 
    12321350 
     
    12451363 
    12461364                /* Only detect nearby monsters */ 
    1247                 if (distance(p_ptr->py, p_ptr->px, y, x) > DET_RADIUS) continue; 
     1365                if (x < x1 || y < y1 || x > x2 || y > y2) continue; 
    12481366 
    12491367                /* Detect all non-invisible monsters */ 
     
    12731391 
    12741392/* 
    1275  * Detect all "invisible" monsters inside radius 22
     1393 * Detect "invisible" monsters around the player
    12761394 */ 
    12771395bool detect_monsters_invis(void) 
    12781396{ 
    12791397        int i, y, x; 
     1398        int x1, x2, y1, y2; 
    12801399 
    12811400        bool flag = FALSE; 
     1401 
     1402        /* Pick an area to map */ 
     1403        y1 = p_ptr->py - DETECT_DIST_Y; 
     1404        y2 = p_ptr->py + DETECT_DIST_Y; 
     1405        x1 = p_ptr->px - DETECT_DIST_X; 
     1406        x2 = p_ptr->px + DETECT_DIST_X; 
     1407 
     1408        if (y1 < 0) y1 = 0; 
     1409        if (x1 < 0) x1 = 0; 
    12821410 
    12831411 
     
    12961424                x = m_ptr->fx; 
    12971425 
    1298                 /* Only detect nearby monsters */ 
    1299                 if (distance(p_ptr->py, p_ptr->px, y, x) > DET_RADIUS) continue; 
     1426                /* Only detect nearby objects */ 
     1427                if (x < x1 || y < y1 || x > x2 || y > y2) continue; 
    13001428 
    13011429                /* Detect invisible monsters */ 
     
    13351463 
    13361464/* 
    1337  * Detect all "evil" monsters inside radius 22
     1465 * Detect "evil" monsters around the player
    13381466 */ 
    13391467bool detect_monsters_evil(void) 
    13401468{ 
    13411469        int i, y, x; 
     1470        int x1, x2, y1, y2; 
    13421471 
    13431472        bool flag = FALSE; 
     1473 
     1474        /* Pick an area to map */ 
     1475        y1 = p_ptr->py - DETECT_DIST_Y; 
     1476        y2 = p_ptr->py + DETECT_DIST_Y; 
     1477        x1 = p_ptr->px - DETECT_DIST_X; 
     1478        x2 = p_ptr->px + DETECT_DIST_X; 
     1479 
     1480        if (y1 < 0) y1 = 0; 
     1481        if (x1 < 0) x1 = 0; 
    13441482 
    13451483 
     
    13581496                x = m_ptr->fx; 
    13591497 
    1360                 /* Only detect nearby monsters */ 
    1361                 if (distance(p_ptr->py, p_ptr->px, y, x) > DET_RADIUS) continue; 
     1498                /* Only detect nearby objects */ 
     1499                if (x < x1 || y < y1 || x > x2 || y > y2) continue; 
    13621500 
    13631501                /* Detect evil monsters */