Changeset 472

Show
Ignore:
Timestamp:
08/09/07 09:35:57 (1 year ago)
Author:
ajps
Message:

Change the way we "view" maps, so that map_info returns information
about what the player knows about the map location, and a new function
grid_data_as_text converts this information into the char/attr
combinations to be displayed. Breaks hallucination (in fact disables
it), but everything else seems OK.

Files:

Legend:

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

    r468 r472  
    445445} 
    446446 
    447  
    448 static void special_lighting_floor(byte *a, char *c, int info) 
    449 
    450         /* Handle "seen" grids */ 
    451         if (info & (CAVE_SEEN)) 
    452         { 
    453                 /* Only lit by "torch" lite */ 
    454                 if (view_yellow_lite && !(info & (CAVE_GLOW))) 
    455                 { 
    456                         /* Use a brightly lit tile */ 
    457                         switch (use_graphics) 
    458                         { 
    459                                 case GRAPHICS_NONE: 
    460                                 case GRAPHICS_PSEUDO: 
    461                                         /* Use "yellow" */ 
    462                                         if (*a == TERM_WHITE) *a = TERM_YELLOW; 
    463                                         break; 
    464                                 case GRAPHICS_ADAM_BOLT: 
    465                                         *c += 2; 
    466                                         break; 
    467                                 case GRAPHICS_DAVID_GERVAIS: 
    468                                         *c -= 1; 
    469                                         break; 
    470                         } 
    471                 } 
    472         } 
    473  
    474         /* Handle "dark" grids and "blindness" */ 
    475         else if ((p_ptr->timed[TMD_BLIND]) || (!(info & CAVE_GLOW))) 
     447/* 
     448 * This function modifies the attr/char pair for an empty floor space 
     449 * to reflect the various lighting options available. 
     450 * 
     451 * For text, this means changing the colouring for view_yellow_lite or 
     452 * view_bright_lite, and for graphics it means modifying the char to 
     453 * use a different tile in the tileset.  These modifications are different 
     454 * for different sets, depending on the tiles available, and their position  
     455 * in the set. 
     456 */ 
     457static void special_lighting_floor(byte *a, char *c, enum grid_light_level lighting, bool in_view) 
     458
     459        /* The floor starts off "lit" - i.e. rendered in white or the default  
     460         * tile. */ 
     461 
     462        if (lighting == LIGHT_TORCH && view_yellow_lite) 
     463        { 
     464                /*  
     465                 * view_yellow_lite distinguishes between torchlit and  
     466                 * permanently-lit areas  
     467                 */ 
     468                switch (use_graphics) 
     469                { 
     470                        case GRAPHICS_NONE: 
     471                        case GRAPHICS_PSEUDO: 
     472                                /* Use "yellow" */ 
     473                                if (*a == TERM_WHITE) *a = TERM_YELLOW; 
     474                                break; 
     475                        case GRAPHICS_ADAM_BOLT: 
     476                                *c += 2; 
     477                                break; 
     478                        case GRAPHICS_DAVID_GERVAIS: 
     479                                *c -= 1; 
     480                                                break; 
     481                } 
     482        } 
     483        else if (lighting == LIGHT_DARK) 
    476484        { 
    477485                /* Use a dark tile */ 
     
    489497                } 
    490498        } 
    491  
    492         /* Handle "view_bright_lite" */ 
    493         else if (view_bright_lite) 
    494         { 
    495                 switch (use_graphics) 
    496                 { 
    497                         case GRAPHICS_NONE: 
    498                         case GRAPHICS_PSEUDO: 
    499                                 /* Use "gray" */ 
    500                                 if (*a == TERM_WHITE) *a = TERM_SLATE; 
    501                                 break; 
    502                         case GRAPHICS_ADAM_BOLT: 
    503                         case GRAPHICS_DAVID_GERVAIS: 
    504                                 *c += 1; 
    505                                 break; 
    506                 } 
    507         } 
    508 
    509  
    510  
    511 static void special_lighting_wall(byte *a, char *c, int feat, int info) 
    512 
    513         /* Handle "seen" grids */ 
    514         if (info & (CAVE_SEEN)) 
    515         { 
    516                 /* Do nothing */ 
    517         } 
    518  
    519         /* Handle "blind" */ 
    520         else if (p_ptr->timed[TMD_BLIND]) 
     499        else 
     500        { 
     501                /*  
     502                 * view_bright_lite makes tiles that aren't in the "eyeline"  
     503                 * of the player show up dimmer than those that are. 
     504                 */ 
     505                if (view_bright_lite && !in_view) 
     506                { 
     507                        switch (use_graphics) 
     508                        { 
     509                                case GRAPHICS_NONE: 
     510                                case GRAPHICS_PSEUDO: 
     511                                        /* Use "gray" */ 
     512                                        if (*a == TERM_WHITE) *a = TERM_SLATE; 
     513                                        break; 
     514                                case GRAPHICS_ADAM_BOLT: 
     515                                case GRAPHICS_DAVID_GERVAIS: 
     516                                        *c += 1; 
     517                                        break; 
     518                        } 
     519                } 
     520        } 
     521
     522 
     523/* 
     524 * This function modifies the attr/char pair for an wall grids 
     525 * to reflect the various lighting options available. 
     526 * 
     527 * For text, this means changing the colouring for dark grids or 
     528 * view_bright_lite, and for graphics it means modifying the char to 
     529 * use a different tile in the tileset.  These modifications are different 
     530 * for different sets, depending on the tiles available, and their position  
     531 * in the set. 
     532 */ 
     533static void special_lighting_wall(byte *a, char *c, enum grid_light_level lighting, bool in_view, int feat) 
     534
     535        /* Grids currently in view are left alone. */ 
     536        if (in_view) return; 
     537 
     538        if (lighting == LIGHT_DARK) 
    521539        { 
    522540                switch (use_graphics) 
     
    567585 
    568586/* 
    569  * Extract the attr/char to display at the given (legal) map location 
    570  * 
    571  * Note that this function, since it is called by "lite_spot()" which 
    572  * is called by "update_view()", is a major efficiency concern. 
    573  * 
    574  * Basically, we examine each "layer" of the world (terrain, objects, 
    575  * monsters/players), from the bottom up, extracting a new attr/char 
    576  * if necessary at each layer, and defaulting to "darkness".  This is 
    577  * not the fastest method, but it is very simple, and it is about as 
    578  * fast as it could be for grids which contain no "marked" objects or 
    579  * "visible" monsters. 
    580  * 
    581  * We apply the effects of hallucination during each layer.  Objects will 
    582  * always appear as random "objects", monsters will always appear as random 
    583  * "monsters", and normal grids occasionally appear as random "monsters" or 
    584  * "objects", but note that these random "monsters" and "objects" are really 
    585  * just "colored ascii symbols" (which may look silly on some machines). 
    586  * 
    587  * The hallucination functions avoid taking any pointers to local variables 
    588  * because some compilers refuse to use registers for any local variables 
    589  * whose address is taken anywhere in the function. 
    590  * 
    591  * As an optimization, we can handle the "player" grid as a special case. 
    592  * 
    593  * Note that the memorization of "objects" and "monsters" is not related 
    594  * to the memorization of "terrain".  This allows the player to memorize 
    595  * the terrain of a grid without memorizing any objects in that grid, and 
    596  * to detect monsters without detecting anything about the terrain of the 
    597  * grid containing the monster. 
    598  * 
    599  * The fact that all interesting "objects" and "terrain features" are 
    600  * memorized as soon as they become visible for the first time means 
    601  * that we only have to check the "CAVE_SEEN" flag for "boring" grids. 
    602  * 
    603  * Note that bizarre things must be done when the "attr" and/or "char" 
    604  * codes have the "high-bit" set, since these values are used to encode 
    605  * various "special" pictures in some versions, and certain situations, 
    606  * such as "multi-hued" or "clear" monsters, cause the attr/char codes 
    607  * to be "scrambled" in various ways. 
    608  * 
    609  * Note that the "zero" entry in the feature/object/monster arrays are 
     587 * This function takes a pointer to a grid info struct describing the  
     588 * contents of a grid location (as obtained through the function map_info) 
     589 * and fills in the character and attr pairs for display. 
     590 * 
     591 * ap and cp are filled with the attr/char pair for the monster, object or  
     592 * floor tile that is at the "top" of the grid (monsters covering objects,  
     593 * which cover floor, assuming all are present). 
     594 * 
     595 * tap and tcp are filled with the attr/char pair for the floor, regardless 
     596 * of what is on it.  This can be used by graphical displays with 
     597 * transparency to place an object onto a floor tile, is desired. 
     598 * 
     599 * Any lighting effects are also applied to these pairs, clear monsters allow 
     600 * the underlying colour or feature to show through (ATTR_CLEAR and 
     601 * CHAR_CLEAR), multi-hued colour-changing (ATTR_MULTI) is applied, and so on. 
     602 * Technically, the flag "CHAR_MULTI" is supposed to indicate that a monster  
     603 * looks strange when examined, but this flag is currently ignored. 
     604 * 
     605 * NOTES: 
     606 * This is called pretty frequently, whenever a grid on the map display 
     607 * needs updating, so don't overcomplicate it. 
     608 * 
     609 * The "zero" entry in the feature/object/monster arrays are 
    610610 * used to provide "special" attr/char codes, with "monster zero" being 
    611611 * used for the player attr/char, "object zero" being used for the "pile" 
    612612 * attr/char, and "feature zero" being used for the "darkness" attr/char. 
    613613 * 
    614  * Note that eventually we may want to use the "&" symbol for embedded 
    615  * treasure, and use the "*" symbol to indicate multiple objects, but 
    616  * currently, we simply use the attr/char of the first "marked" object 
    617  * in the stack, if any, and so "object zero" is unused.  XXX XXX XXX 
    618  * 
    619  * Note the assumption that doing "x_ptr = &x_info[x]" plus a few of 
    620  * "x_ptr->xxx", is quicker than "x_info[x].xxx", even if "x" is a fixed 
    621  * constant.  If this is incorrect then a lot of code should be changed. 
    622  * 
    623  * 
    624  * Some comments on the "terrain" layer... 
    625  * 
    626  * Note that "boring" grids (floors, invisible traps, and any illegal grids) 
    627  * are very different from "interesting" grids (all other terrain features), 
    628  * and the two types of grids are handled completely separately.  The most 
    629  * important distinction is that "boring" grids may or may not be memorized 
    630  * when they are first encountered, and so we must use the "CAVE_SEEN" flag 
    631  * to see if they are "see-able". 
    632  * 
    633  * 
    634  * Some comments on the "terrain" layer (boring grids)... 
    635  * 
    636  * Note that "boring" grids are always drawn using the picture for "empty 
    637  * floors", which is stored in "f_info[FEAT_FLOOR]".  Sometimes, special 
    638  * lighting effects may cause this picture to be modified. 
    639  * 
    640  * Note that "invisible traps" are always displayes exactly like "empty 
    641  * floors", which prevents various forms of "cheating", with no loss of 
    642  * efficiency.  There are still a few ways to "guess" where traps may be 
    643  * located, for example, objects will never fall into a grid containing 
    644  * an invisible trap.  XXX XXX 
    645  * 
    646  * To determine if a "boring" grid should be displayed, we simply check to 
    647  * see if it is either memorized ("CAVE_MARK"), or currently "see-able" by 
    648  * the player ("CAVE_SEEN").  Note that "CAVE_SEEN" is now maintained by the 
    649  * "update_view()" function. 
    650  * 
    651  * Note the "special lighting effects" which can be activated for "boring" 
    652  * grids using the "view_special_lite" option, causing certain such grids 
    653  * to be displayed using special colors (if they are normally "white"). 
    654  * If the grid is "see-able" by the player, we will use the normal "white" 
    655  * (except that, if the "view_yellow_lite" option is set, and the grid 
    656  * is *only* "see-able" because of the player's torch, then we will use 
    657  * "yellow"), else if the player is "blind", we will use "dark gray", 
    658  * else if the grid is not "illuminated", we will use "dark gray", else 
    659  * if the "view_bright_lite" option is set, we will use "slate" (gray), 
    660  * else we will use the normal "white". 
    661  * 
    662  * 
    663  * Some comments on the "terrain" layer (non-boring grids)... 
    664  * 
    665  * Note the use of the "mimic" field in the "terrain feature" processing, 
    666  * which allows any feature to "pretend" to be another feature.  This is 
    667  * used to "hide" secret doors, and to make all "doors" appear the same, 
    668  * and all "walls" appear the same, and "hidden" treasure stay hidden. 
    669  * Note that it is possible to use this field to make a feature "look" 
    670  * like a floor, but the "view_special_lite" flag only affects actual 
    671  * "boring" grids. 
    672  * 
    673  * Since "interesting" grids are always memorized as soon as they become 
    674  * "see-able" by the player ("CAVE_SEEN"), such a grid only needs to be 
    675  * displayed if it is memorized ("CAVE_MARK").  Most "interesting" grids 
    676  * are in fact non-memorized, non-see-able, wall grids, so the fact that 
    677  * we do not have to check the "CAVE_SEEN" flag adds some efficiency, at 
    678  * the cost of *forcing* the memorization of all "interesting" grids when 
    679  * they are first seen.  Since the "CAVE_SEEN" flag is now maintained by 
    680  * the "update_view()" function, this efficiency is not as significant as 
    681  * it was in previous versions, and could perhaps be removed. 
    682  * 
    683  * Note the "special lighting effects" which can be activated for "wall" 
    684  * grids using the "view_granite_lite" option, causing certain such grids 
    685  * to be displayed using special colors (if they are normally "white"). 
    686  * If the grid is "see-able" by the player, we will use the normal "white" 
    687  * else if the player is "blind", we will use "dark gray", else if the 
    688  * "view_bright_lite" option is set, we will use "slate" (gray), else we 
    689  * will use the normal "white". 
    690  * 
    691  * Note that "wall" grids are more complicated than "boring" grids, due to 
    692  * the fact that "CAVE_GLOW" for a "wall" grid means that the grid *might* 
    693  * be glowing, depending on where the player is standing in relation to the 
    694  * wall.  In particular, the wall of an illuminated room should look just 
    695  * like any other (dark) wall unless the player is actually inside the room. 
    696  * 
    697  * Thus, we do not support as many visual special effects for "wall" grids 
    698  * as we do for "boring" grids, since many of them would give the player 
    699  * information about the "CAVE_GLOW" flag of the wall grid, in particular, 
    700  * it would allow the player to notice the walls of illuminated rooms from 
    701  * a dark hallway that happened to run beside the room. 
    702  * 
    703  * 
    704  * Some comments on the "object" layer... 
    705  * 
    706  * Currently, we do nothing with multi-hued objects, because there are 
    707  * not any.  If there were, they would have to set "shimmer_objects" 
    708  * when they were created, and then new "shimmer" code in "dungeon.c" 
    709  * would have to be created handle the "shimmer" effect, and the code 
    710  * in "cave.c" would have to be updated to create the shimmer effect. 
    711  * This did not seem worth the effort.  XXX XXX 
    712  * 
    713  * 
    714  * Some comments on the "monster"/"player" layer... 
    715  * 
    716  * Note that monsters can have some "special" flags, including "ATTR_MULTI", 
    717  * which means their color changes, and "ATTR_CLEAR", which means they take 
    718  * the color of whatever is under them, and "CHAR_CLEAR", which means that 
    719  * they take the symbol of whatever is under them.  Technically, the flag 
    720  * "CHAR_MULTI" is supposed to indicate that a monster looks strange when 
    721  * examined, but this flag is currently ignored. 
    722  * 
    723  * Normally, players could be handled just like monsters, except that the 
    724  * concept of the "torch lite" of others player would add complications. 
    725  * For efficiency, however, we handle the (only) player first, since the 
    726  * "player" symbol always "pre-empts" any other facts about the grid. 
    727  * 
    728  * ToDo: The transformations for tile colors, or brightness for the 16x16 
     614 * TODO: 
     615 * The transformations for tile colors, or brightness for the 16x16 
    729616 * tiles should be handled differently.  One possibility would be to 
    730617 * extend feature_type with attr/char definitions for the different states. 
    731  */ 
    732 void map_info(int y, int x, byte *ap, char *cp, byte *tap, char *tcp) 
     618 * This will probably be done outside of the current text->graphics mappings 
     619 * though. 
     620 */ 
     621void grid_data_as_text(grid_data *g, byte *ap, char *cp, byte *tap, char *tcp) 
    733622{ 
    734623        byte a; 
    735624        char c; 
    736  
    737         byte feat; 
    738         byte info; 
    739  
    740         feature_type *f_ptr; 
    741         object_type *o_ptr; 
    742  
    743         s16b m_idx; 
    744  
    745         s16b image = p_ptr->timed[TMD_IMAGE]; 
    746  
    747         int floor_num = 0; 
    748  
    749         /* Monster/Player */ 
    750         m_idx = cave_m_idx[y][x]; 
    751  
    752         /* Feature */ 
    753         feat = cave_feat[y][x]; 
    754  
    755         /* Cave flags */ 
    756         info = cave_info[y][x]; 
    757  
    758         /* Hack -- rare random hallucination on non-outer walls */ 
    759         if (image && (!rand_int(256)) && (feat < FEAT_PERM_SOLID)) 
    760         { 
    761                 int i = image_random(); 
    762  
    763                 a = PICT_A(i); 
    764                 c = PICT_C(i); 
    765         } 
    766  
    767         /* Boring grids (floors, etc) */ 
    768         else if (feat <= FEAT_INVIS) 
    769         { 
    770                 /* Memorized (or seen) floor */ 
    771                 if ((info & (CAVE_MARK)) || 
    772                     (info & (CAVE_SEEN))) 
    773                 { 
    774                         /* Get the floor feature */ 
    775                         f_ptr = &f_info[FEAT_FLOOR]; 
    776  
    777                         /* Normal attr */ 
    778                         a = f_ptr->x_attr; 
    779  
    780                         /* Normal char */ 
    781                         c = f_ptr->x_char; 
    782  
    783                         /* Special lighting effects */ 
    784                         if (view_special_lite) special_lighting_floor(&a, &c, info); 
    785                 } 
    786  
    787                 /* Unknown */ 
    788                 else 
    789                 { 
    790                         /* Get the darkness feature */ 
    791                         f_ptr = &f_info[FEAT_NONE]; 
    792  
    793                         /* Normal attr */ 
    794                         a = f_ptr->x_attr; 
    795  
    796                         /* Normal char */ 
    797                         c = f_ptr->x_char; 
    798                 } 
    799         } 
    800  
    801         /* Interesting grids (non-floors) */ 
    802         else 
    803         { 
    804                 /* Memorized grids */ 
    805                 if (info & (CAVE_MARK)) 
    806                 { 
    807                         /* Apply "mimic" field */ 
    808                         feat = f_info[feat].mimic; 
    809  
    810                         /* Get the feature */ 
    811                         f_ptr = &f_info[feat]; 
    812  
    813                         /* Normal attr */ 
    814                         a = f_ptr->x_attr; 
    815  
    816                         /* Normal char */ 
    817                         c = f_ptr->x_char; 
    818  
    819                         /* Special lighting effects (walls only) */ 
    820                         if (view_granite_lite) special_lighting_wall(&a, &c, feat, info); 
    821                 } 
    822  
    823                 /* Unknown */ 
    824                 else 
    825                 { 
    826                         /* Get the darkness feature */ 
    827                         f_ptr = &f_info[FEAT_NONE]; 
    828  
    829                         /* Normal attr */ 
    830                         a = f_ptr->x_attr; 
    831  
    832                         /* Normal char */ 
    833                         c = f_ptr->x_char; 
    834                 } 
    835         } 
     625         
     626        feature_type *f_ptr = &f_info[g->f_idx]; 
     627         
     628        /* Normal attr and char */ 
     629        a = f_ptr->x_attr; 
     630        c = f_ptr->x_char; 
     631 
     632        /* Special lighting effects */ 
     633        if (g->f_idx <= FEAT_INVIS && view_special_lite) 
     634                special_lighting_floor(&a, &c, g->lighting, g->in_view); 
     635 
     636        /* Special lighting effects (walls only) */ 
     637        if (g->f_idx > FEAT_INVIS && view_granite_lite)  
     638                special_lighting_wall(&a, &c, g->lighting, g->in_view, g->f_idx); 
    836639 
    837640        /* Save the terrain info for the transparency effects */ 
     
    839642        (*tcp) = c; 
    840643 
    841         /* Objects */ 
    842         for (o_ptr = get_first_object(y, x); o_ptr; o_ptr = get_next_object(o_ptr)) 
    843         { 
    844                 /* Memorized objects */ 
    845                 if (o_ptr->marked && !squelch_hide_item(o_ptr)) 
    846                 { 
    847                         /* Hack -- object hallucination */ 
    848                         if (image) 
    849                         { 
    850                                 int i = image_object(); 
    851  
    852                                 a = PICT_A(i); 
    853                                 c = PICT_C(i); 
    854  
    855                                 break; 
    856                         } 
    857  
    858                         /* Normal attr */ 
    859                         a = object_attr(o_ptr); 
    860  
    861                         /* Normal char */ 
    862                         c = object_char(o_ptr); 
    863  
    864                         /* First marked object */ 
    865                         if (!show_piles) break; 
    866  
    867                         /* Special stack symbol */ 
    868                         if (++floor_num > 1) 
    869                         { 
    870                                 object_kind *k_ptr; 
    871  
    872                                 /* Get the "pile" feature */ 
    873                                 k_ptr = &k_info[0]; 
    874  
    875                                 /* Normal attr */ 
    876                                 a = k_ptr->x_attr; 
    877  
    878                                 /* Normal char */ 
    879                                 c = k_ptr->x_char; 
    880  
    881                                 break; 
    882                         } 
    883                 } 
    884         } 
    885  
    886  
    887         /* Monsters */ 
    888         if (m_idx > 0) 
    889         { 
    890                 monster_type *m_ptr = &mon_list[m_idx]; 
    891  
     644 
     645        /* If there's an object, deal with that. */ 
     646        if (g->first_k_idx) 
     647        { 
     648                object_kind *k_ptr = &k_info[g->first_k_idx]; 
     649 
     650                /* Normal attr and char */ 
     651                a = k_ptr->x_attr; 
     652                c = k_ptr->x_char; 
     653                 
     654                if (show_piles && g->multiple_objects) 
     655                { 
     656                        /* Get the "pile" feature instead */ 
     657                        k_ptr = &k_info[0]; 
     658                         
     659                        a = k_ptr->x_attr; 
     660                        c = k_ptr->x_char; 
     661                } 
     662        } 
     663 
     664        /* If there's a monster (that's not the player) */ 
     665        if (g->m_idx > 0) 
     666        { 
     667                monster_type *m_ptr = &mon_list[g->m_idx]; 
     668                 
    892669                /* Visible monster */ 
    893670                if (m_ptr->ml) 
     
    898675                        char dc; 
    899676 
    900                         /* Desired attr */ 
     677                        /* Desired attr & char*/ 
    901678                        da = r_ptr->x_attr; 
    902  
    903                         /* Desired char */ 
    904679                        dc = r_ptr->x_char; 
    905680 
    906                         /* Hack -- monster hallucination */ 
    907                         if (image) 
    908                         { 
    909                                 int i = image_monster(); 
    910  
    911                                 a = PICT_A(i); 
    912                                 c = PICT_C(i); 
    913                         } 
    914  
    915681                        /* Special attr/char codes */ 
    916                         else if ((da & 0x80) && (dc & 0x80)) 
     682                        if ((da & 0x80) && (dc & 0x80)) 
    917683                        { 
    918684                                /* Use attr */ 
     
    970736 
    971737        /* Handle "player" */ 
    972         else if (m_idx < 0) 
     738        else if (g->m_idx < 0) 
    973739        { 
    974740                monster_race *r_ptr = &r_info[0]; 
     
    999765        } 
    1000766 
    1001         /* Players */ 
    1002         else if (m_idx < 0) 
    1003         { 
    1004                 monster_race *r_ptr = &r_info[0]; 
    1005  
    1006                 /* Get the "player" attr */ 
    1007                 a = r_ptr->x_attr; 
    1008  
    1009                 /* Get the "player" char */ 
    1010                 c = r_ptr->x_char; 
    1011         } 
    1012  
    1013767        /* Result */ 
    1014768        (*ap) = a; 
    1015         (*cp) = c; 
    1016 
     769        (*cp) = c;       
     770
     771 
     772 
     773/* 
     774 * This function takes a grid location (x, y) and extracts information the 
     775 * player is allowed to know about it, filling in the grid_data structure 
     776 * passed in 'g'. 
     777 * 
     778 * The information filled in is as follows: 
     779 *  - g->f_idx is filled in with the terrain's feature type, or FEAT_NONE 
     780 *    if the player doesn't know anything about the grid.  The function 
     781 *    makes use of the "mimic" field in terrain in order to allow one 
     782 *    feature to look like another (hiding secret doors, invisible traps, 
     783 *    etc).  This will return the terrain type the player "Knows" about, 
     784 *    not necessarily the real terrain. 
     785 *  - g->m_idx is set to the monster index, or 0 if there is none (or the 
     786 *    player doesn't know it). 
     787 *  - g->first_k_idx is set to the index of the first object in a grid 
     788 *    that the player knows (and cares, as per hide_squelchable) about, 
     789 *    or zero for no object in the grid. 
     790 *  - g->muliple_objects is TRUE if there is more than one object in the 
     791 *    grid that the player knows and cares about (to facilitate any special 
     792 *    floor stack symbol that might be used). 
     793 *  - g->in_view is TRUE if the player can currently see the grid - this can 
     794 *    be used to indicate field-of-view, such as through the view_bright_lite 
     795 *    option. 
     796 *  - g->lighting is set to indicate the lighting level for the grid: 
     797 *    LIGHT_DARK for unlit grids, LIGHT_TORCH for those lit by the player's 
     798 *    light source, and LIGHT_GLOW for inherently light grids (lit rooms, etc). 
     799 *        
     800 * NOTES: 
     801 * This is called pretty frequently, whenever a grid on the map display 
     802 * needs updating, so don't overcomplicate it. 
     803 * 
     804 * Terrain is remembered separately from objects and monsters, so can be 
     805 * shown even when the player can't "see" it.  This leads to the "interesting" 
     806 * effects when doors out of view change from closed to open and so on. 
     807 *  
     808 * Note that "boring" grids (floors, invisible traps, and any illegal grids) 
     809 * are different from "interesting" grids (all other terrain features), 
     810 * and the two are handled differently, with LIGHT_TORCH only applied to  
     811 * the boring grids.  In fact, wall grids are handled strangely wrt lighting 
     812 * altogether because we have to be careful not to have "paper walls" where a 
     813 * wall shows as lit from the other side (i.e. a dark corridor next to a lit 
     814 * room). 
     815 * 
     816 * TODO: 
     817 * Hallucination is currently disabled (it was a display-level hack before, 
     818 * and we need it to be a knowledge-level hack).  The idea is that objects 
     819 * may turn into different objects, monsters into different monsters, and 
     820 * terrain may be objects, monsters, or stay the same. 
     821 */ 
     822#undef HALLUCINATION_SUPPORT /* needs to be generalised. */ 
     823void map_info(unsigned y, unsigned x, grid_data *g) 
     824
     825        object_type *o_ptr; 
     826        byte info = cave_info[y][x]; 
     827 
     828#if HALLUCINATION_SUPPORT 
     829        s16b image = p_ptr->timed[TMD_IMAGE]; 
     830#endif 
     831 
     832        /* Default "clear" values, others will be set later where appropriate. */ 
     833        g->first_k_idx = 0; 
     834        g->multiple_objects = FALSE; 
     835        g->lighting = LIGHT_GLOW; 
     836 
     837        /* Set various indexes */ 
     838        g->m_idx = cave_m_idx[y][x]; 
     839        g->f_idx = cave_feat[y][x]; 
     840 
     841#if HALLUCINATION_SUPPORT 
     842        /* Hack -- rare random hallucination on non-outer walls */ 
     843        if (image && (!rand_int(256)) && (g->f_idx < FEAT_PERM_SOLID)) 
     844        { 
     845                int i = image_random(); 
     846 
     847                a = PICT_A(i); 
     848                c = PICT_C(i); 
     849        } 
     850#endif 
     851 
     852        g->in_view = (info & CAVE_SEEN) ? TRUE : FALSE; 
     853 
     854        /* If the grid is memorised or can currently be seen */ 
     855        if ((info & CAVE_MARK) || (info & CAVE_SEEN)) 
     856        { 
     857                /* Apply "mimic" field */ 
     858                g->f_idx = f_info[g->f_idx].mimic; 
     859                         
     860                /* Boring grids (floors, etc) */ 
     861                if (g->f_idx <= FEAT_INVIS) 
     862                { 
     863                        /* Get the floor feature */ 
     864                        g->f_idx = FEAT_FLOOR; 
     865 
     866                        /* Handle currently visible grids */ 
     867                        if (info & CAVE_SEEN) 
     868                        { 
     869                                /* Only lit by "torch" lite */ 
     870                                if (info & CAVE_GLOW) 
     871                                        g->lighting = LIGHT_GLOW; 
     872                                else 
     873                                        g->lighting = LIGHT_TORCH; 
     874                        } 
     875 
     876                        /* Handle "dark" grids and "blindness" */ 
     877                        else if (p_ptr->timed[TMD_BLIND] || !(info & CAVE_GLOW)) 
     878                                g->lighting = LIGHT_DARK; 
     879                } 
     880                /* Interesting grids (non-floors) */ 
     881                else 
     882                { 
     883                        /* Skip currently visible grids for lighting */ 
     884                        if (!(info & (CAVE_SEEN))) 
     885                        { 
     886                                /* Handle "blind" */ 
     887                                if (p_ptr->timed[TMD_BLIND]) 
     888                                        g->lighting = LIGHT_DARK; 
     889                                else 
     890                                        g->lighting = LIGHT_GLOW; 
     891                        } 
     892                } 
     893        } 
     894        /* Unknown */ 
     895        else 
     896        { 
     897                g->f_idx = FEAT_NONE; 
     898        } 
     899        
     900 
     901 
     902        /* Objects */ 
     903        for (o_ptr = get_first_object(y, x); o_ptr; o_ptr = get_next_object(o_ptr)) 
     904        { 
     905                /* Memorized objects */ 
     906                if (o_ptr->marked && !squelch_hide_item(o_ptr)) 
     907                { 
     908#ifdef HALLUCINATION_SUPPORT 
     909                        /* Hack -- object hallucination */ 
     910                        if (image) 
     911                        { 
     912                                int i = image_object(); 
     913 
     914                                a = PICT_A(i); 
     915                                c = PICT_C(i); 
     916 
     917                                break; 
     918                        } 
     919#endif 
     920                        /* First item found */ 
     921                        if (g->first_k_idx == 0) 
     922                        { 
     923                                g->first_k_idx = o_ptr->k_idx; 
     924                        } 
     925                        else 
     926                        { 
     927                                g->multiple_objects = TRUE; 
     928 
     929                                /* And we know all we need to know. */ 
     930                                break; 
     931                        } 
     932                } 
     933        } 
     934 
     935 
     936#if HALLUCINATION_SUPPORT 
     937        /* Monsters */ 
     938        if (g->m_idx > 0) 
     939        { 
     940                /* Hack -- monster hallucination */ 
     941                if (image) 
     942                { 
     943                        int i = image_monster(); 
     944                         
     945                        a = PICT_A(i); 
     946                        c = PICT_C(i); 
     947                } 
     948        } 
     949#endif 
     950 
     951        /* Handle the player */ 
     952        if (g->m_idx < 0) 
     953        { 
     954                g->m_idx = -1; 
     955        } 
     956
     957 
    1017958 
    1018959 
     
    12921233static void lite_spot_map(int y, int x) 
    12931234{ 
     1235        grid_data g; 
    12941236        byte a, ta; 
    12951237        char c, tc; 
     
    13241266                if ((kx < 0) || (kx >= t->wid)) continue; 
    13251267 
    1326                 /* Hack -- redraw the grid */ 
    1327                 map_info(y, x, &a, &c, &ta, &tc); 
    1328  
    1329                 /* Hack -- Queue it */ 
     1268                /* Hack -- redraw the grid spot */ 
     1269                map_info(y, x, &g); 
     1270                grid_data_as_text(&g, &a, &c, &ta, &tc); 
    13301271                Term_queue_char(t, kx, ky, a, c, ta, tc); 
    13311272 
     
    13631304        byte ta; 
    13641305        char tc; 
     1306        grid_data g; 
    13651307 
    13661308        int ky, kx; 
     
    13911333 
    13921334        /* Hack -- redraw the grid */ 
    1393         map_info(y, x, &a, &c, &ta, &tc); 
    1394  
    1395         /* Hack -- Queue it */ 
     1335        map_info(y, x, &g); 
     1336        grid_data_as_text(&g, &a, &c, &ta, &tc); 
    13961337        Term_queue_char(Term, vx, vy, a, c, ta, tc); 
    13971338 
     
    14151356        byte ta; 
    14161357        char tc; 
     1358        grid_data g; 
    14171359 
    14181360        int y, x; 
     
    14501392 
    14511393                                /* Determine what is there */ 
    1452                                 map_info(y, x, &a, &c, &ta, &tc); 
    1453  
    1454                                 /* Hack -- Queue it */ 
     1394                                map_info(y, x, &g); 
     1395                                grid_data_as_text(&g, &a, &c, &ta, &tc); 
    14551396                                Term_queue_char(t, vx, vy, a, c, ta, tc); 
    14561397 
     
    14881429        byte ta; 
    14891430        char tc; 
     1431        grid_data g; 
    14901432 
    14911433        int y, x; 
     
    15091451 
    15101452                        /* Determine what is there */ 
    1511                         map_info(y, x, &a, &c, &ta, &tc); 
     1453                        map_info(y, x, &g); 
     1454                        grid_data_as_text(&g, &a, &c, &ta, &tc); 
    15121455 
    15131456                        /* Hack -- Queue it */ 
     
    16351578 
    16361579        int x, y; 
     1580        grid_data g; 
    16371581 
    16381582        byte ta; 
     
    17041648 
    17051649                        /* Get the attr/char at that map location */ 
    1706                         map_info(y, x, &ta, &tc, &ta, &tc); 
     1650                        map_info(y, x, &g); 
     1651                        grid_data_as_text(&g, &ta, &tc, &ta, &tc); 
    17071652 
    17081653                        /* Get the priority of that attr/char */ 
  • trunk/src/externs.h

    r469 r472  
    270270extern bool cave_valid_bold(int y, int x); 
    271271extern bool feat_supports_lighting(int feat); 
    272 extern void map_info(int y, int x, byte *ap, char *cp, byte *tap, char *tcp); 
     272extern void map_info(unsigned x, unsigned y, grid_data *g); 
    273273extern void move_cursor_relative(int y, int x); 
    274274extern void print_rel(char c, byte a, int y, int x); 
  • trunk/src/types.h

    r455 r472  
    11181118 
    11191119 
     1120enum grid_light_level 
     1121{ 
     1122        LIGHT_TORCH, 
     1123        LIGHT_GLOW, 
     1124        LIGHT_DARK 
     1125}; 
     1126 
     1127typedef struct 
     1128{ 
     1129        s32b m_idx;             /* Monster index - 0 for none, -1 for the player */ 
     1130        u32b f_idx;             /* Feature index */ 
     1131        u32b first_k_idx;       /* The "Kind" of the first item on the grid */ 
     1132        bool multiple_objects;  /* Is there more than one item there? */ 
     1133 
     1134        enum grid_light_level lighting; /* Light level */ 
     1135        bool in_view; /* TRUE when the player can currently see the grid. */ 
     1136} grid_data; 
     1137