Changeset 652

Show
Ignore:
Timestamp:
01/29/08 04:25:13 (7 months ago)
Author:
takkaria
Message:

Check in an initial version of the new, saner object_desc() code. This introduces a new file, obj-desc.c, for object description-related functions. (#430)

Files:

Legend:

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

    r595 r652  
    1616attack.o: attack.c angband.h h-basic.h z-file.h z-form.h z-util.h \ 
    1717  z-virt.h z-rand.h z-term.h ui-event.h z-quark.h z-msg.h config.h \ 
    18   defines.h option.h types.h ui.h z-type.h externs.h 
     18  defines.h option.h types.h ui.h z-type.h externs.h object.h 
    1919birth.o: birth.c angband.h h-basic.h z-file.h z-form.h z-util.h z-virt.h \ 
    2020  z-rand.h z-term.h ui-event.h z-quark.h z-msg.h config.h defines.h \ 
    21   option.h types.h ui.h z-type.h externs.h cmds.h ui-menu.h 
     21  option.h types.h ui.h z-type.h externs.h object.h cmds.h ui-menu.h 
    2222cave.o: cave.c angband.h h-basic.h z-file.h z-form.h z-util.h z-virt.h \ 
    2323  z-rand.h z-term.h ui-event.h z-quark.h z-msg.h config.h defines.h \ 
    24   option.h types.h ui.h z-type.h externs.h game-event.h 
     24  option.h types.h ui.h z-type.h externs.h object.h game-event.h 
    2525compress.o: compress.c compress.h h-basic.h 
    2626cmd0.o: cmd0.c angband.h h-basic.h z-file.h z-form.h z-util.h z-virt.h \ 
    2727  z-rand.h z-term.h ui-event.h z-quark.h z-msg.h config.h defines.h \ 
    28   option.h types.h ui.h z-type.h externs.h cmds.h ui-menu.h 
     28  option.h types.h ui.h z-type.h externs.h object.h wizard.h cmds.h \ 
     29  ui-menu.h 
    2930cmd1.o: cmd1.c angband.h h-basic.h z-file.h z-form.h z-util.h z-virt.h \ 
    3031  z-rand.h z-term.h ui-event.h z-quark.h z-msg.h config.h defines.h \ 
    31   option.h types.h ui.h z-type.h externs.h cmds.h 
     32  option.h types.h ui.h z-type.h externs.h object.h cmds.h 
    3233cmd2.o: cmd2.c angband.h h-basic.h z-file.h z-form.h z-util.h z-virt.h \ 
    3334  z-rand.h z-term.h ui-event.h z-quark.h z-msg.h config.h defines.h \ 
    34   option.h types.h ui.h z-type.h externs.h 
     35  option.h types.h ui.h z-type.h externs.h object.h 
    3536cmd3.o: cmd3.c angband.h h-basic.h z-file.h z-form.h z-util.h z-virt.h \ 
    3637  z-rand.h z-term.h ui-event.h z-quark.h z-msg.h config.h defines.h \ 
    37   option.h types.h ui.h z-type.h externs.h 
     38  option.h types.h ui.h z-type.h externs.h object.h 
    3839cmd4.o: cmd4.c angband.h h-basic.h z-file.h z-form.h z-util.h z-virt.h \ 
    3940  z-rand.h z-term.h ui-event.h z-quark.h z-msg.h config.h defines.h \ 
    40   option.h types.h ui.h z-type.h externs.h ui-menu.h 
     41  option.h types.h ui.h z-type.h externs.h object.h ui-menu.h 
    4142cmd5.o: cmd5.c angband.h h-basic.h z-file.h z-form.h z-util.h z-virt.h \ 
    4243  z-rand.h z-term.h ui-event.h z-quark.h z-msg.h config.h defines.h \ 
    43   option.h types.h ui.h z-type.h externs.h 
     44  option.h types.h ui.h z-type.h externs.h object.h 
    4445cmd6.o: cmd6.c angband.h h-basic.h z-file.h z-form.h z-util.h z-virt.h \ 
    4546  z-rand.h z-term.h ui-event.h z-quark.h z-msg.h config.h defines.h \ 
    46   option.h types.h ui.h z-type.h externs.h cmds.h effects.h 
     47  option.h types.h ui.h z-type.h externs.h object.h cmds.h effects.h 
    4748cmd-obj.o: cmd-obj.c angband.h h-basic.h z-file.h z-form.h z-util.h \ 
    4849  z-virt.h z-rand.h z-term.h ui-event.h z-quark.h z-msg.h config.h \ 
    49   defines.h option.h types.h ui.h z-type.h externs.h cmds.h 
     50  defines.h option.h types.h ui.h z-type.h externs.h object.h cmds.h 
     51death.o: death.c angband.h h-basic.h z-file.h z-form.h z-util.h z-virt.h \ 
     52  z-rand.h z-term.h ui-event.h z-quark.h z-msg.h config.h defines.h \ 
     53  option.h types.h ui.h z-type.h externs.h object.h ui-menu.h 
    5054debug.o: debug.c angband.h h-basic.h z-file.h z-form.h z-util.h z-virt.h \ 
    5155  z-rand.h z-term.h ui-event.h z-quark.h z-msg.h config.h defines.h \ 
    52   option.h types.h ui.h z-type.h externs.h debug.h 
     56  option.h types.h ui.h z-type.h externs.h object.h debug.h 
    5357dungeon.o: dungeon.c angband.h h-basic.h z-file.h z-form.h z-util.h \ 
    5458  z-virt.h z-rand.h z-term.h ui-event.h z-quark.h z-msg.h config.h \ 
    55   defines.h option.h types.h ui.h z-type.h externs.h cmds.h 
     59  defines.h option.h types.h ui.h z-type.h externs.h object.h cmds.h 
    5660effects.o: effects.c angband.h h-basic.h z-file.h z-form.h z-util.h \ 
    5761  z-virt.h z-rand.h z-term.h ui-event.h z-quark.h z-msg.h config.h \ 
    58   defines.h option.h types.h ui.h z-type.h externs.h effects.h 
     62  defines.h option.h types.h ui.h z-type.h externs.h object.h effects.h 
    5963files.o: files.c angband.h h-basic.h z-file.h z-form.h z-util.h z-virt.h \ 
    6064  z-rand.h z-term.h ui-event.h z-quark.h z-msg.h config.h defines.h \ 
    61   option.h types.h ui.h z-type.h externs.h cmds.h 
     65  option.h types.h ui.h z-type.h externs.h object.h ui-menu.h cmds.h 
    6266game-cmd.o: game-cmd.c angband.h h-basic.h z-file.h z-form.h z-util.h \ 
    6367  z-virt.h z-rand.h z-term.h ui-event.h z-quark.h z-msg.h config.h \ 
    64   defines.h option.h types.h ui.h z-type.h externs.h game-cmd.h 
     68  defines.h option.h types.h ui.h z-type.h externs.h object.h game-cmd.h 
    6569game-event.o: game-event.c z-virt.h h-basic.h game-event.h 
    6670generate.o: generate.c angband.h h-basic.h z-file.h z-form.h z-util.h \ 
    6771  z-virt.h z-rand.h z-term.h ui-event.h z-quark.h z-msg.h config.h \ 
    68   defines.h option.h types.h ui.h z-type.h externs.h 
     72  defines.h option.h types.h ui.h z-type.h externs.h object.h 
     73history.o: history.c angband.h h-basic.h z-file.h z-form.h z-util.h \ 
     74  z-virt.h z-rand.h z-term.h ui-event.h z-quark.h z-msg.h config.h \ 
     75  defines.h option.h types.h ui.h z-type.h externs.h object.h 
    6976init1.o: init1.c angband.h h-basic.h z-file.h z-form.h z-util.h z-virt.h \ 
    7077  z-rand.h z-term.h ui-event.h z-quark.h z-msg.h config.h defines.h \ 
    71   option.h types.h ui.h z-type.h externs.h effects.h init.h 
     78  option.h types.h ui.h z-type.h externs.h object.h effects.h init.h 
    7279init2.o: init2.c angband.h h-basic.h z-file.h z-form.h z-util.h z-virt.h \ 
    7380  z-rand.h z-term.h ui-event.h z-quark.h z-msg.h config.h defines.h \ 
    74   option.h types.h ui.h z-type.h externs.h init.h cmds.h game-event.h \ 
    75   game-cmd.h 
     81  option.h types.h ui.h z-type.h externs.h object.h init.h cmds.h \ 
     82  game-event.h game-cmd.h 
    7683load.o: load.c angband.h h-basic.h z-file.h z-form.h z-util.h z-virt.h \ 
    7784  z-rand.h z-term.h ui-event.h z-quark.h z-msg.h config.h defines.h \ 
    78   option.h types.h ui.h z-type.h externs.h 
     85  option.h types.h ui.h z-type.h externs.h object.h 
    7986loadsave.o: loadsave.c angband.h h-basic.h z-file.h z-form.h z-util.h \ 
    8087  z-virt.h z-rand.h z-term.h ui-event.h z-quark.h z-msg.h config.h \ 
    81   defines.h option.h types.h ui.h z-type.h externs.h z-blockfile.h \ 
    82   z-smap.h 
     88  defines.h option.h types.h ui.h z-type.h externs.h object.h \ 
     89  z-blockfile.h z-smap.h 
    8390melee1.o: melee1.c angband.h h-basic.h z-file.h z-form.h z-util.h \ 
    8491  z-virt.h z-rand.h z-term.h ui-event.h z-quark.h z-msg.h config.h \ 
    85   defines.h option.h types.h ui.h z-type.h externs.h 
     92  defines.h option.h types.h ui.h z-type.h externs.h object.h 
    8693melee2.o: melee2.c angband.h h-basic.h z-file.h z-form.h z-util.h \ 
    8794  z-virt.h z-rand.h z-term.h ui-event.h z-quark.h z-msg.h config.h \ 
    88   defines.h option.h types.h ui.h z-type.h externs.h 
     95  defines.h option.h types.h ui.h z-type.h externs.h object.h 
    8996monster1.o: monster1.c angband.h h-basic.h z-file.h z-form.h z-util.h \ 
    9097  z-virt.h z-rand.h z-term.h ui-event.h z-quark.h z-msg.h config.h \ 
    91   defines.h option.h types.h ui.h z-type.h externs.h 
     98  defines.h option.h types.h ui.h z-type.h externs.h object.h 
    9299monster2.o: monster2.c angband.h h-basic.h z-file.h z-form.h z-util.h \ 
    93100  z-virt.h z-rand.h z-term.h ui-event.h z-quark.h z-msg.h config.h \ 
    94   defines.h option.h types.h ui.h z-type.h externs.h 
     101  defines.h option.h types.h ui.h z-type.h externs.h object.h 
    95102object1.o: object1.c angband.h h-basic.h z-file.h z-form.h z-util.h \ 
    96103  z-virt.h z-rand.h z-term.h ui-event.h z-quark.h z-msg.h config.h \ 
    97   defines.h option.h types.h ui.h z-type.h externs.h randname.h 
     104  defines.h option.h types.h ui.h z-type.h externs.h object.h randname.h 
    98105object2.o: object2.c angband.h h-basic.h z-file.h z-form.h z-util.h \ 
    99106  z-virt.h z-rand.h z-term.h ui-event.h z-quark.h z-msg.h config.h \ 
    100   defines.h option.h types.h ui.h z-type.h externs.h 
     107  defines.h option.h types.h ui.h z-type.h externs.h object.h 
     108obj-desc.o: obj-desc.c angband.h h-basic.h z-file.h z-form.h z-util.h \ 
     109  z-virt.h z-rand.h z-term.h ui-event.h z-quark.h z-msg.h config.h \ 
     110  defines.h option.h types.h ui.h z-type.h externs.h object.h 
    101111obj-info.o: obj-info.c angband.h h-basic.h z-file.h z-form.h z-util.h \ 
    102112  z-virt.h z-rand.h z-term.h ui-event.h z-quark.h z-msg.h config.h \ 
    103   defines.h option.h types.h ui.h z-type.h externs.h effects.h cmds.h 
     113  defines.h option.h types.h ui.h z-type.h externs.h object.h effects.h \ 
     114  cmds.h 
     115obj-make.o: obj-make.c angband.h h-basic.h z-file.h z-form.h z-util.h \ 
     116  z-virt.h z-rand.h z-term.h ui-event.h z-quark.h z-msg.h config.h \ 
     117  defines.h option.h types.h ui.h z-type.h externs.h object.h 
    104118option.o: option.c angband.h h-basic.h z-file.h z-form.h z-util.h \ 
    105119  z-virt.h z-rand.h z-term.h ui-event.h z-quark.h z-msg.h config.h \ 
    106   defines.h option.h types.h ui.h z-type.h externs.h 
     120  defines.h option.h types.h ui.h z-type.h externs.h object.h 
    107121randart.o: randart.c angband.h h-basic.h z-file.h z-form.h z-util.h \ 
    108122  z-virt.h z-rand.h z-term.h ui-event.h z-quark.h z-msg.h config.h \ 
    109   defines.h option.h types.h ui.h z-type.h externs.h init.h randname.h 
     123  defines.h option.h types.h ui.h z-type.h externs.h object.h init.h \ 
     124  randname.h 
    110125randname.o: randname.c angband.h h-basic.h z-file.h z-form.h z-util.h \ 
    111126  z-virt.h z-rand.h z-term.h ui-event.h z-quark.h z-msg.h config.h \ 
    112   defines.h option.h types.h ui.h z-type.h externs.h randname.h 
     127  defines.h option.h types.h ui.h z-type.h externs.h object.h randname.h 
    113128pathfind.o: pathfind.c angband.h h-basic.h z-file.h z-form.h z-util.h \ 
    114129  z-virt.h z-rand.h z-term.h ui-event.h z-quark.h z-msg.h config.h \ 
    115   defines.h option.h types.h ui.h z-type.h externs.h 
     130  defines.h option.h types.h ui.h z-type.h externs.h object.h 
    116131score.o: score.c angband.h h-basic.h z-file.h z-form.h z-util.h z-virt.h \ 
    117132  z-rand.h z-term.h ui-event.h z-quark.h z-msg.h config.h defines.h \ 
    118   option.h types.h ui.h z-type.h externs.h 
     133  option.h types.h ui.h z-type.h externs.h object.h 
    119134signals.o: signals.c angband.h h-basic.h z-file.h z-form.h z-util.h \ 
    120135  z-virt.h z-rand.h z-term.h ui-event.h z-quark.h z-msg.h config.h \ 
    121   defines.h option.h types.h ui.h z-type.h externs.h 
     136  defines.h option.h types.h ui.h z-type.h externs.h object.h 
    122137save.o: save.c angband.h h-basic.h z-file.h z-form.h z-util.h z-virt.h \ 
    123138  z-rand.h z-term.h ui-event.h z-quark.h z-msg.h config.h defines.h \ 
    124   option.h types.h ui.h z-type.h externs.h 
     139  option.h types.h ui.h z-type.h externs.h object.h 
    125140spells1.o: spells1.c angband.h h-basic.h z-file.h z-form.h z-util.h \ 
    126141  z-virt.h z-rand.h z-term.h ui-event.h z-quark.h z-msg.h config.h \ 
    127   defines.h option.h types.h ui.h z-type.h externs.h 
     142  defines.h option.h types.h ui.h z-type.h externs.h object.h 
    128143spells2.o: spells2.c angband.h h-basic.h z-file.h z-form.h z-util.h \ 
    129144  z-virt.h z-rand.h z-term.h ui-event.h z-quark.h z-msg.h config.h \ 
    130   defines.h option.h types.h ui.h z-type.h externs.h 
     145  defines.h option.h types.h ui.h z-type.h externs.h object.h 
    131146squelch.o: squelch.c angband.h h-basic.h z-file.h z-form.h z-util.h \ 
    132147  z-virt.h z-rand.h z-term.h ui-event.h z-quark.h z-msg.h config.h \ 
    133   defines.h option.h types.h ui.h z-type.h externs.h cmds.h ui-menu.h 
     148  defines.h option.h types.h ui.h z-type.h externs.h object.h cmds.h \ 
     149  ui-menu.h 
    134150store.o: store.c angband.h h-basic.h z-file.h z-form.h z-util.h z-virt.h \ 
    135151  z-rand.h z-term.h ui-event.h z-quark.h z-msg.h config.h defines.h \ 
    136   option.h types.h ui.h z-type.h externs.h cmds.h ui-menu.h 
     152  option.h types.h ui.h z-type.h externs.h object.h cmds.h ui-menu.h 
    137153tables.o: tables.c angband.h h-basic.h z-file.h z-form.h z-util.h \ 
    138154  z-virt.h z-rand.h z-term.h ui-event.h z-quark.h z-msg.h config.h \ 
    139   defines.h option.h types.h ui.h z-type.h externs.h 
     155  defines.h option.h types.h ui.h z-type.h externs.h object.h 
    140156trap.o: trap.c angband.h h-basic.h z-file.h z-form.h z-util.h z-virt.h \ 
    141157  z-rand.h z-term.h ui-event.h z-quark.h z-msg.h config.h defines.h \ 
    142   option.h types.h ui.h z-type.h externs.h 
     158  option.h types.h ui.h z-type.h externs.h object.h 
    143159ui.o: ui.c angband.h h-basic.h z-file.h z-form.h z-util.h z-virt.h \ 
    144160  z-rand.h z-term.h ui-event.h z-quark.h z-msg.h config.h defines.h \ 
    145   option.h types.h ui.h z-type.h externs.h 
     161  option.h types.h ui.h z-type.h externs.h object.h 
    146162ui-event.o: ui-event.c angband.h h-basic.h z-file.h z-form.h z-util.h \ 
    147163  z-virt.h z-rand.h z-term.h ui-event.h z-quark.h z-msg.h config.h \ 
    148   defines.h option.h types.h ui.h z-type.h externs.h 
     164  defines.h option.h types.h ui.h z-type.h externs.h object.h 
    149165ui-menu.o: ui-menu.c angband.h h-basic.h z-file.h z-form.h z-util.h \ 
    150166  z-virt.h z-rand.h z-term.h ui-event.h z-quark.h z-msg.h config.h \ 
    151   defines.h option.h types.h ui.h z-type.h externs.h ui-menu.h 
     167  defines.h option.h types.h ui.h z-type.h externs.h object.h ui-menu.h 
    152168util.o: util.c angband.h h-basic.h z-file.h z-form.h z-util.h z-virt.h \ 
    153169  z-rand.h z-term.h ui-event.h z-quark.h z-msg.h config.h defines.h \ 
    154   option.h types.h ui.h z-type.h externs.h randname.h 
     170  option.h types.h ui.h z-type.h externs.h object.h randname.h 
    155171variable.o: variable.c angband.h h-basic.h z-file.h z-form.h z-util.h \ 
    156172  z-virt.h z-rand.h z-term.h ui-event.h z-quark.h z-msg.h config.h \ 
    157   defines.h option.h types.h ui.h z-type.h externs.h 
     173  defines.h option.h types.h ui.h z-type.h externs.h object.h 
    158174wiz-spoil.o: wiz-spoil.c angband.h h-basic.h z-file.h z-form.h z-util.h \ 
    159175  z-virt.h z-rand.h z-term.h ui-event.h z-quark.h z-msg.h config.h \ 
    160   defines.h option.h types.h ui.h z-type.h externs.h cmds.h 
     176  defines.h option.h types.h ui.h z-type.h externs.h object.h cmds.h 
    161177wiz-stats.o: wiz-stats.c angband.h h-basic.h z-file.h z-form.h z-util.h \ 
    162178  z-virt.h z-rand.h z-term.h ui-event.h z-quark.h z-msg.h config.h \ 
    163   defines.h option.h types.h ui.h z-type.h externs.h wizard.h 
     179  defines.h option.h types.h ui.h z-type.h externs.h object.h wizard.h 
    164180wizard.o: wizard.c angband.h h-basic.h z-file.h z-form.h z-util.h \ 
    165181  z-virt.h z-rand.h z-term.h ui-event.h z-quark.h z-msg.h config.h \ 
    166   defines.h option.h types.h ui.h z-type.h externs.h wizard.h cmds.h 
     182  defines.h option.h types.h ui.h z-type.h externs.h object.h wizard.h \ 
     183  cmds.h 
    167184x-spell.o: x-spell.c angband.h h-basic.h z-file.h z-form.h z-util.h \ 
    168185  z-virt.h z-rand.h z-term.h ui-event.h z-quark.h z-msg.h config.h \ 
    169   defines.h option.h types.h ui.h z-type.h externs.h 
     186  defines.h option.h types.h ui.h z-type.h externs.h object.h 
    170187xtra1.o: xtra1.c angband.h h-basic.h z-file.h z-form.h z-util.h z-virt.h \ 
    171188  z-rand.h z-term.h ui-event.h z-quark.h z-msg.h config.h defines.h \ 
    172   option.h types.h ui.h z-type.h externs.h game-event.h 
     189  option.h types.h ui.h z-type.h externs.h object.h game-event.h 
    173190xtra2.o: xtra2.c angband.h h-basic.h z-file.h z-form.h z-util.h z-virt.h \ 
    174191  z-rand.h z-term.h ui-event.h z-quark.h z-msg.h config.h defines.h \ 
    175   option.h types.h ui.h z-type.h externs.h cmds.h 
     192  option.h types.h ui.h z-type.h externs.h object.h cmds.h 
    176193xtra3.o: xtra3.c angband.h h-basic.h z-file.h z-form.h z-util.h z-virt.h \ 
    177194  z-rand.h z-term.h ui-event.h z-quark.h z-msg.h config.h defines.h \ 
    178   option.h types.h ui.h z-type.h externs.h game-event.h 
     195  option.h types.h ui.h z-type.h externs.h object.h game-event.h 
    179196z-file.o: z-file.c z-file.h h-basic.h z-virt.h z-util.h z-form.h 
    180197z-form.o: z-form.c z-form.h h-basic.h z-type.h z-util.h z-virt.h 
  • trunk/src/Makefile.src

    r636 r652  
    8080        object1.o \ 
    8181        object2.o \ 
     82        obj-desc.o \ 
    8283        obj-info.o \ 
    8384        obj-make.o \ 
  • trunk/src/object.h

    r610 r652  
    11#ifndef INCLUDED_OBJECT_H 
    22#define INCLUDED_OBJECT_H 
     3 
     4 
     5/*** Variables ***/ 
     6 
     7/* object1.c */ 
     8 
     9#define MAX_TITLES     50       /* Used with scrolls (min 48) */ 
     10 
     11/* The titles of scrolls, by sval. */ 
     12extern char scroll_adj[MAX_TITLES][16]; 
     13 
     14 
     15/*** Functions ***/ 
    316 
    417/* object1.c */ 
    518void flavor_init(void); 
    619void reset_visuals(bool unused); 
    7 void object_kind_name(char *buf, size_t max, int k_idx, bool easy_know); 
    820void object_flags(const object_type *o_ptr, u32b *f1, u32b *f2, u32b *f3); 
    921void object_flags_known(const object_type *o_ptr, u32b *f1, u32b *f2, u32b *f3); 
    10 void object_desc(char *buf, size_t max, const object_type *o_ptr, int pref, int mode); 
    11 void object_desc_spoil(char *buf, size_t max, const object_type *o_ptr, int pref, int mode); 
    1222char index_to_label(int i); 
    1323s16b label_to_inven(int c); 
    1424s16b label_to_equip(int c); 
    1525s16b wield_slot(const object_type *o_ptr); 
    16 cptr mention_use(int i); 
    17 cptr describe_use(int i); 
     26const char *mention_use(int i); 
     27const char *describe_use(int i); 
    1828bool item_tester_okay(const object_type *o_ptr); 
    1929int scan_floor(int *items, int max_size, int y, int x, int mode); 
     
    2333void show_equip(void); 
    2434void show_floor(const int *floor_list, int floor_num, bool gold); 
    25 bool verify_item(cptr prompt, int item); 
    26 bool get_item(int *cp, cptr pmt, cptr str, int mode); 
     35bool verify_item(const char *prompt, int item); 
     36bool get_item(int *cp, const char *pmt, const char *str, int mode); 
    2737 
    2838/* object2.c */ 
     
    3343void wipe_o_list(void); 
    3444s16b o_pop(void); 
    35 object_type* get_first_object(int y, int x); 
     45object_type *get_first_object(int y, int x); 
    3646object_type *get_next_object(const object_type *o_ptr); 
    3747void object_known(object_type *o_ptr); 
     
    7282void reduce_charges(object_type *o_ptr, int amt); 
    7383 
     84 
     85/*** obj-name.c ***/ 
     86 
     87/** 
     88 * Modes for object_desc(). 
     89 */ 
     90enum 
     91{ 
     92        ODESC_BASENAME = 0, 
     93        ODESC_ALL = 3, 
     94        ODESC_INSTORE = 4 
     95}; 
     96 
     97/** 
     98 * Describes item "o_ptr" into buffer "buf" of size "max". 
     99 * 
     100 * If "prefix" is TRUE, then the name will be prefixed with a pseudo-numeric 
     101 * indicator of the number of items in the pile. 
     102 * 
     103 * Modes ("prefix" is TRUE): 
     104 *   OD_BASENAME -- Chain Mail of Death 
     105 *   OD_INSTORE  -- 5 Rings of Death [1,+3] (+2 to Stealth) {nifty} 
     106 *   OD_ALL      -- 5 Rings of Death [1,+3] (+2 to Stealth) {nifty} (squelch) 
     107 * 
     108 * Modes ("prefix" is FALSE): 
     109 *   OD_BASENAME -- Chain Mail of Death 
     110 *   OD_INSTORE  -- Rings of Death [1,+3] (+2 to Stealth) {nifty} 
     111 *   OD_ALL      -- Rings of Death [1,+3] (+2 to Stealth) {nifty} (squelch) 
     112 */ 
     113size_t object_desc(char *buf, size_t max, const object_type *o_ptr, bool prefix, int mode); 
     114 
     115/** 
     116 * Describes item "o_ptr" fully into buffer "buf" of size "max". 
     117 * 
     118 * This differs from object_desc() only in that it can provide information the 
     119 * player isn't meant to know. 
     120 */ 
     121void object_desc_spoil(char *buf, size_t max, const object_type *o_ptr, int pref, int mode); 
     122 
     123/** 
     124 * Describe item kind "k_idx" into buffer "buf" of size "max". 
     125 * 
     126 * XXX 
     127 */ 
     128void object_kind_name(char *buf, size_t max, int k_idx, bool easy_know); 
     129 
     130 
    74131/* obj-make.c */ 
    75132void free_obj_alloc(void); 
  • trunk/src/object1.c

    r625 r652  
    2020 
    2121 
    22 /* 
    23  * Max sizes of the following arrays. 
    24  */ 
    25 #define MAX_TITLES     50       /* Used with scrolls (min 48) */ 
    26  
    2722 
    2823/* 
    2924 * Hold the titles of scrolls, 6 to 14 characters each. 
    30  * 
    31  * Also keep an array of scroll colors (always WHITE for now). 
    32  */ 
    33  
    34 static char scroll_adj[MAX_TITLES][16]; 
     25 */ 
     26char scroll_adj[MAX_TITLES][16]; 
    3527 
    3628 
     
    372364 
    373365 
    374  
    375 /* 
    376  * Puts a very stripped-down version of an object's name into buf. 
    377  * If easy_know is TRUE, then the IDed names are used, otherwise 
    378  * flavours, scroll names, etc will be used. 
    379  * 
    380  * Just truncates if the buffer isn't big enough. 
    381  */ 
    382 void object_kind_name(char *buf, size_t max, int k_idx, bool easy_know) 
    383 { 
    384         char *t; 
    385  
    386         object_kind *k_ptr = &k_info[k_idx]; 
    387  
    388         /* If not aware, use flavor */ 
    389         if (!easy_know && !k_ptr->aware && k_ptr->flavor) 
    390         { 
    391                 if (k_ptr->tval == TV_SCROLL) 
    392                 { 
    393                         strnfmt(buf, max, "\"%s\"", scroll_adj[k_ptr->sval]); 
    394                 } 
    395                 else if (k_ptr->tval == TV_FOOD && k_ptr->sval < SV_FOOD_MIN_FOOD) 
    396                 { 
    397                         strnfmt(buf, max, "%s Mushroom", flavor_text + flavor_info[k_ptr->flavor].text); 
    398                 } 
    399                 else 
    400                 { 
    401                         /* Plain flavour (e.g. Copper) will do. */ 
    402                         my_strcpy(buf, flavor_text + flavor_info[k_ptr->flavor].text, max); 
    403                 } 
    404         } 
    405  
    406         /* Use proper name (Healing, or whatever) */ 
    407         else 
    408         { 
    409                 cptr str = (k_name + k_ptr->name); 
    410  
    411                 if (k_ptr->tval == TV_FOOD && k_ptr->sval < SV_FOOD_MIN_FOOD) 
    412                 { 
    413                         my_strcpy(buf, "Mushroom of ", max); 
    414                         max -= strlen(buf); 
    415                         t = buf + strlen(buf); 
    416                 } 
    417                 else 
    418                 { 
    419                         t = buf; 
    420                 } 
    421  
    422                 /* Skip past leading characters */ 
    423                 while ((*str == ' ') || (*str == '&')) str++; 
    424  
    425                 /* Copy useful chars */ 
    426                 for (; *str && max > 1; str++) 
    427                 { 
    428                         /* Pluralizer for irregular plurals */ 
    429                         /* Useful for languages where adjective changes for plural */ 
    430                         if (*str == '|') 
    431                         { 
    432                                 /* Process singular part */ 
    433                                 for (str++; *str != '|' && max > 1; str++)  
    434                                 { 
    435                                         *t++ = *str; 
    436                                         max--; 
    437                                 } 
    438  
    439                                 /* Process plural part */ 
    440                                 for (str++; *str != '|'; str++) ; 
    441                         } 
    442  
    443                         /* English plural indicator can simply be skipped */ 
    444                         else if (*str != '~') 
    445                         { 
    446                                 *t++ = *str; 
    447                                 max--; 
    448                         } 
    449                 } 
    450  
    451                 /* Terminate the new name */ 
    452                 *t = '\0'; 
    453         } 
    454 } 
    455  
    456  
    457  
    458 /* 
    459  * Efficient version of '(T) += sprintf((T), "%c", (C))' 
    460  */ 
    461 #define object_desc_chr_macro(T,C) do { \ 
    462  \ 
    463         /* Copy the char */ \ 
    464         *(T)++ = (C); \ 
    465  \ 
    466 } while (0) 
    467  
    468  
    469  
    470 /* 
    471  * Efficient version of '(T) += sprintf((T), "%s", (S))' 
    472  */ 
    473 #define object_desc_str_macro(T,S) do { \ 
    474  \ 
    475         cptr s = (S); \ 
    476  \ 
    477         /* Copy the string */ \ 
    478         while (*s) *(T)++ = *s++; \ 
    479  \ 
    480 } while (0) 
    481  
    482  
    483  
    484 /* 
    485  * Efficient version of '(T) += sprintf((T), "%u", (N))' 
    486  */ 
    487 #define object_desc_num_macro(T,N) do { \ 
    488  \ 
    489         int n = (N); \ 
    490  \ 
    491         int p; \ 
    492  \ 
    493         /* Find "size" of "n" */ \ 
    494         for (p = 1; n >= p * 10; p = p * 10) /* loop */; \ 
    495  \ 
    496         /* Dump each digit */ \ 
    497         while (p >= 1) \ 
    498         { \ 
    499                 /* Dump the digit */ \ 
    500                 *(T)++ = I2D(n / p); \ 
    501  \ 
    502                 /* Remove the digit */ \ 
    503                 n = n % p; \ 
    504  \ 
    505                 /* Process next digit */ \ 
    506                 p = p / 10; \ 
    507         } \ 
    508  \ 
    509 } while (0) 
    510  
    511  
    512  
    513 /* 
    514  * Efficient version of '(T) += sprintf((T), "%+d", (I))' 
    515  */ 
    516 #define object_desc_int_macro(T,I) do { \ 
    517  \ 
    518         int i = (I); \ 
    519  \ 
    520         /* Negative */ \ 
    521         if (i < 0) \ 
    522         { \ 
    523                 /* Take the absolute value */ \ 
    524                 i = 0 - i; \ 
    525  \ 
    526                 /* Use a "minus" sign */ \ 
    527                 *(T)++ = '-'; \ 
    528         } \ 
    529  \ 
    530         /* Positive (or zero) */ \ 
    531         else \ 
    532         { \ 
    533                 /* Use a "plus" sign */ \ 
    534                 *(T)++ = '+'; \ 
    535         } \ 
    536  \ 
    537         /* Dump the number itself */ \ 
    538         object_desc_num_macro(T, i); \ 
    539  \ 
    540 } while (0) 
    541  
    542  
    543  
    544  
    545 /* 
    546  * Creates a description of the item "o_ptr", and stores it in "buf". 
    547  * 
    548  * One can choose the "verbosity" of the description, including whether 
    549  * or not the "number" of items should be described, and how much detail 
    550  * should be used when describing the item. 
    551  * 
    552  * The given "buf" should be at least 80 chars long to hold the longest 
    553  * possible description, which can get pretty long, including inscriptions, 
    554  * such as: 
    555  * "no more Maces of Disruption (Defender) (+10,+10) [+5] (+3 to stealth)". 
    556  * 
    557  * Note that the object description will be clipped to fit into the given 
    558  * buffer size. 
    559  * 
    560  * Note the use of "object_desc_int_macro()" and "object_desc_num_macro()" 
    561  * and "object_desc_str_macro()" and "object_desc_chr_macro()" as extremely 
    562  * efficient, portable, versions of some common "sprintf()" commands (without 
    563  * the bounds checking or termination writing), which allow a pointer to 
    564  * efficiently move through a buffer while modifying it in various ways. 
    565  * 
    566  * Various improper uses and/or placements of "&" or "~" characters can 
    567  * easily induce out-of-bounds memory accesses.  Some of these could be 
    568  * easily checked for, if efficiency was not a concern. 
    569  * 
    570  * Note that all ego-items (when known) append an "Ego-Item Name", unless 
    571  * the item is also an artifact, which should never happen. 
    572  * 
    573  * Note that all artifacts (when known) append an "Artifact Name", so we 
    574  * have special processing for "Specials" (artifact Lites, Rings, Amulets). 
    575  * The "Specials" never use "modifiers" if they are "known", since they 
    576  * have special "descriptions", such as "The Necklace of the Dwarves". 
    577  * 
    578  * Special Lite's use the "k_info" base-name (Phial, Star, or Arkenstone), 
    579  * plus the artifact name, just like any other artifact, if known. 
    580  * 
    581  * Special Ring's and Amulet's, if not "aware", use the same code as normal 
    582  * rings and amulets, and if "aware", use the "k_info" base-name (Ring or 
    583  * Amulet or Necklace).  They will NEVER "append" the "k_info" name.  But, 
    584  * they will append the artifact name, just like any artifact, if known. 
    585  * 
    586  * None of the Special Rings/Amulets are "EASY_KNOW", though they could be, 
    587  * at least, those which have no "pluses", such as the three artifact lites. 
    588  * 
    589  * The "pluralization" rules are extremely hackish, in fact, for efficiency, 
    590  * we only handle things like "torch"/"torches" and "cutlass"/"cutlasses", 
    591  * and we would not handle "box"/"boxes", or "knife"/"knives", correctly. 
    592  * Of course, it would be easy to add rules for these forms. 
    593  * 
    594  * If "pref" is true then a "numeric" prefix will be pre-pended, else is is 
    595  * assumed that a string such as "The" or "Your" will be pre-pended later. 
    596  * 
    597  * Modes ("pref" is TRUE): 
    598  *   0 -- Chain Mail of Death 
    599  *   1 -- A Cloak of Death [1,+3] 
    600  *   2 -- An Amulet of Death [1,+3] (+2 to Stealth) 
    601  *   3 -- 5 Rings of Death [1,+3] (+2 to Stealth) {nifty} (squelch) 
    602  *   4 -- 5 Rings of Death [1,+3] (+2 to Stealth) {nifty} 
    603  * 
    604  * Modes ("pref" is FALSE): 
    605  *   0 -- Chain Mail of Death 
    606  *   1 -- Cloak of Death [1,+3] 
    607  *   2 -- Amulet of Death [1,+3] (+2 to Stealth) 
    608  *   3 -- Rings of Death [1,+3] (+2 to Stealth) {nifty} (squelch) 
    609  *   4 -- Rings of Death [1,+3] (+2 to Stealth) {nifty} 
    610  */ 
    611 void object_desc(char *buf, size_t max, const object_type *o_ptr, int pref, int mode) 
    612 { 
    613         cptr basenm; 
    614         cptr modstr; 
    615  
    616         int power; 
    617  
    618         bool aware; 
    619         bool known; 
    620  
    621         bool flavor; 
    622  
    623         bool append_name; 
    624  
    625         bool show_weapon; 
    626         bool show_armour; 
    627  
    628         char *b; 
    629  
    630         char *t; 
    631  
    632         cptr s; 
    633  
    634         cptr u; 
    635         cptr v; 
    636  
    637         char p1 = '(', p2 = ')'; 
    638         char b1 = '[', b2 = ']'; 
    639         char c1 = '{', c2 = '}'; 
    640  
    641         char tmp_buf[128]; 
    642  
    643         u32b f1, f2, f3; 
    644  
    645         object_kind *k_ptr = &k_info[o_ptr->k_idx]; 
    646  
    647  
    648         /* Extract some flags */ 
    649         object_flags(o_ptr, &f1, &f2, &f3); 
    650  
    651  
    652         /* See if the object is "aware" */ 
    653         aware = (object_aware_p(o_ptr) ? TRUE : FALSE); 
    654  
    655         /* See if the object is "known" */ 
    656         known = (object_known_p(o_ptr) ? TRUE : FALSE); 
    657  
    658         /* See if the object is "flavored" */ 
    659         flavor = (k_ptr->flavor ? TRUE : FALSE); 
    660  
    661         /* Allow flavors to be hidden when aware */ 
    662         if (aware && !show_flavors) flavor = FALSE; 
    663  
    664         /* Hack -- mark-to-squelch worthless items XXX */ 
    665         if (!k_ptr->everseen && aware && OPT(squelch_worthless)) 
    666         { 
    667                 if (object_value(o_ptr) == 0) 
    668                 { 
    669                         k_ptr->squelch = TRUE; 
    670                         p_ptr->notice |= PN_SQUELCH; 
    671                 } 
    672         } 
    673  
    674         /* We've seen it at least once now we're aware of it */ 
    675         if (aware) k_ptr->everseen = TRUE; 
    676  
    677         /* Object is in the inventory of a store */ 
    678         if (o_ptr->ident & IDENT_STORE) 
    679         { 
    680                 /* Don't show flavors */ 
    681                 flavor = FALSE; 
    682  
    683                 /* Pretend known and aware */ 
    684                 aware = TRUE; 
    685                 known = TRUE; 
    686         } 
    687  
    688  
    689         /* XXX anything object_desc'd can be squelched */ 
    690         if (aware) k_ptr->everseen = TRUE; 
    691  
    692         /* Assume no name appending */ 
    693         append_name = FALSE; 
    694  
    695         /* Assume no need to show "weapon" bonuses */ 
    696         show_weapon = FALSE; 
    697  
    698         /* Assume no need to show "armour" bonuses */ 
    699         show_armour = FALSE; 
    700  
    701         /* Extract default "base" string */ 
    702         basenm = (k_name + k_ptr->name); 
    703  
    704         /* Assume no "modifier" string */ 
    705         modstr = ""; 
    706  
    707  
    708         /* Analyze the object */ 
    709         switch (o_ptr->tval) 
    710         { 
    711                 /* Some objects are easy to describe */ 
    712                 case TV_SKELETON: 
    713                 case TV_BOTTLE: 
    714                 case TV_JUNK: 
    715                 case TV_SPIKE: 
    716                 case TV_FLASK: 
    717                 case TV_CHEST: 
    718                 { 
    719                         break; 
    720                 } 
    721  
    722                 /* Missiles/Bows/Weapons */ 
    723                 case TV_SHOT: 
    724                 case TV_BOLT: 
    725                 case TV_ARROW: 
    726                 case TV_BOW: 
    727                 case TV_HAFTED: 
    728                 case TV_POLEARM: 
    729                 case TV_SWORD: 
    730                 case TV_DIGGING: 
    731                 { 
    732                         show_weapon = TRUE; 
    733                         break; 
    734                 } 
    735  
    736                 /* Armour */ 
    737                 case TV_BOOTS: 
    738                 case TV_GLOVES: 
    739                 case TV_CLOAK: 
    740                 case TV_CROWN: 
    741                 case TV_HELM: 
    742                 case TV_SHIELD: 
    743                 case TV_SOFT_ARMOR: 
    744                 case TV_HARD_ARMOR: 
    745                 case TV_DRAG_ARMOR: 
    746                 { 
    747                         show_armour = TRUE; 
    748                         break; 
    749                 } 
    750  
    751                 /* Lites (including a few "Specials") */ 
    752                 case TV_LITE: 
    753                 { 
    754                         break; 
    755                 } 
    756  
    757                 /* Amulets (including a few "Specials") */ 
    758                 case TV_AMULET: 
    759                 { 
    760                         /* Hack -- Known artifacts */ 
    761                         if (artifact_p(o_ptr) && aware) break; 
    762  
    763                         /* Color the object */ 
    764                         modstr = flavor_text + flavor_info[k_ptr->flavor].text; 
    765                         if (aware) append_name = TRUE; 
    766                         basenm = (flavor ? "& # Amulet~" : "& Amulet~"); 
    767  
    768                         break; 
    769                 } 
    770  
    771                 /* Rings (including a few "Specials") */ 
    772                 case TV_RING: 
    773                 { 
    774                         /* Hack -- Known artifacts */ 
    775                         if (artifact_p(o_ptr) && aware) break; 
    776  
    777                         /* Color the object */ 
    778                         modstr = flavor_text + flavor_info[k_ptr->flavor].text; 
    779                         if (aware) append_name = TRUE; 
    780                         basenm = (flavor ? "& # Ring~" : "& Ring~"); 
    781  
    782                         break; 
    783                 } 
    784  
    785                 /* Staffs */ 
    786                 case TV_STAFF: 
    787                 { 
    788                         /* Color the object */ 
    789                         modstr = flavor_text + flavor_info[k_ptr->flavor].text; 
    790                         if (aware) append_name = TRUE; 
    791                         basenm = (flavor ? "& # Staff~" : "& Staff~"); 
    792  
    793                         break; 
    794                 } 
    795  
    796                 /* Wands */ 
    797                 case TV_WAND: 
    798                 { 
    799                         /* Color the object */ 
    800                         modstr = flavor_text + flavor_info[k_ptr->flavor].text; 
    801                         if (aware) append_name = TRUE; 
    802                         basenm = (flavor ? "& # Wand~" : "& Wand~"); 
    803  
    804                         break; 
    805                 } 
    806  
    807                 /* Rods */ 
    808                 case TV_ROD: 
    809                 { 
    810                         /* Color the object */ 
    811                         modstr = flavor_text + flavor_info[k_ptr->flavor].text; 
    812                         if (aware) append_name = TRUE; 
    813                         basenm = (flavor ? "& # Rod~" : "& Rod~"); 
    814  
    815                         break; 
    816                 } 
    817  
    818                 /* Scrolls */ 
    819                 case TV_SCROLL: 
    820                 { 
    821                         /* Color the object */ 
    822                         modstr = scroll_adj[o_ptr->sval]; 
    823                         if (aware) append_name = TRUE; 
    824                         basenm = (flavor ? "& Scroll~ titled \"#\"" : "& Scroll~"); 
    825  
    826                         break; 
    827                 } 
    828  
    829                 /* Potions */ 
    830                 case TV_POTION: 
    831                 { 
    832                         /* Color the object */ 
    833                         modstr = flavor_text + flavor_info[k_ptr->flavor].text; 
    834                         if (aware) append_name = TRUE; 
    835                         basenm = (flavor ? "& # Potion~" : "& Potion~"); 
    836  
    837                         break; 
    838                 } 
    839  
    840                 /* Food */ 
    841                 case TV_FOOD: 
    842                 { 
    843                         /* Ordinary food is "boring" */ 
    844                         if (o_ptr->sval >= SV_FOOD_MIN_FOOD) break; 
    845  
    846                         /* Color the object */ 
    847                         modstr = flavor_text + flavor_info[k_ptr->flavor].text; 
    848                         if (aware) append_name = TRUE; 
    849                         basenm = (flavor ? "& # Mushroom~" : "& Mushroom~"); 
    850  
    851                         break; 
    852                 } 
    853  
    854                 /* Magic Books */ 
    855                 case TV_MAGIC_BOOK: 
    856                 { 
    857                         modstr = basenm; 
    858                         basenm = "& Book~ of Magic Spells #"; 
    859                         break; 
    860                 } 
    861  
    862                 /* Prayer Books */ 
    863                 case TV_PRAYER_BOOK: 
    864                 { 
    865                         modstr = basenm; 
    866                         basenm = "& Holy Book~ of Prayers #"; 
    867                         break; 
    868                 } 
    869  
    870                 /* Hack -- Gold/Gems */ 
    871                 case TV_GOLD: 
    872                 { 
    873                         my_strcpy(buf, basenm, max); 
    874                         return; 
    875                 } 
    876  
    877                 /* Hack -- Default -- Used in the "inventory" routine */ 
    878                 default: 
    879                 { 
    880                         my_strcpy(buf, "(nothing)", max); 
    881                         return; 
    882                 } 
    883         } 
    884  
    885  
    886         /* Start dumping the result */ 
    887         t = b = tmp_buf; 
    888  
    889         /* Begin */ 
    890         s = basenm; 
    891  
    892         /* Handle objects which sometimes use "a" or "an" */ 
    893         if (*s == '&') 
    894         { 
    895                 /* Paranoia XXX XXX XXX */ 
    896                 /* ASSERT(s[1] == ' '); */ 
    897  
    898                 /* Skip the ampersand and the following space */ 
    899                 s += 2; 
    900  
    901                 /* No prefix */ 
    902                 if (!pref) 
    903                 { 
    904                         /* Nothing */ 
    905                 } 
    906  
    907                 /* Hack -- None left */ 
    908                 else if (o_ptr->number <= 0) 
    909                 { 
    910                         object_desc_str_macro(t, "no more "); 
    911                 } 
    912  
    913                 /* Extract the number */ 
    914                 else if (o_ptr->number > 1) 
    915                 { 
    916                         object_desc_num_macro(t, o_ptr->number); 
    917                         object_desc_chr_macro(t, ' '); 
    918                 } 
    919  
    920                 /* Hack -- The only one of its kind */ 
    921                 else if (known && artifact_p(o_ptr)) 
    922                 { 
    923                         object_desc_str_macro(t, "The "); 
    924                 } 
    925  
    926                 /* Hack -- A single one, and next character will be a vowel */ 
    927                 else if ((*s == '#') ? is_a_vowel(modstr[0]) : is_a_vowel(*s)) 
    928                 { 
    929                         object_desc_str_macro(t, "an "); 
    930                 } 
    931  
    932