Character Creation Help

Posted by Palatis on Tue 22 Aug 2006 06:21 PM — 11 posts, 34,135 views.

#0
Well, i'm trying to change the way a character is created. Main thing right now is trying to add color. In some area's color works. But other areas color just doesn't seem to work. Here's one area where it doesn't work:


if( d->newstate == 0 )
{

/* No such player */
send_to_desc_color( "\n\r&RNo such player exists. Please check your spelling.\n\r", d );
send_to_desc_color( "\n\r&WEnter your character's name, or type new:", d );
d->connected = CON_GET_NAME;
d->character->desc = NULL;
free_char( d->character ); /* Big Memory Leak before --Shaddai */
d->character = NULL;
return;
}
sprintf( buf, "\n\r&zDid I get that right&R %s, &z(&RYes&z/&RNo&z) ? ", argument );
send_to_desc_color( buf, d);
d->connected = CON_CONFIRM_NEW_NAME;
return;
}
break;


I've changed sprintf to send_to_desc_color, and it still doesn't work. I'm not too sure. Altho, color does work in other functions like:

send_to_desc_color( "\n\r&zChoosing a name is one of the most important parts of this game..."
"\n\rMake sure to pick a name appropriate to the character you are going"
"\n\rto role play, and be sure that it suits a &RWARCRAFT Theme&z. If the name"
"\n\ryou select is not acceptable, you will be asked to choose another one."
"\n\r\n\rPlease choose a &RName&z for your character&W:&w\n\r", d);

There is also alot of areas including -- The game is wizlocked -- where color does not work also.

I'm using SMAUGFUSS 1.7.
USA #1
Chances are that the descriptor is not being given the ANSI color flag until either the player is successfully loaded, or when a new character is created. Look for where the ANSI flag is set, and then just do the same as soon as a new connection is made.

(Of course, this might be dangerous, because if somebody connects without ANSI color support, they'll get all kinds of junk in their output. Then again, there are probably very, very few clients without ANSI color support, so maybe this isn't really something to worry about.)
#2
Well>< I mean I said it works in other parts of the code, just not when it asks

Did I get that right, XXX, (Y|N)

Still -- How would i go about doing this?
USA #3
The functions that send data over the connection strip out color codes unless the descriptor structure has the ANSI color flag set. I don't have the code handy so I can't say exactly where that normally is; but, you can look through mud.h for the flag, and then search the .c files for it (using e.g. grep). Then, if you want to force color on all the time, find the place where a descriptor is created, and set the flag there.

Sorry that I can't be more specific at the moment, as I said I don't currently have the code handy.
#4
Erm>< Do you know what would be the flag -- sort of new :P
USA #5
In mud.h you will find flags for the descriptors; one of them will probably have ANSI in it. If you do a text search for ANSI you will probably find the flag. If I remember correctly, it will be near a flag with 'RIP' in the name. Again, sorry for not being more specific, since I don't have the source code at hand.
USA #6
Or you could just force hard coded ANSI colors.
Australia Forum Administrator #7
You need to edit save.c around line 663 in stock SMAUGfuss, inside the function load_char_obj, which is used to create a new character structure.

A little way down it sets default flags for the newly-created character, you need to add PLR_ANSI to the list, in other words, change:


   ch->act = multimeb( PLR_BLANK, PLR_COMBINE, PLR_PROMPT, -1 );


to:


   ch->act = multimeb( PLR_BLANK, PLR_COMBINE, PLR_PROMPT, PLR_ANSI, -1 );
Amended on Tue 22 Aug 2006 10:21 PM by Nick Gammon
Australia Forum Administrator #8
Also, in comm.c, function nanny (around line 2284) you need to change the sense of the changes if they say the don't want ANSI, as you have already set the bit by default. I would make it like this:



      case CON_GET_WANT_RIPANSI:
         switch ( argument[0] )
         {
            case 'r':
            case 'R':
               xSET_BIT( ch->act, PLR_RIP );
               xSET_BIT( ch->act, PLR_ANSI );
               break;
            case 'a':
            case 'A':
               xSET_BIT( ch->act, PLR_ANSI );
               break;
            case 'n':
            case 'N':
                xREMOVE_BIT(ch->act, PLR_ANSI);
               break;
            default:
               write_to_buffer( d, "Invalid selection.\r\nRIP, ANSI or NONE? ", 0 );
               return;
         }


New line in bold.
Australia Forum Administrator #9
I used gdb to work this out, see my post on this:

http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=3653

I put a breakpoint on the send_to_desc_color function, then colorize, then colorcode, which is the actual function which works out whether to do the colour coding or not.

There is a series of tests in colorcode to work out whether to show the ANSI codes, I was interested to see which one failed.
#10
Thanks everyone for trying to help -- Big thanks to you nick:P It works now.

<333 :P