Changeset 461

Show
Ignore:
Timestamp:
08/07/07 16:50:02 (1 year ago)
Author:
takkaria
Message:

Do a little code review on util.c:

  • Move damroll() function into z-rand, where it belongs.
  • Move gamma comment to where the gamma code is located.
  • Clean up the code generally; restyle so things are a bit more compact, and also so it fits the coding guidelines a bit better.
  • Remove unused functions (maxroll, get_check_other).
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/externs.h

    r455 r461  
    671671extern void pause_line(int row); 
    672672extern void request_command(void); 
    673 extern int damroll(int num, int sides); 
    674 extern int maxroll(int num, int sides); 
    675673extern bool is_a_vowel(int ch); 
    676674extern int color_char_to_attr(char c); 
  • trunk/src/util.c

    r460 r461  
    2222} 
    2323 
    24  
    25  
    2624/* 
    2725 * Convert a hexidecimal-digit into a decimal 
     
    8179 
    8280                /* Shift key might be going to change keycode */ 
    83                 if ('S' == macro_modifier_chr[i]
     81                if (macro_modifier_chr[i] == 'S'
    8482                        shiftstatus = 1; 
    8583        } 
     
    127125        { 
    128126                char ch = macro_template[i]; 
    129                 int j; 
    130  
    131                 switch(ch) 
    132                 { 
    133                 case '&': 
     127 
     128                switch (ch) 
     129                { 
    134130                        /* Modifier key character */ 
    135                         for (j = 0; macro_modifier_chr[j]; j++) 
    136                         { 
    137                                 if (mod_status[j]) 
    138                                         strnfcat(buf, max, &current_len, "%c", macro_modifier_chr[j]); 
    139                         } 
    140                         break; 
    141                 case '#': 
     131                        case '&': 
     132                                size_t j; 
     133                                for (j = 0; macro_modifier_chr[j]; j++) 
     134                                { 
     135                                        if (mod_status[j]) 
     136                                                strnfcat(buf, max, &current_len, "%c", macro_modifier_chr[j]); 
     137                                } 
     138                                break; 
     139 
    142140                        /* Key code */ 
    143                         strnfcat(buf, max, &current_len, "%s", key_code); 
    144                         break; 
    145                 default: 
     141                        case '#': 
     142                                strnfcat(buf, max, &current_len, "%s", key_code); 
     143                                break; 
     144 
    146145                        /* Fixed string */ 
    147                         strnfcat(buf, max, &current_len, "%c", ch); 
    148                         break; 
     146                        default: 
     147                                strnfcat(buf, max, &current_len, "%c", ch); 
     148                                break; 
    149149                } 
    150150        } 
     
    180180                if (*str == '\\') 
    181181                { 
    182                         /* Skip the backslash */ 
    183182                        str++; 
    184  
    185                         /* Paranoia */ 
    186                         if (!(*str)) break; 
    187  
    188                         /* Macro Trigger */ 
    189                         if (*str == '[') 
     183                        if (*str == '\0') break; 
     184 
     185                        switch (*str) 
    190186                        { 
    191                                 /* Terminate before appending the trigger */ 
    192                                 *s = '\0'; 
    193  
    194                                 s += trigger_text_to_ascii(buf, len, &str); 
    195                         } 
    196  
    197                         /* Hack -- simple way to specify Escape */ 
    198                         else if (*str == 'e') 
    199                         { 
    200                                 *s++ = ESCAPE; 
    201                         } 
    202  
    203                         /* Hack -- simple way to specify "space" */ 
    204                         else if (*str == 's') 
    205                         { 
    206                                 *s++ = ' '; 
    207                         } 
    208  
    209                         /* Backspace */ 
    210                         else if (*str == 'b') 
    211                         { 
    212                                 *s++ = '\b'; 
    213                         } 
    214  
    215                         /* Newline */ 
    216                         else if (*str == 'n') 
    217                         { 
    218                                 *s++ = '\n'; 
    219                         } 
    220  
    221                         /* Return */ 
    222                         else if (*str == 'r') 
    223                         { 
    224                                 *s++ = '\r'; 
    225                         } 
    226  
    227                         /* Tab */ 
    228                         else if (*str == 't') 
    229                         { 
    230                                 *s++ = '\t'; 
    231                         } 
    232  
    233                         /* Bell */ 
    234                         else if (*str == 'a') 
    235                         { 
    236                                 *s++ = '\a'; 
    237                         } 
    238  
    239                         /* Actual "backslash" */ 
    240                         else if (*str == '\\') 
    241                         { 
    242                                 *s++ = '\\'; 
    243                         } 
    244  
    245                         /* Hack -- Actual "caret" */ 
    246                         else if (*str == '^') 
    247                         { 
    248                                 *s++ = '^'; 
    249                         } 
    250  
    251                         /* Hack -- Hex-mode */ 
    252                         else if (*str == 'x') 
    253                         { 
    254                                 if (isxdigit((unsigned char)(*(str + 1))) && 
    255                                     isxdigit((unsigned char)(*(str + 2)))) 
     187                                /* Macro trigger */ 
     188                                case '[': 
    256189                                { 
    257                                         *s = 16 * dehex(*++str); 
    258                                         *s++ += dehex(*++str); 
     190                                        /* Terminate before appending the trigger */ 
     191                                        *s = '\0'; 
     192                                        s += trigger_text_to_ascii(buf, len, &str); 
     193                                        break; 
    259194                                } 
    260                                 else 
     195 
     196                                /* Hex-mode */ 
     197                                case 'x': 
    261198                                { 
    262                                         /* HACK - Invalid hex number */ 
    263                                         *s++ = '?'; 
     199                                        if (isxdigit((unsigned char)(*(str + 1))) && 
     200                                            isxdigit((unsigned char)(*(str + 2)))) 
     201                                        { 
     202                                                *s = 16 * dehex(*++str); 
     203                                                *s++ += dehex(*++str); 
     204                                        } 
     205                                        else 
     206                                        { 
     207                                                /* HACK - Invalid hex number */ 
     208                                                *s++ = '?'; 
     209                                        } 
     210                                        break; 
    264211                                } 
    265                         } 
    266  
    267                         /* Oops */ 
    268                         else 
    269                         { 
    270                                 *s = *str; 
     212 
     213                                case 'e': 
     214                                        *s++ = ESCAPE; 
     215                                        break; 
     216                                case 's': 
     217                                        *s++ = ' '; 
     218                                        break; 
     219                                case 'b': 
     220                                        *s++ = '\b'; 
     221                                        break; 
     222                                case 'n': 
     223                                        *s++ = '\n'; 
     224                                        break; 
     225                                case 'r': 
     226                                        *s++ = '\r'; 
     227                                        break; 
     228                                case 't': 
     229                                        *s++ = '\t'; 
     230                                        break; 
     231                                case 'a': 
     232                                        *s++ = '\a'; 
     233                                        break; 
     234                                case '\\': 
     235                                        *s++ = '\\'; 
     236                                        break; 
     237                                case '^': 
     238                                        *s++ = '^'; 
     239                                        break; 
     240 
     241                                default: 
     242                                        *s = *str; 
     243                                        break; 
    271244                        } 
    272245 
     
    279252                { 
    280253                        str++; 
    281  
    282                         if (*str) 
    283                         { 
    284                                 *s++ = KTRL(*str); 
    285                                 str++; 
    286                         } 
     254                        if (*str == '\0') break; 
     255 
     256                        *s++ = KTRL(*str); 
     257                        str++; 
    287258                } 
    288259 
     
    321292        for (i = 0; macro_template[i]; i++) 
    322293        { 
    323                 int j; 
    324294                char ch = macro_template[i]; 
    325295 
    326                 switch(ch) 
    327                 { 
    328                 case '&': 
     296                switch (ch) 
     297                { 
    329298                        /* Read modifier */ 
    330                         while ((tmp = strchr(macro_modifier_chr, *str))) 
    331                         { 
    332                                 j = (int)(tmp - macro_modifier_chr); 
    333                                 strnfcat(buf, max, &current_len, "%s", macro_modifier_name[j]); 
     299                        case '&': 
     300                                size_t j; 
     301                                while ((tmp = strchr(macro_modifier_chr, *str))) 
     302                                { 
     303                                        j = tmp - macro_modifier_chr; 
     304                                        strnfcat(buf, max, &current_len, "%s", macro_modifier_name[j]); 
     305                                        str++; 
     306                                } 
     307                                break; 
     308 
     309                        /* Read key code */ 
     310                        case '#': 
     311                                size_t j; 
     312                                for (j = 0; *str && (*str != '\r') && (j < sizeof(key_code) - 1); j++) 
     313                                        key_code[j] = *str++; 
     314                                key_code[j] = '\0'; 
     315                                break; 
     316 
     317                        /* Skip fixed strings */ 
     318                        default: 
     319                                if (ch != *str) return 0; 
    334320                                str++; 
    335                         } 
    336                         break; 
    337                 case '#': 
    338                         /* Read key code */ 
    339                         for (j = 0; *str && (*str != '\r') && (j < (int)sizeof(key_code) - 1); j++) 
    340                                 key_code[j] = *str++; 
    341                         key_code[j] = '\0'; 
    342                         break; 
    343                 default: 
    344                         /* Skip fixed strings */ 
    345                         if (ch != *str) return 0; 
    346                         str++; 
    347321                } 
    348322        } 
     
    502476        /* Nothing possible */ 
    503477        if (!macro__use[(byte)(pat[0])]) 
    504         { 
    505                 return (-1); 
    506         } 
     478                return -1; 
    507479 
    508480        /* Scan the macros */ 
    509481        for (i = 0; i < macro__num; ++i) 
    510482        { 
    511                 /* Skip macros which do not match the pattern */ 
    512                 if (!streq(macro__pat[i], pat)) continue; 
    513  
    514                 /* Found one */ 
    515                 return (i); 
     483                if (streq(macro__pat[i], pat)) 
     484                        return i; 
    516485        } 
    517486 
    518487        /* No matches */ 
    519         return (-1)
     488        return -1
    520489} 
    521490 
     
    530499        /* Nothing possible */ 
    531500        if (!macro__use[(byte)(pat[0])]) 
    532         { 
    533                 return (-1); 
    534         } 
     501                return -1; 
    535502 
    536503        /* Scan the macros */ 
    537504        for (i = 0; i < macro__num; ++i) 
    538505        { 
    539                 /* Skip macros which do not contain the pattern */ 
    540                 if (!prefix(macro__pat[i], pat)) continue; 
    541  
    542                 /* Found one */ 
    543                 return (i); 
     506                if (prefix(macro__pat[i], pat)) 
     507                        return i; 
    544508        } 
    545509 
    546510        /* Nothing */ 
    547         return (-1); 
    548 
    549  
     511        return -1; 
     512
    550513 
    551514 
     
    559522        /* Nothing possible */ 
    560523        if (!macro__use[(byte)(pat[0])]) 
    561         { 
    562                 return (-1); 
    563         } 
     524                return -1; 
    564525 
    565526        /* Scan the macros */ 
    566527        for (i = 0; i < macro__num; ++i) 
    567528        { 
    568                 /* Skip macros which do not contain the pattern */ 
    569                 if (!prefix(macro__pat[i], pat)) continue; 
    570  
    571                 /* Skip macros which exactly match the pattern XXX XXX */ 
    572                 if (streq(macro__pat[i], pat)) continue; 
    573  
    574                 /* Found one */ 
    575                 return (i); 
     529                if (prefix(macro__pat[i], pat) && !streq(macro__pat[i], pat)) 
     530                        return i; 
    576531        } 
    577532 
    578533        /* Nothing */ 
    579         return (-1); 
    580 
     534        return -1; 
     535
     536 
    581537 
    582538 
     
    590546        /* Nothing possible */ 
    591547        if (!macro__use[(byte)(pat[0])]) 
    592         { 
    593                 return (-1); 
    594         } 
     548                return -1; 
    595549 
    596550        /* Scan the macros */ 
     
    612566 
    613567        /* Result */ 
    614         return (n)
     568        return n
    615569} 
    616570 
     
    634588        int n; 
    635589 
    636  
    637         /* Paranoia -- require data */ 
    638590        if (!pat || !act) return (-1); 
    639591 
     
    645597        if (n >= 0) 
    646598        { 
    647                 /* Free the old macro action */ 
    648599                string_free(macro__act[n]); 
    649600        } 
     
    654605                /* Get a new index */ 
    655606                n = macro__num++; 
    656  
    657                 /* Boundary check */ 
    658607                if (macro__num >= MACRO_MAX) quit("Too many macros!"); 
    659608 
     
    695644errr macro_free(void) 
    696645{ 
    697         int i, j; 
     646        int i; 
     647        size_t j; 
    698648 
    699649        /* Free the macros */ 
     
    710660        for (i = 0; i < KEYMAP_MODES; ++i) 
    711661        { 
    712                 for (j = 0; j < (int)N_ELEMENTS(keymap_act[i]); ++j) 
     662                for (j = 0; j < N_ELEMENTS(keymap_act[i]); ++j) 
    713663                { 
    714664                        string_free(keymap_act[i][j]); 
     
    12981248char anykey(void) 
    12991249{ 
    1300   event_type ke = EVENT_EMPTY; 
     1250       event_type ke = EVENT_EMPTY; 
    13011251   
    1302   /* Only accept a keypress or mouse click*/ 
    1303   do 
    1304    
    1305       ke = inkey_ex(); 
    1306     } while (!(ke.type & (EVT_MOUSE|EVT_KBRD))); 
    1307    
    1308   return ke.key; 
     1252       /* Only accept a keypress or mouse click*/ 
     1253       do 
     1254       
     1255               ke = inkey_ex(); 
     1256       } while ((ke.type != EVT_MOUSE) && (ke.type != EVT_KBRD)); 
     1257 
     1258       return ke.key; 
    13091259} 
    13101260 
     
    13141264char inkey(void) 
    13151265{ 
    1316         event_type ke
     1266        event_type ke = EVENT_EMPTY
    13171267 
    13181268        /* Only accept a keypress */ 
     
    13201270        { 
    13211271                ke = inkey_ex(); 
    1322         } while (!(ke.type  & (EVT_KBRD|EVT_ESCAPE))); 
     1272        } while ((ke.type != EVT_ESCAPE) && (ke.type != EVT_KBRD)); 
     1273 
    13231274        /* Paranoia */ 
    1324         if(ke.type == EVT_ESCAPE) ke.key = ESCAPE; 
    1325  
     1275        if (ke.type == EVT_ESCAPE) ke.key = ESCAPE; 
    13261276        return ke.key; 
    13271277} 
     
    13441294                /* Window stuff */ 
    13451295                p_ptr->window |= (PW_MESSAGE); 
    1346  
    1347                 /* Force window redraw */ 
    13481296                window_stuff(); 
    13491297        } 
     
    13641312{ 
    13651313        /* No sound */ 
    1366         if (!use_sound) return; 
    1367  
    1368         /* Make a noise */ 
    1369         if (sound_hook) 
    1370                 sound_hook(val); 
     1314        if (!use_sound || !sound_hook) return; 
     1315 
     1316        sound_hook(val); 
    13711317} 
    13721318 
     
    13851331        return FALSE; 
    13861332} 
     1333 
    13871334 
    13881335/* 
     
    15331480u16b message_type(s16b age) 
    15341481{ 
    1535         s16b x; 
    1536  
    15371482        /* Paranoia */ 
    1538         if (!message__type) return (MSG_GENERIC); 
     1483        if (!message__type) 
     1484                return MSG_GENERIC; 
    15391485 
    15401486        /* Forgotten messages are generic */ 
    1541         if ((age < 0) || (age >= message_num())) return (MSG_GENERIC); 
    1542  
    1543         /* Get the "logical" index */ 
    1544         x = message_age2idx(age); 
     1487        if ((age < 0) || (age >= message_num())) 
     1488                return MSG_GENERIC; 
    15451489 
    15461490        /* Return the message type */ 
    1547         return (message__type[x]); 
     1491        return (message__type[message_age2idx(age)]); 
    15481492} 
    15491493 
     
    15581502        if (color == TERM_DARK) color = TERM_WHITE; 
    15591503 
    1560         return (color)
     1504        return color
    15611505} 
    15621506 
     
    15731517errr message_color_define(u16b type, byte color) 
    15741518{ 
    1575         /* Ignore illegal types */ 
    1576         if (type >= MSG_MAX) return (1); 
     1519        if (type >= MSG_MAX) return 1; 
    15771520 
    15781521        /* Store the color */ 
    15791522        message__color[type] = color; 
    1580  
    1581         /* Success */ 
    1582         return (0); 
     1523        return 0; 
    15831524} 
    15841525 
     
    16341575                /* Increase the message count */ 
    16351576                message__count[x]++; 
    1636  
    1637                 /* Success */ 
    16381577                return; 
    16391578        } 
     
    18221761 
    18231762        /* Success */ 
    1824         return (0)
     1763        return 0
    18251764} 
    18261765 
     
    18391778 
    18401779 
    1841 /* 
    1842  * XXX XXX XXX Important note about "colors" XXX XXX XXX 
    1843  * 
    1844  * The "TERM_*" color definitions list the "composition" of each 
    1845  * "Angband color" in terms of "quarters" of each of the three color 
    1846  * components (Red, Green, Blue), for example, TERM_UMBER is defined 
    1847  * as 2/4 Red, 1/4 Green, 0/4 Blue. 
    1848  * 
    1849  * The following info is from "Torbjorn Lindgren" (see "main-xaw.c"). 
    1850  * 
    1851  * These values are NOT gamma-corrected.  On most machines (with the 
    1852  * Macintosh being an important exception), you must "gamma-correct" 
    1853  * the given values, that is, "correct for the intrinsic non-linearity 
    1854  * of the phosphor", by converting the given intensity levels based 
    1855  * on the "gamma" of the target screen, which is usually 1.7 (or 1.5). 
    1856  * 
    1857  * The actual formula for conversion is unknown to me at this time, 
    1858  * but you can use the table below for the most common gamma values. 
    1859  * 
    1860  * So, on most machines, simply convert the values based on the "gamma" 
    1861  * of the target screen, which is usually in the range 1.5 to 1.7, and 
    1862  * usually is closest to 1.7.  The converted value for each of the five 
    1863  * different "quarter" values is given below: 
    1864  * 
    1865  *  Given     Gamma 1.0       Gamma 1.5       Gamma 1.7     Hex 1.7 
    1866  *  -----       ----            ----            ----          --- 
    1867  *   0/4        0.00            0.00            0.00          #00 
    1868  *   1/4        0.25            0.27            0.28          #47 
    1869  *   2/4        0.50            0.55            0.56          #8f 
    1870  *   3/4        0.75            0.82            0.84          #d7 
    1871  *   4/4        1.00            1.00            1.00          #ff 
    1872  * 
    1873  * Note that some machines (i.e. most IBM machines) are limited to a 
    1874  * hard-coded set of colors, and so the information above is useless. 
    1875  * 
    1876  * Also, some machines are limited to a pre-determined set of colors, 
    1877  * for example, the IBM can only display 16 colors, and only 14 of 
    1878  * those colors resemble colors used by Angband, and then only when 
    1879  * you ignore the fact that "Slate" and "cyan" are not really matches, 
    1880  * so on the IBM, we use "orange" for both "Umber", and "Light Umber" 
    1881  * in addition to the obvious "Orange", since by combining all of the 
    1882  * "indeterminate" colors into a single color, the rest of the colors 
    1883  * are left with "meaningful" values. 
    1884  */ 
     1780 
    18851781 
    18861782 
     
    26552551} 
    26562552 
     2553 
    26572554/* 
    26582555 * Get some input at the cursor location. 
     
    26792576bool askfor_aux(char *buf, size_t len, bool keypress_h(char *, size_t, size_t *, size_t *, char, bool)) 
    26802577{ 
    2681  
    26822578        int y, x; 
    26832579 
     
    27392635        return (ch != ESCAPE); 
    27402636} 
     2637 
    27412638 
    27422639/* 
     
    29112808} 
    29122809 
    2913 /* 
    2914  * Hack - duplication of get_check prompt to give option of setting destroyed 
    2915  * option to squelch. 
    2916  * 
    2917  * 0 - No 
    2918  * 1 = Yes 
    2919  * 2 = third option 
    2920  * 
    2921  * The "prompt" should take the form "Query? " 
    2922  * 
    2923  * Note that "[y/n/{char}]" is appended to the prompt. 
    2924  */ 
    2925 int get_check_other(cptr prompt, char other) 
    2926 { 
    2927         char ch; 
    2928         char buf[80]; 
    2929  
    2930         int result; 
    2931  
    2932         /* Paranoia XXX XXX XXX */ 
    2933         message_flush(); 
    2934  
    2935         /* Hack -- Build a "useful" prompt */ 
    2936         strnfmt(buf, 78, "%.70s[y/n/%c] ", prompt, other); 
    2937  
    2938         /* Prompt for it */ 
    2939         prt(buf, 0, 0); 
    2940  
    2941         /* Get an acceptable answer */ 
    2942         while (TRUE) 
    2943         { 
    2944                 ch = inkey(); 
    2945                 if (quick_messages) break; 
    2946                 if (ch == ESCAPE) break; 
    2947                 if (strchr("YyNn", ch)) break; 
    2948                 if (ch == toupper((unsigned char) other)) break; 
    2949                 if (ch == tolower((unsigned char) other)) break; 
    2950                 bell("Illegal response to question!"); 
    2951         } 
    2952  
    2953         /* Erase the prompt */ 
    2954         prt("", 0, 0); 
    2955  
    2956  
    2957         /* Yes */ 
    2958         if ((ch == 'Y') || (ch == 'y')) 
    2959                 result = 1; 
    2960  
    2961         /* Third option */ 
    2962         else if ((ch == toupper((unsigned char) other)) || (ch == tolower((unsigned char) other))) 
    2963                 result = 2; 
    2964  
    2965         /* Default to no */ 
    2966         else 
    2967                 result = 0; 
    2968  
    2969  
    2970         /* Success */ 
    2971         return (result); 
    2972 } 
    2973  
    29742810 
    29752811/* 
     
    30342870} 
    30352871 
     2872 
    30362873bool get_com_ex(cptr prompt, event_type *command) 
    30372874{ 
     
    31022939{ 
    31032940        int i; 
     2941        int mode; 
    31042942 
    31052943        event_type ke = EVENT_EMPTY; 
    31062944 
    3107         int mode; 
    3108  
    31092945        cptr act; 
    31102946 
    31112947 
    3112         /* Roguelike */ 
    31132948        if (rogue_like_commands) 
    3114         { 
    31152949                mode = KEYMAP_MODE_ROGUE; 
    3116         } 
    3117  
    3118         /* Original */ 
    31192950        else 
    3120         { 
    31212951                mode = KEYMAP_MODE_ORIG; 
    3122         } 
    3123  
    3124  
    3125         /* No command yet */ 
     2952 
     2953 
     2954        /* Reset command/argument/direction */ 
    31262955        p_ptr->command_cmd = 0; 
    3127  
    3128         /* No "argument" yet */ 
    31292956        p_ptr->command_arg = 0; 
    3130  
    3131         /* No "direction" yet */ 
    31322957        p_ptr->command_dir = 0; 
    31332958 
     
    33783203 
    33793204 
    3380 /* 
    3381  * Generates damage for "2d6" style dice rolls 
    3382  */ 
    3383 int damroll(int num, int sides) 
    3384 { 
    3385         int i; 
    3386         int sum = 0; 
    3387  
    3388  
    3389         /* HACK - prevent undefined behaviour */ 
    3390         if (sides <= 0) return (0); 
    3391  
    3392         for (i = 0; i < num; i++) 
    3393         { 
    3394                 sum += rand_die(sides); 
    3395         } 
    3396  
    3397         return (sum); 
    3398 } 
    3399  
    3400  
    3401  
    34023205 
    34033206/* 
     
    34133216                case 'o': 
    34143217                case 'u': 
     3218                { 
    34153219                        return (TRUE); 
     3220                } 
    34163221        } 
    34173222 
     
    34563261int color_text_to_attr(cptr name) 
    34573262{ 
    3458         if (my_stricmp(name, "dark")       == 0) return (TERM_DARK)
    3459         if (my_stricmp(name, "white")      == 0) return (TERM_WHITE)
    3460         if (my_stricmp(name, "slate")      == 0) return (TERM_SLATE)
    3461         if (my_stricmp(name, "orange")     == 0) return (TERM_ORANGE)
    3462         if (my_stricmp(name, "red")        == 0) return (TERM_RED)
    3463         if (my_stricmp(name, "green")      == 0) return (TERM_GREEN)
    3464         if (my_stricmp(name, "blue")       == 0) return (TERM_BLUE)
    3465         if (my_stricmp(name, "umber")      == 0) return (TERM_UMBER)
    3466         if (my_stricmp(name, "violet")     == 0) return (TERM_VIOLET)
    3467         if (my_stricmp(name, "yellow")     == 0) return (TERM_YELLOW)
    3468         if (my_stricmp(name, "lightdark")  == 0) return (TERM_L_DARK)
    3469         if (my_stricmp(name, "lightwhite") == 0) return (TERM_L_WHITE)
    3470         if (my_stricmp(name, "lightred")   == 0) return (TERM_L_RED)
    3471         if (my_stricmp(name, "lightgreen") == 0) return (TERM_L_GREEN)
    3472         if (my_stricmp(name, "lightblue")  == 0) return (TERM_L_BLUE)
    3473         if (my_stricmp(name, "lightumber") == 0) return (TERM_L_UMBER)
     3263        if (my_stricmp(name, "dark")       == 0) return TERM_DARK
     3264        if (my_stricmp(name, "white")      == 0) return TERM_WHITE
     3265        if (my_stricmp(name, "slate")      == 0) return TERM_SLATE
     3266        if (my_stricmp(name, "orange")     == 0) return TERM_ORANGE
     3267        if (my_stricmp(name, "red")        == 0) return TERM_RED
     3268        if (my_stricmp(name, "green")      == 0) return TERM_GREEN
     3269        if (my_stricmp(name, "blue")       == 0) return TERM_BLUE
     3270        if (my_stricmp(name, "umber")      == 0) return TERM_UMBER
     3271        if (my_stricmp(name, "violet")     == 0) return TERM_VIOLET
     3272        if (my_stricmp(name, "yellow")     == 0) return TERM_YELLOW
     3273        if (my_stricmp(name, "lightdark")  == 0) return TERM_L_DARK
     3274        if (my_stricmp(name, "lightwhite") == 0) return TERM_L_WHITE
     3275        if (my_stricmp(name, "lightred")   == 0) return TERM_L_RED
     3276        if (my_stricmp(name, "lightgreen") == 0) return TERM_L_GREEN
     3277        if (my_stricmp(name, "lightblue")  == 0) return TERM_L_BLUE
     3278        if (my_stricmp(name, "lightumber") == 0) return TERM_L_UMBER
    34743279 
    34753280        /* Oops */ 
    3476         return (-1)
     3281        return -1
    34773282} 
    34783283 
     
    34853290        switch (a) 
    34863291        { 
    3487                 case TERM_DARK:    return ("Dark")
    3488                 case TERM_WHITE:   return ("White")
    3489                 case TERM_SLATE:   return ("Slate")
    3490                 case TERM_ORANGE:  return ("Orange")
    3491                 case TERM_RED:     return ("Red")
    3492                 case TERM_GREEN:   return ("Green")
    3493                 case TERM_BLUE:    return ("Blue")
    3494                 case TERM_UMBER:   return ("Umber")
    3495                 case TERM_L_DARK:  return ("L.Dark")
    3496                 case TERM_L_WHITE: return ("L.Slate")
    3497                 case TERM_VIOLET:  return ("Violet")
    3498                 case TERM_YELLOW:  return ("Yellow")
    3499                 case TERM_L_RED:   return ("L.Red")
    3500                 case TERM_L_GREEN: return ("L.Green")
    3501                 case TERM_L_BLUE:  return ("L.Blue")
    3502                 case TERM_L_UMBER: return ("L.Umber")
     3292                case TERM_DARK:    return "Dark"
     3293                case TERM_WHITE:   return "White"
     3294                case TERM_SLATE:   return "Slate"
     3295                case TERM_ORANGE:  return "Orange"
     3296                case TERM_RED:     return "Red"
     3297                case TERM_GREEN:   return "Green"
     3298                case TERM_BLUE:    return "Blue"
     3299                case TERM_UMBER:   return "Umber"
     3300                case TERM_L_DARK:  return "L.Dark"
     3301                case TERM_L_WHITE: return "L.Slate"
     3302                case TERM_VIOLET:  return "Violet"
     3303                case TERM_YELLOW:  return "Yellow"
     3304                case TERM_L_RED:   return "L.Red"
     3305                case TERM_L_GREEN: return "L.Green"
     3306                case TERM_L_BLUE:  return "L.Blue"
     3307                case TERM_L_UMBER: return "L.Umber"
    35033308        } 
    35043309 
    35053310        /* Oops */ 
    3506         return ("Icky")
     3311        return "Icky"
    35073312} 
    35083313 
     
    35583363        if (repeat__idx) 
    35593364                repeat__cnt = --repeat__idx; 
     3365 
    35603366        /* Paranoia */ 
    35613367        else 
     
    36103416 
    36113417#ifdef SUPPORT_GAMMA 
     3418 
     3419/* 
     3420 * XXX XXX XXX Important note about "colors" XXX XXX XXX 
     3421 * 
     3422 * The "TERM_*" color definitions list the "composition" of each 
     3423 * "Angband color" in terms of "quarters" of each of the three color 
     3424 * components (Red, Green, Blue), for example, TERM_UMBER is defined 
     3425 * as 2/4 Red, 1/4 Green, 0/4 Blue. 
     3426 * 
     3427 * The following info is from "Torbjorn Lindgren" (see "main-xaw.c"). 
     3428 * 
     3429 * These values are NOT gamma-corrected.  On most machines (with the 
     3430 * Macintosh being an important exception), you must "gamma-correct" 
     3431 * the given values, that is, "correct for the intrinsic non-linearity 
     3432 * of the phosphor", by converting the given intensity levels based 
     3433 * on the "gamma" of the target screen, which is usually 1.7 (or 1.5). 
     3434 * 
     3435 * The actual formula for conversion is unknown to me at this time, 
     3436 * but you can use the table below for the most common gamma values. 
     3437 * 
     3438 * So, on most machines, simply convert the values based on the "gamma" 
     3439 * of the target screen, which is usually in the range 1.5 to 1.7, and 
     3440 * usually is closest to 1.7.  The converted value for each of the five 
     3441 * different "quarter" values is given below: 
     3442 * 
     3443 *  Given     Gamma 1.0       Gamma 1.5       Gamma 1.7     Hex 1.7 
     3444 *  -----       ----            ----            ----          --- 
     3445 *   0/4        0.00            0.00            0.00          #00 
     3446 *   1/4        0.25            0.27            0.28          #47 
     3447 *   2/4        0.50            0.55            0.56          #8f 
     3448 *   3/4        0.75            0.82            0.84          #d7 
     3449 *   4/4        1.00            1.00            1.00          #ff 
     3450 */ 
    36123451 
    36133452/* Table of gamma values */ 
  • trunk/src/z-rand.c

    r1 r461  
    346346        return (result); 
    347347} 
     348 
     349 
     350 
     351/* 
     352 * Generates damage for "2d6" style dice rolls 
     353 */ 
     354int damroll(int num, int sides) 
     355{ 
     356        int i; 
     357        int sum = 0; 
     358 
     359        if (sides <= 0) return (0); 
     360 
     361        for (i = 0; i < num; i++) 
     362                sum += rand_die(sides); 
     363 
     364        return (sum); 
     365}&nbs