FIND_MAT.C
LIB3/SECURE/SIMUL_EF/FIND_MAT.C · 4.6 KB
From the archive nm4dos.zip
Download the archive « Back to the archive contents
static mixed *rest;
/*
** Looked at on 23/3/94 by Newstyle, just before
** I went out & got drunk.
*/
object *fix_list( object *org );
/* modified by Nivek, 2-Apr-94, so that we can have some decent
* hiding and invisibility stuff.
* str = pattern to be matched
* ob (ack) = object, or array of objects, whose inventories are to
* searched.
* To make your object hidden to find_match(), define a function
* query_hidden() to return 1, or query_hidden(object ob), to
* return 1 if your object is hidden to ob.
* For example, in the creator object, add the function:
* query_hidden(object ob)
* { return ( invis
* && !ob->query_creator() )
* }
*/
find_match( string str, mixed ob )
{
mixed *array, test, *ret;
int i, num, top, bot, bing, j;
string nick, type, *bits;
if( !ob || intp( ob ) )
return({ });
if( str == "" || !str )
return({ });
if( stringp( ob ) )
if( !(ob = find_object( ob )) )
{
catch( ob->dummy() );
if( !(ob = find_object( ob )) )
return({ });
}
if( !pointerp( ob ) )
{
if( !(ob = (object *)ob->find_inv_match( str )) )
return({ });
}
else
{
array = ({ });
for( i = 0; i < sizeof( ob ); i++ )
if( (test = (object *)ob[ i ]->find_inv_match( str )) )
array += test;
ob = array;
}
bits = explode( replace( str, " and ", "," ), "," );
ret = ({ });
for( j = 0; j < sizeof( bits ); j++ )
{
str = bits[ j ];
nick = (string)this_object()->expand_nickname( str );
if( !nick && this_player() )
nick = (string)this_player()->expand_nickname( str );
if( nick && nick != "" )
str = nick;
if( str == "it" || str == "them" || str == "him" || str == "her" )
{
rest = all_inventory( this_player() ) +
all_inventory( environment( this_player() ) );
array = (object *)this_player()->query_it_them();
while( i < sizeof( array ) )
if( member_array( array[ i ], rest ) == -1 )
array = delete( array, i, 1 );
else
i++;
if( !sizeof( array ) )
continue;
if( str == "it" )
{
ret += array[ 0..0 ];
continue;
}
if( str == "her" )
if( living( array[ 0 ] ) && (int)array[ 0 ]->query_gender() == 2 )
{
ret += array[ 0..0 ];
continue;
}
else
continue;
if( str == "him" )
if( living( array[ 0 ] ) && (int)array[ 0 ]->query_gender() == 1 )
{
ret += array[ 0..0 ];
continue;
}
else
continue;
ret += array;
continue;
}
test = explode( str, " " );
sscanf( test[ sizeof( test ) - 1 ], "%d", bing );
test = ({ });
rest = ({ });
if( sscanf( str, "%d/%d of %s", top, bot, str ) != 3 )
top = bot = 1;
if( top <= 0 )
top = 1;
if( bot < top )
bot = top;
parse_command( str, ob, "%i", test );
if( !test || !sizeof( test ) )
continue;
if( bot != top )
{
num = test[ 0 ];
array = query_strange_inventory( test[ 1..sizeof( test ) - 1 ] );
test = ({ });
for( i = 0; i < sizeof( array ); i += 2 )
test += map_array( array[ i + 1 ], "query_frac_simul_efun_id",
this_object(), ({ num, str, 0, sizeof( array[ i + 1 ] ),
top, bot }) );
array = test + rest;
ret += array;
continue;
}
if( test[ 0 ] == 1 && bing )
test[ 0 ] = -bing;
array = map_array( test[ 1..sizeof( test ) - 1 ], "query_simul_efun_id",
this_object(), ({ test[ 0 ], str }) );
array += rest;
ret += array;
}
ret = fix_list( ret );
if( this_player() && !this_player()->query_creator() )
for( i = sizeof( ret ) - 1; i >= 0; i-- )
if( ret[ i ]->query_hidden( this_player() ) )
ret -= ret[ i ];
if( this_player() && sizeof( ret ) )
this_player()->set_it_them( ret );
return ret;
} /* find_match() */
object *fix_list( object *org )
{
object *ret;
int i;
ret = ({ });
for( i = 0; i < sizeof( org ); i++ )
if( org[ i ] && (member_array( org[ i ], org ) == i) )
if( living( org[ i ] ) )
ret = ({ org[ i ] }) +ret;
else
ret += ({ org[ i ] });
return ret;
}
object query_simul_efun_id( object ob, mixed *arr )
{
mixed ret;
ret = (mixed)ob->query_parse_id( arr );
if( !pointerp( ret ) )
return ret;
rest += ret[ 1..sizeof( ret ) ];
return ret[ 0 ];
} /* query_simul_efun_id() */
object query_frac_simul_efun_id( object ob, mixed *arr )
{
mixed ret;
ret = (mixed)ob->query_frac_parse_id( arr );
if( !pointerp( ret ) )
return ret;
rest += ret[ 1..sizeof( ret ) ];
return ret[ 0 ];
} /* query_frac_efun_id() */
int fixup_parse_command( mixed ob )
{
return objectp( ob );
} /* fixup_parse_command() */