I do understand bitmasks and binary, and I have coding knowledge, but I've been more of a logic programmer, and I'm porting my knowledge of other languages over to C, which is a transistion that's not being very easy for me to make.. I learn best by asking a lot of questions and this is just something I don't understand too well, sorry for bugging you for so much clarification. I don't think I totally understand it, but it did work, and it's whittled the errors down to when you save, it seems to print weird stuff
->Afg† 0 0 0<-
(and the weird holy cross looks like an a with a circle ontop of it in shell..)
It seems to save new mobs funny... that mob had the flags 'npc' and 'shaman', and printed the above... the code for saving is in olc_save.c and I think the following function...
char *fwrite_flag( long long flags, char buf[] )
{
char offset;
char *cp;
buf[0] = '\0';
if ( flags == 0 )
{
strcpy( buf, "0" );
return buf;
}
/* 64 -- number of bits in a long long */
for ( offset = 0, cp = buf; offset < 64; offset++ )
if ( flags & ( (long)1 << offset ) )
{
if ( offset <= 'Z' - 'A' )
*(cp++) = 'A' + offset;
else
*(cp++) = 'a' + offset - ( 'Z' - 'A' + 1 );
}
*cp = '\0';
return buf;
}
and it's read in by this..
long long fread_flag( FILE *fp)
{
int number;
char c;
bool negative = FALSE;
do
{
c = getc(fp);
}
while ( isspace(c));
if (c == '-')
{
negative = TRUE;
c = getc(fp);
}
number = 0;
if (!isdigit(c))
{
while (('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z'))
{
number += flag_convert(c);
c = getc(fp);
}
}
while (isdigit(c))
{
number = number * 10 + c - '0';
c = getc(fp);
}
if (c == '|')
number += fread_flag(fp);
else if ( c != ' ')
ungetc(c,fp);
if (negative)
return -1 * number;
return number;
}
this function also kinda stuck out to me...
long long fread_flag( FILE *fp)
{
int number;
char c;
bool negative = FALSE;
do
{
c = getc(fp);
}
while ( isspace(c));
if (c == '-')
{
negative = TRUE;
c = getc(fp);
}
number = 0;
if (!isdigit(c))
{
while (('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z'))
{
number += flag_convert(c);
c = getc(fp);
}
}
while (isdigit(c))
{
number = number * 10 + c - '0';
c = getc(fp);
}
if (c == '|')
number += fread_flag(fp);
else if ( c != ' ')
ungetc(c,fp);
if (negative)
return -1 * number;
return number;
} |