Title and Colors

Posted by Toy on Sat 05 Jun 2004 05:56 PM — 18 posts, 66,881 views.

#0
I noticed something today. I know smaug has rough issues with color, and do_title is no exception.

void do_title( CHAR_DATA *ch, char *argument )
{
    	if ( IS_NPC(ch) )
		return;
	
    	set_char_color( AT_SCORE, ch );
    	if ( ch->level < 30 )
    	{
		send_to_char( "Sorry... you must be at least level 30 to set your title...\n\r", ch );
		return;
    	}
    
    	if ( IS_SET( ch->pcdata->flags, PCFLAG_NOTITLE ))
    	{
		set_char_color( AT_IMMORT, ch );
        	send_to_char( "The Gods prohibit you from changing your title.\n\r", ch );
        	return;
    	}
	
    	if ( argument[0] == '\0' )
    	{
		send_to_char( "Change your title to what?\n\r", ch );
		return;
    	}
	
    	if ( strlen(argument) > 50 )
		argument[50] = '\0';
	
    	smash_tilde( argument );
    	set_title( ch, argument );
    	send_to_char( "Ok.\n\r", ch );
}


When in the mud i tried this:
title &rTest

And it came out like this:
Head Admin Lord ToyTest.

The word 'Test' in red like it should be, but it removes the space between the name and the title. I can't seem to figure out how to fix that. Anyone know how or what i'm not seeing?

-Toy
Amended on Sat 05 Jun 2004 05:57 PM by Toy
USA #1
Uh, you could do title &r Test I think :)
USA #2
That's a feature, actually. It's removing the space so that you can have titles like "Fred, the Adventurer". I believe that the rule it follows is that if the first character is not a letter, it removes the space.

Whiteknight's solution should work fine.
USA #3
One of the MUDs I admin on has that fixed. But I assume it justs adds an extra space, in the code. I could look it up.
#4
Please, if you could. Not horribly important, I just like having all the little details fixed. :)

-Toy
USA #5
No difference in do_title except strlen(argument) > 47

Maybe set_title.

void set_title( CHAR_DATA *ch, char *title )
{
    char buf[MAX_STRING_LENGTH];

    if ( IS_NPC(ch) )
    {
        bug( "Set_title: NPC.", 0 );
        return;
    }

    if ( isalpha(title[0]) || isdigit(title[0]) )
    {
        buf[0] = ' ';
        strcpy( buf+1, title );
    }
    else if ( title[0] == '&' )
    {
        buf[0] = ' ';
        strcpy( buf+1, title );
    }
    else
        strcpy( buf, title );

    STRFREE( ch->pcdata->title );
    ch->pcdata->title = STRALLOC( buf );
    return;
}


Any difference?
#6
Yup, that works. Thanks. :)

-Toy
#7
OK, well, it sorta works. When you make a title in the game, everything works fine. Save, and quit. Come back in and the space between your name and title are gone. Thinking it's a issue with fread_char not supporting color in your title. I'll post again if I find out if that's right or not.

-Toy

-edit-

OK, I think I found where the problem is, just not sure how to rectify it.
in save.c under fread_char
	    			if ( !strcmp( word, "Title" ) )
	    			{
					ch->pcdata->title = fread_string( fp );
		
					if ( isalpha(ch->pcdata->title[0])
					||   isdigit(ch->pcdata->title[0]) )
					{
		    				sprintf( buf, " %s", ch->pcdata->title );
		    
		    				if ( ch->pcdata->title )
		      					STRFREE( ch->pcdata->title );
		    					ch->pcdata->title = STRALLOC( buf );
					}

					fMatch = TRUE;
					break;
	    			}
				break; 


Pretty sure the problem lies in the code.

-Toy
Amended on Sun 06 Jun 2004 09:57 PM by Toy
USA #8
If I'm not mistaken the read functions skip over all whitespace in the beginning.

I still think it would be much easier if you just did what Whiteknight suggested. :) That will work and chances are that you're going to break something here if you mess with it too much. :P
Canada #9
Didn't realise that the smaug and the SWR method was different, but here might be another option for titles: Have it display the title but not their name, and leave it up to them to put their name in the title. It allows a little more flexabilty, as they can have "Greven the Geek" or "President Greven of Geeks". Just a thought. The code is in player.c in the swrfuss packages available through Nicks download area should anyone be interested.
USA #10
look for do_who function.

there's a place for the title, put a space in between the name %s and the title %s, that worked for me. i don't have my code with me right now so i can't show you, but it's there. it's like this:

%s %s%s%s%s%s

name, title, clan, blah blah blah...

Ithildin *space* the newbie coder

USA #11
Ah, yes, but then you can't use comma-titles anymore, so no good. e.g. no more: Ksilyan, the coder who likes commas. :)

The "right" way to do this is to figure out if the title starts with punctuation in which case you remove the space, and if it starts with a letter or the color you add the space, but if it starts with color and punctuation you remove the space, etc.

Or, you take the easy way out and just add spaces in titles manually. :)
USA #12
Yes yes, you can do that. but I took out titles for my players. i don't see the sense in having them for players. just an accident waiting to happen. plus they need to RP their characters so that others will know what their "title" should be. but that's my logic. so only my IMM's have titles. and the titles go like this:

[Supreme Entity ] Ithildin - The newbie coder

all i did was "title '- The newbie coder'"

but that's just me. and that's the easy way around it ;)


hence the name right now newbie coder heh
USA #13
On our MUD the players have to petition the staff for titles, and we check that they have a good bio that matches their title. That way, the "accident waiting to happen" problem is solved. :)

Easy ways around things aren't good when they take away features that used to be there. :-)
#14
Ok, so I've got the titles saving properly, and it shows great on the do_who screen.

Head Admin Lord Toy the Dark Puppet

So, after checking some more things out, I realized that there was another problem with spacing.

(Immortal) Lord Toythe Dark Puppet is here before you.

I've tracked the issue down to show_char_to_char section of act_info.c. Still working on fixing it, but not having much luck atm.

-Toy

PS. Spacing + Smaug colors = Pain in the ass. :)

USA #15
That's because you did it wrong! :P You shouldn't be adding a space to the display but to the title. Otherwise you're just asking for trouble.
USA #16
what is the trouble in doing the spacing? what can happen? i'm curious now..heh, i'll have to avoid it.
USA #17
If you add a space in the display, then you have to go edit every single place where you print the title - and everybody who subsequently uses your codebase has to be aware of this "quirk".

On the other hand, if the title itself contains the space, then life is good and the birds are singing - you no longer have to change anything whatsoever.

Basically to change the display is a mistake in program design, simply in that the space should be proper to the title and not the display. By fixing the display, you are fixing the symptom but not the disease, and this is rather self-obviously not the right way to go about doing things. :)