Changeset 1433 for trunk

Show
Ignore:
Timestamp:
06/08/09 19:19:42 (15 months ago)
Author:
magnate
Message:

Dynastic character numbering support - closes #63

Location:
trunk/src
Files:
8 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/birth.c

    r1422 r1433  
    10061006        int points_spent[A_MAX]; 
    10071007        int points_left; 
     1008        char *buf; 
    10081009 
    10091010        bool rolled_stats = FALSE; 
     
    10391040        reset_stats(stats, points_spent, &points_left); 
    10401041        do_birth_reset(quickstart_allowed, &quickstart_prev); 
     1042 
     1043        /* Handle incrementing name suffix */ 
     1044        if (op_ptr->name_suffix) 
     1045        { 
     1046                ++op_ptr->name_suffix; 
     1047                buf = find_roman_suffix_start(op_ptr->full_name); 
     1048                if (buf) 
     1049                { 
     1050                        romanify(op_ptr->name_suffix, buf, 
     1051                                 sizeof(op_ptr->full_name) - (buf - (char *)&op_ptr->full_name)); 
     1052                } 
     1053        } 
    10411054 
    10421055        /* We're ready to start the interactive birth process. */ 
  • trunk/src/externs.h

    r1431 r1433  
    586586extern void text_to_ascii(char *buf, size_t len, cptr str); 
    587587extern void ascii_to_text(char *buf, size_t len, cptr str); 
     588extern void romanify(int in, char *buf, size_t len); 
     589extern char *find_roman_suffix_start(cptr buf); 
    588590extern int macro_find_exact(cptr pat); 
    589591extern errr macro_add(cptr pat, cptr act); 
  • trunk/src/files.c

    r1417 r1433  
    16141614 * when a new character is created, and then when the character is done 
    16151615 * being created, they call this function to choose a new savefile name. 
     1616 * 
     1617 * This also now handles the turning on and off of the automatic 
     1618 * sequential numbering of character names with Roman numerals.   
    16161619 */ 
    16171620void process_player_name(bool sf) 
     
    16191622        int i; 
    16201623 
     1624        /* If the selected name ends in " I", i.e. "the first", then we're using 
     1625         * Roman numerals style suffices, so set the savefile flag. 
     1626         * Equally if there's no roman numerals at all, switch off suffices.*/ 
     1627        char *buf = find_roman_suffix_start(op_ptr->full_name); 
     1628        if (!buf) 
     1629        { 
     1630                op_ptr->name_suffix = 0; 
     1631        } 
     1632        else 
     1633        { 
     1634                if (buf[0] == 'I' && buf[1] == '\0') 
     1635                { 
     1636                        op_ptr->name_suffix = 1; 
     1637                }  
     1638        } 
    16211639 
    16221640        /* Process the player name */ 
  • trunk/src/load-old.c

    r1377 r1433  
    782782        sp_ptr = &sex_info[p_ptr->psex]; 
    783783 
    784         strip_bytes(1); 
     784        /* Numeric name suffix */ 
     785        rd_byte(&op_ptr->name_suffix); 
    785786 
    786787        /* Special Race/Class info */ 
  • trunk/src/load.c

    r1377 r1433  
    664664        sp_ptr = &sex_info[p_ptr->psex]; 
    665665 
    666         strip_bytes(1); 
     666        /* Numeric name suffix */ 
     667        rd_byte(&op_ptr->name_suffix); 
    667668 
    668669        /* Special Race/Class info */ 
  • trunk/src/player/types.h

    r1405 r1433  
    400400         
    401401        byte delay_factor;              /* Delay factor (0 to 9) */ 
     402         
     403        byte name_suffix;               /* numeric suffix for player name */ 
    402404} player_other; 
    403405 
  • trunk/src/save.c

    r1346 r1433  
    326326        wr_byte(p_ptr->pclass); 
    327327        wr_byte(p_ptr->psex); 
    328         wr_byte(0);     /* oops */ 
     328        wr_byte(op_ptr->name_suffix); 
    329329         
    330330        wr_byte(p_ptr->hitdie); 
  • trunk/src/util.c

    r1376 r1433  
    469469} 
    470470 
    471  
     471static char *roman_order[] = {"", "a", "aa", "aaa", "ab", "b", "ba", "baa", "baaa", "ac"}; 
     472 
     473/* 
     474 * Fill in buf (up to size len) with the roman digits corresponding to the 
     475 * input digit, based on the radix string specified. This will be the 
     476 * characters of the current decimal position, e.g. IVX for digits, XLC for 
     477 * tens, CDM for hundreds. 
     478 *  
     479 * Returns number of chars put in the string. 
     480 */ 
     481static size_t roman_digits(char *buf, size_t len, int digit, char *radix) 
     482{ 
     483        char *template = roman_order[digit]; 
     484        size_t radix_len = strlen(radix); 
     485        size_t added = 0; 
     486         
     487        while (*template && len) { 
     488                int offset = *template - 'a'; 
     489                if (offset < radix_len) 
     490                { 
     491                        *buf = radix[offset]; 
     492                } 
     493                else 
     494                { 
     495                        *buf = '?'; 
     496                } 
     497                ++buf; 
     498                ++template; 
     499                ++added; 
     500                --len; 
     501        } 
     502        return added; 
     503} 
     504 
     505/* 
     506 * Convert a number into a string in roman numerals 
     507 * Ignores any value over a thousand, on the grounds that it's hard to  
     508 * print characters with bars on top in ASCII... 
     509 */ 
     510void romanify(int in, char *buf, size_t len) 
     511{ 
     512        int hundreds = (in / 100) % 10; 
     513        int tens = (in / 10) % 10; 
     514        int ones = in % 10; 
     515        size_t ret; 
     516         
     517        if (hundreds) 
     518        { 
     519                ret = roman_digits(buf, len, hundreds, "CDM"); 
     520                buf += ret; 
     521                len -= ret; 
     522        } 
     523        if (tens) 
     524        { 
     525                ret = roman_digits(buf, len, tens, "XLC"); 
     526                buf += ret; 
     527                len -= ret; 
     528        } 
     529        if (ones) 
     530        { 
     531                ret = roman_digits(buf, len, ones, "IVX"); 
     532                buf += ret; 
     533                len -= ret; 
     534        } 
     535        if (len) 
     536        { 
     537                *buf = '\0'; 
     538        } 
     539} 
     540 
     541/* 
     542 * Find the start of a possible Roman numerals suffix by going back from the 
     543 * end of the string to a space, then checking that all the remaining chars 
     544 * are valid Roman numerals. 
     545 *  
     546 * Return the start position, or NULL if there isn't a valid suffix.  
     547 */ 
     548char *find_roman_suffix_start(cptr buf) 
     549{ 
     550        const char *start = strrchr(buf, ' '); 
     551        const char *p; 
     552         
     553        if (start) 
     554        { 
     555                start++; 
     556                p = start; 
     557                while (*p) 
     558                { 
     559                        if (*p != 'I' && *p != 'V' && *p != 'X' && *p != 'L' && 
     560                            *p != 'C' && *p != 'D' && *p != 'M') 
     561                        { 
     562                                start = NULL; 
     563                                break; 
     564                        } 
     565                        ++p;                         
     566                } 
     567        } 
     568        return (char *)start; 
     569} 
    472570 
    473571/*