03 Nov, 2007, Kayle wrote in the 1st comment:
Votes: 0
Maybe it's because I've not been able to sleep tonight, but I can't get this to work at all.

I'm trying to expand character creation and add in an option to customize your appearance. So with that comes the ability to pick your height within the limits assigned to the class. So I've come to the conclusion, that the players should be able to input their height the easiest way for them, currently the code will do the following to spit out the limits so they can read them:
case 'y': 
case 'Y':
if( ch->sex == SEX_MALE )
{
feet = ( ( int )( race_table[ch->race]->maleheight * .888 ) ) / 12;
inches = ( ( int )( race_table[ch->race]->maleheight * .888 ) ) % 12;
feet2 = ( ( int )( race_table[ch->race]->maleheight * 1.15 ) ) / 12;
inches2 = ( ( int )( race_table[ch->race]->maleheight * 1.15 ) ) % 12;

snprintf( buf, MSL, "Please choose a height between %d (%d'%d\") and %d (%d'%d\").\r\n: &D",
( int )( race_table[ch->race]->maleheight * .888 ), feet, inches, ( int )( race_table[ch->race]->maleheight * 1.15 ), feet2, inches2 );
}
if( ch->sex == SEX_FEMALE )
{
feet = ( ( int )( race_table[ch->race]->femaleheight * .888 ) ) / 12;
inches = ( ( int )( race_table[ch->race]->femaleheight * .888 ) ) % 12;
feet2 = ( ( int )( race_table[ch->race]->femaleheight * 1.15 ) ) / 12;
inches2 = ( ( int )( race_table[ch->race]->femaleheight * 1.15 ) ) % 12;

snprintf( buf, MSL, "Please choose a height between %d (%d'%d\") and %d (%d'%d\").\r\n: &D",
( int )( race_table[ch->race]->femaleheight * .888 ), feet, inches, ( int )( race_table[ch->race]->femaleheight * 1.15 ), feet2, inches2 );
}
send_to_desc_color( buf, d );
d->connected = CON_GET_HEIGHT;
break;


Kiasyn tried to explain this to me on Ichat, but I think a combination of lack of sleep and attempting to understand RegExp caused me to be utterly unable to do anything. I need the following code to be able to read both straight inches and X'X" format. For instance, a player could use 78 or 6'6" to select their height.

Currently in my stupor, I've only managed to pull off:
void nanny_get_height( DESCRIPTOR_DATA * d, char *argument )
{
CHAR_DATA *ch;
char buf[MSL];
int feet, inches;

ch = d->character;
if( is_number( argument )
{
if( ch->sex == SEX_MALE )
{
if( argument >= ( int )( race_table[ch->race]->maleheight * .888 ) && argument <= ( int )( race_table[ch->race]->maleheight * 1.15 ) )
ch->height = argument;
}
if( ch->sex == SEX_FEMALE )
{
if( argument >= ( int )( race_table[ch->race]->femaleheight * .888 ) && argument <= ( int )( race_table[ch->race]->femaleheight * 1.15 ) )
ch->height = argument;
}
}
else


}


Granted, this is probably wrong as well, needless to say I probably shouldn't be coding in my current state, but I can't sleep and coding normally calms me down. I will need to be able to convert any x'x" formats to inches as well. And.. Hmm.. This is a SmaugFUSS 1.8 base.. and Um.. I should probably go sleep. Any help is appreciated, Um.. Thanks in advance.. and.. I sound like a total retard right now. So I'm going to shut up now. :)
03 Nov, 2007, Davion wrote in the 2nd comment:
Votes: 0
What about using sscanf?

sscanf(argument, "%d'%d", &feet, &inches );


If sscanf fails to find the pattern it'll leave the value of feet or inches, so set them to -1 or something and if any come out of the sscanf as -1 bad format.
03 Nov, 2007, Kayle wrote in the 3rd comment:
Votes: 0
I had thought about that but Kiasyn had said that it wouldn't work. I'm not sure why, though, he didn't elaborate.
03 Nov, 2007, Kayle wrote in the 4th comment:
Votes: 0
So I threw this together, hoping maybe it would work, and it's actually acting like it might, except I keep getting a couple of compiler errors, that I can't quite figure out, partially becuase I think I might have really screwed myself up not sleeping for at least 5 hours.

void nanny_get_height( DESCRIPTOR_DATA * d, char *argument )
{
CHAR_DATA *ch;
//char buf[MSL];
int rfeet, feet = -1, rinches, inches = -1, height;

ch = d->character;
if( sscanf( argument, "%d'%d\"", &rfeet, &rinches ) )
{
feet = &rfeet;
inches = &rinches;
if( feet != -1 && inches != -1 )
{
height = ( feet * 12 ) + inches;
if( ch->sex == SEX_MALE )
{
if( height >= ( int )( race_table[ch->race]->maleheight * .888 ) && height <= ( int )( race_table[ch->race]->maleheight * 1.15 ) )
ch->height = height;
}
if( ch->sex == SEX_FEMALE )
{
if( height >= ( int )( race_table[ch->race]->femaleheight * .888 ) && height <= ( int )( race_table[ch->race]->femaleheight * 1.15 ) )
ch->height = height;
}
}
else
{
height = atoi( argument );
if( ch->sex == SEX_MALE )
{
if( height >= ( int )( race_table[ch->race]->maleheight * .888 ) && height <= ( int )( race_table[ch->race]->maleheight * 1.15 ) )
ch->height = height;
}
if( ch->sex == SEX_FEMALE )
{
if( height >= ( int )( race_table[ch->race]->femaleheight * .888 ) && height <= ( int )( race_table[ch->race]->femaleheight * 1.15 ) )
ch->height = height;
}
}
}
}


Compiler Errors. -CYGWIN, btw.
[Kayle@Malevolum ~/coding/src]$ make
make -s smaug
Compiling o/comm.o….
comm.c: In function `void nanny_get_height(DESCRIPTOR_DATA*, char*)':
comm.c:2544: error: invalid conversion from `int*' to `int'
comm.c:2545: error: invalid conversion from `int*' to `int'
make[1]: *** [o/comm.o] Error 1
make: *** [all] Error 2
[Kayle@Malevolum ~/coding/src]$
03 Nov, 2007, Davion wrote in the 5th comment:
Votes: 0
feet = &rfeet;
inches = &rinches;


That sets feet to the address of rfeet. You want

feet = rfeet;
inches = rinches


Also, sscanf returns the number of input items successfully matched and assigned, so if it's just 1, it still might not be valid. In this case, you probably want 2.
03 Nov, 2007, Kayle wrote in the 6th comment:
Votes: 0
Davion said:
Also, sscanf returns the number of input items successfully matched and assigned, so if it's just 1, it still might not be valid. In this case, you probably want 2.


Sorry, brain seems to fail at functioning today for whatever reason, but I didn't completely understand that.
03 Nov, 2007, Davion wrote in the 7th comment:
Votes: 0
if( sscanf( argument, "%d'%d\"", &rfeet, &rinches ) )


If rfeet and rinches are matched and assigned, sscanf will return 2. If only one is matched and assigned it'll return 1, and of course, 0 for no matches.

So

if(sscanf(argument, "%d'%d\"", &rfeet, &rinches ) == 2 )
will mean both rfeet and rinches were assigned values and that it is indeed entered correctly.
03 Nov, 2007, Kayle wrote in the 8th comment:
Votes: 0
Ah, Ok, that makes sense.
03 Nov, 2007, Kayle wrote in the 9th comment:
Votes: 0
So now I've come across another small problem.

Venia has all the races all figured out, and six of them are in the planetouched category, which means one of their parents was an extraplanar being. So.. they each get to pick one type of planar feature from their heritage. Now most of these features will replace one that they picked earlier in creation. So I need to figure out the best way to figure out which feature they ended up with, and how to display it to them. So right now, I have a function that generates a generic description based on what options they've picked/been assigned. So far it looks like:

const char *show_appearance( CHAR_DATA * ch )
{
static char buf[MSL];
int feet, inches;

feet = ch->height / 12;
inches = ch->height % 12;

if( ch->race == RACE_LIZARDFOLK )
{
snprintf( buf, MSL, "Your %s eyes stand out ferociously against your %s scales.\r\n"
"You stand %d'%d\" tall and weight %d pounds, and your %s build\r\n"
"makes you a worthy adversary for any warm-blood that challenges\r\n"
"you.\r\n", get_eye_color( ch, ch->eyecolor ), scale_color[ch->scalecolor], feet, inches,
ch->weight, build_name[ch->build] );
}
else if( ch->race == RACE_LUPINAL )
{
snprintf( buf, MSL, "", ? );
}
else if( ch->race == RACE_FELINID )
{
snprintf( buf, MSL, "", ? );
}
else if( ch->race == RACE_HALFDEMON || ch->race == RACE_HALFCELESTIAL || ch->race == RACE_IGNAN
|| ch->race == RACE_TERRAN || ch->race == RACE_BOREAN || ch->race == HALF_AQUAN )
{
snprintf( buf, MSL, "", ? );
}
else
{
snprintf( buf, MSL, "", ? );
}

return buf;
}


But I need a way to be able to replace certain features in the description for the Planetouched, and I'm not sure about the best way to go about it. Any ideas?

Sorry there's no example for the Planetouched, but I haven't gotten that far, as you could probably tell. But as I started on the Lupinals, I realized they were going to present a problem and decided to go ahead and ask while I worked on the rest.
04 Nov, 2007, David Haley wrote in the 10th comment:
Votes: 0
I don't really understand what you are trying to do, so this is a little bit of guesswork. Can't you just track the features they selected, and then when you want to display the features, iterate over their list of current features and display all that appear there that weren't in the original list?
04 Nov, 2007, Kayle wrote in the 11th comment:
Votes: 0
Alright, let me elaborate a bit, and then we'll see how well your suggest fits. Let's say.. A Player starts a new character and chooses Half-Demon as a race, Half-Demon is a planetouched and gets to pick a planar feature. So, They go through and they pick height, weight, eye color (we'll say they pick blue), skin tone, hair color, hair length, hair style, and then they pick a planar feature (we'll say they pick the glowing red eyes). So this particular character has already picked their eye color, but they chose to go with the glowing red eyes planar feature, because the red eyes are a planar feature it supersedes the chosen eye color, so instead of getting something like: "Your blue eyes contrast beautifully with your light skin tone." They would get something like: "You light skin tone is immediately belied by your glowing red eyes." or something to that effect.

I guess the easiest way to do this would be with if checks against their chosen options, and then write a separate description based on each one, but I was really hoping for something a little less line consuming.
04 Nov, 2007, David Haley wrote in the 12th comment:
Votes: 0
If that's the kind of feature you're talking about, why can't you just have that feature choice change the eye color setting from "blue" to "glowing red", and then when you print it out, you just look up their eye color in a table – and by that point, the code has (correctly) "forgotten" that they picked blue?

But yes, if you want to create separate descriptions for every combination of skin tone/eye color/etc. you'll just have to go ahead and do all that; there's no magic wand here. You could stick the descriptions into an array of some kind, where the first dimension is the skin tone, the second dimension is the eye color, and so forth, and then you don't have to write any if statements, but you'll still have to write all the descriptions.
04 Nov, 2007, Kayle wrote in the 13th comment:
Votes: 0
I think what I might end up doing is use inline checks. something like:

snprintf( buf, MSL, "Your %s eyes gaze mischievously about, and your %s are the envy of the rest\r\n"
"of the pride. Your %s %s hair is worn %s%s. You stand at %d'%d\" and weigh\r\n"
"%d pounds, with a %s build. You are ready for anything.\r\n",
get_eye_color( ch, ch->eyecolor ), felinid_fur_color[ch->furcolor], hair_length[ch->hlength],
get_hair_color( ch, ch->hcolor ), ch->hstyle == 9 ? "as " : ch->hstyle == 10 ?
"with long bangs framed around your face" : "", ch->hstyle == 10 ? "" : hair_style[ch->hstyle],
feet, inches, ch->weight, build_name[ch->build] );


the above his how I did the felinid description which are I wanna say cat people. But I think I can do something similar to that for each of the planetouched, so I might take that route.
04 Nov, 2007, David Haley wrote in the 14th comment:
Votes: 0
That works too. It's probably better to try to stick with more general description templates like what you just posted; it will greatly reduce your workload in any case. If you want to non-trivially change the description based on feature combinations, you'll have a whole lot more work ahead of you…
04 Nov, 2007, Kayle wrote in the 15th comment:
Votes: 0
Yeah, I guess it's a good thing this will never see the light of day then, because when its finished it's probably going to be the most hard to read and hard to follow chunk of code I've ever written. :tongue: :lol:
06 Nov, 2007, Kayle wrote in the 16th comment:
Votes: 0
New problem cropped up once everything was done and written. Well… See for yourself…

Quote
Your blue eyes twinkle with a need for adventure, and contrast with your
blue skin. Your blue blue hair is worn blue. You stand at 6'5" and weigh
160 pounds, with a blue build. Your blue is neatly trimmed.

Do you wish to customize your appearance (Y/N)?


Here's the code in question:
char *show_appearance( CHAR_DATA * ch )
{
static char buf[MSL];
int feet, inches;

feet = ch->height / 12;
inches = ch->height % 12;

(…)
else
{
if( ch->race == RACE_GOLDDWARF || ch->race == RACE_SHIELDDWARF || ( ch->race == RACE_HUMAN && ch->sex == SEX_MALE )
|| ( ch->race == RACE_HALFELF && ch->sex == SEX_MALE ) || ( ch->race == RACE_HALFORC && ch->sex == SEX_MALE )
|| ( ch->race == RACE_HALFOGRE && ch->sex == SEX_MALE ) || ( ch->race == RACE_ROCKGNOME && ch->sex == SEX_MALE )
|| ( ch->race == RACE_DUERGAR && ch->sex == SEX_MALE ) )
{
snprintf( buf, MSL, "&wYour &W%s&w eyes twinkle with a need for adventure, and contrast with your\r\n"
"&W%s&w skin. Your &W%s %s&w hair is worn &W%s%s&w. You stand at &W%d'%d\"&w and weigh\r\n"
"&W%d&w pounds, with a &W%s&w build. Your &W%s&w%s.&D\r\n",
strlower( get_eye_color( ch, ch->eyecolor ) ), strlower( get_skin_tone( ch, ch->skintone ) ),
strlower( hair_length[ch->hlength] ), strlower( get_hair_color( ch, ch->hcolor ) ),
ch->hstyle == 9 ? "as " : "", strlower( hair_style[ch->hstyle] ), feet, inches,
ch->weight, strlower( build_name[ch->build] ), strlower( facial_hair[ch->facialhair] ),
ch->facialhair == 0 ? " face draws all the attention of the ladies" : ch->facialhair == 5 ?
" are neatly trimmed" : " is neatly trimmed" );
}
else
{
snprintf( buf, MSL, "&wYour &W%s&w eyes twinkle with a need for adventure, and contrast with your\r\n"
"&W%s&w skin. Your&W %s %s&w hair is worn &W%s%s&w. You stand at&W %d'%d\"&w and weigh\r\n"
"&W%d &wpounds, with a &W%s&w build. You are ready for anything.\r\n",
strlower( get_eye_color( ch, ch->eyecolor ) ), strlower( get_skin_tone( ch, ch->skintone ) ),
strlower( hair_length[ch->hlength] ), strlower( get_hair_color( ch, ch->hcolor ) ),
ch->hstyle == 9 ? "as " : "", strlower( hair_style[ch->hstyle] ), feet, inches,
ch->weight, strlower( build_name[ch->build] ) );
}
}

return buf;
}

Any Idea why this is happening? And how to fix it?


Side note, I don't know why everything tabs over so far, it doesn't look that way in Visual Studio =/
06 Nov, 2007, Justice wrote in the 17th comment:
Votes: 0
Well, it's pretty simple really. strlower uses a static buffer that it returns a pointer to. You can pretty much look at this as a single global buffer. What's happening is that when the printf resolves the value, they all resolve to the same value (since they're pointing at the same buffer). You'll need to either copy the text to a local buffer before passing it to the printf, or you'll have to find another way to lower the values.

As for the tabbing, it's because you probably have actual "tab" characters. Visual studio will view them as 4 spaces, although other system may view them as 6 or 8 spaces. I always configure visual studio to replace tabs with spaces so that it's uniform regardless of the application used.

char *strlower( const char *str )
{
static char strlow[MAX_STRING_LENGTH];
int i;

for( i = 0; str[i] != '\0'; i++ )
strlow[i] = LOWER( str[i] );
strlow[i] = '\0';
return strlow;
}
06 Nov, 2007, Kayle wrote in the 18th comment:
Votes: 0
Thanks for the tip on Visual Studio, Justice, I'll fiddle with the descriptions and see if I can't get them to work now. :)
06 Nov, 2007, David Haley wrote in the 19th comment:
Votes: 0
The static buffer is an interesting decision… It was made to simplify things, and it does, most of the time, because you don't have to manage the string returned to you; however, if people don't understand what it's doing, it leads to this kind of "bizarre bug". It's probably the kind of thing that would be fixed with better API documentation, I suppose.
06 Nov, 2007, Kayle wrote in the 20th comment:
Votes: 0
So I came up with two solutions, and the one would be a lot easier but I don't know for sure whether any of them will work. btw, I hate working with Strings. :)

So Solution one is a painful solution:
if( ch->race == RACE_LIZARDFOLK )
{
snprintf( buf, MSL, "&wYour &W%s&w eyes stand out ferociously against your", strlower( get_eye_color( ch, ch->eyecolor ) ) );
snprintf( buf, MSL, "&W%s&w scales. You stand\r\n&W%d'%d\"&w tall and weigh &W%d&w pounds,",
strlower( scale_color[ch->scalecolor] ), feet, inches, ch->weight );
snprintf( buf, MSL, "and your &W%s&w build makes you a worthy\r\n&wadversary for any warm-blood that challenges you.\r\n",
strlower( build_name[ch->build] ) );


Solution two is much simpler and the one I like, but I don't know whether it will fix the issue:
feet = ch->height / 12;
inches = ch->height % 12;
eyecolor = strlower( get_eye_color( ch, ch->eyecolor ) );
furcolor = strlower( get_fur_color( ch, ch->furcolor ) );
scalecolor = strlower( scale_color[ch->scalecolor] );
(…)
else if( ch->race == RACE_FELINID )
{
snprintf( buf, MSL, "&wYour &W%s&w eyes twinkle mischievously, and your &W%s&w are the envy of the rest\r\n"
"&wof the pride. Your &W%s %s&w hair is worn &W%s%s&w. You stand at &W%d'%d\"&w and weigh\r\n"
"&W%d&w pounds, with a &W%s&w build. You are ready for anything.\r\n",
eyecolor, furcolor, hairlength,haircolor, ch->hstyle == 9 ? "as " : "", hairstyle,
feet, inches, ch->weight, build );


So, Which one if either is going to actually work?
0.0/61