booleval.txt

Uploaded: 24 May, 2007
Previous uploads by this submitter: 0

Author: Richard Ortiz

Downloads: 68

This is a similar function to mprog_seval and mprog_veval but it will evaulate a boolean. Stock smaug had originally just evaluated ifchecks for a given circumstance and just returned without being able to use an operator and a value, value being true or false. To overcome this builders would have to create an ELSE clause, and not every ifcheck did something in an ELSE situation

For example:
if isfight($n)
break
else
if rand(10)
yawn
endif
endif

The following function will allow you to do something shorter like so:
if isfight($n) == false
if rand(10)
yawn
endif
endif

// Boolean Evaluation
bool mprog_beval( bool lhs, char *opr, char *rhs, CHAR_DATA *mob )
{
char log_buf[MAX_STRING_LENGTH];
bool rval;

if ( rhs[0] == '\0' )
return lhs;
else if ( !str_cmp( rhs, "true" ) )
rval = TRUE;
else if ( !str_cmp( rhs, "false" ) )
rval = FALSE;
else
return lhs;

if ( opr[0] == '\0' )
return lhs;
if ( !str_cmp( opr, "==" ) )
return ( bool )( lhs == rval );
if ( !str_cmp( opr, "!=" ) )
return ( bool )( lhs != rval );

sprintf( log_buf, "Improper MOBprog operator '%s' for Boolean Evaluation", opr );
progbug( log_buf, mob );
return lhs;
}


Now in mud_prog.c for the ifchecks you will change to the following, I will show you isfight as the example:
Original Code:
if ( !str_cmp(chck, "isfight") )
{
return who_fighting(chkchar) ? TRUE : FALSE;
}


This now becomes:
if ( !str_cmp(chck, "isfight") )
{
return mprog_beval( (who_fighting(chkchar) != NULL), opr, rval, mob );
}