Author Topic: problem with get  (Read 1821 times)

Offline z993126

  • BFF
  • ***
  • Posts: 128
    • View Profile
problem with get
« on: December 31, 2011, 09:27:58 pm »
trying to bring /verbs/items/get.c up to speed with the additions I made to drop, and it works for get_wrd_wrd, but the get_wrd_wrd_from_obj stuff is having serious issues.

Code: [Select]
/*  /verbs/items/get.c
 *  from the Dead Souls Mud Library
 *  created by Descartes of Borg 950113
 *  Version: @(#) get.c 1.5@(#)
 *  Last Modified: 96/11/12
 *  2011-Dec-28 T. Cook added resource handling
 *              T. Cook corrected passed-array bug in do_get_wrd_wrd_from_obj() & do_get_wrd_from_obj()
 *              T. Cook modified help message
 *  2011-Dec-31 T. Cook added can_get_wrd_wrd() and do_get_wrd_wrd() for plurals
 */
#include <lib.h>
#include <daemons.h>

inherit LIB_VERB;
int yes;

static void create() {
verb::create();
SetVerb( "get" );
SetRules(
"OBS OBJ", "WRD WRD", "WRD from OBJ", "WRD out of OBJ", "WRD WRD from OBJ", "WRD WRD out of OBJ", "OBS",
"OBS out of OBJ", "OBS from OBJ"
);
SetSynonyms( "take", "pick up", "acquire" );
SetErrorMessage( "Get what?  Or, get what from where?" );
SetHelp(
"Syntax:  '%^B_WHITE%^%^BLACK%^get <WHAT>%^RESET%^'\n"
"         '%^B_WHITE%^%^BLACK%^get <WHAT> from <WHAT>%^RESET%^'\n"
"         '%^B_WHITE%^%^BLACK%^get <WHAT> out of <WHAT>%^RESET%^'\n"
"         '%^B_WHITE%^%^BLACK%^get <AMOUNT> <WHAT>%^RESET%^'\n"  // this doesn't exist yet
"         '%^B_WHITE%^%^BLACK%^get <AMOUNT> <WHAT> from <WHAT>%^RESET%^'\n"
"         '%^B_WHITE%^%^BLACK%^get <AMOUNT> <WHAT> out of <WHAT>%^RESET%^'\n\n"
"If you wish to acquire a movable object in your environment, or one which is inside of a container, you "
"can use this command to attempt to do so.  Whether you can clearly see the object, as well as the combined "
"weight of everything you're carrying, affect your ability to pick up the item.  This also works on piles of "
"money and clouds, heaps, and puddles of resources; either the entire collection or a part of it can be had "
"in this way.\n\n"
"Synonyms:  take, pick up, acquire\n\n"
"See also:  drop, give, put, steal"  // todo: add owner property to items to show if an item has been stolen
);
}

mixed eventCheckLight( object who ){
int light;

if( ( light = who->GetEffectiveVision() ) < 2 ){
if( 100 + ( 10 * light ) < random( 100 ) ){
return "You fumble around in the darkness.";
}else{
return this_player()->CanManipulate();
}
}else if( light > 5 ){
if( 100 - ( 10 * light ) < random( 100 ) ){
return "You fumble around in the blinding light.";
}else{
return this_player()->CanManipulate();
}
}else{
return this_player()->CanManipulate();
}
}

mixed can_get_obj( string verb ){
return eventCheckLight( this_player() );
}

mixed can_get_wrd_wrd( mixed args... ){
string s_num, s_what, s_resource, s_id;
string *sa_resources = ({}), *sa_ids = ({});
int i_amt, i_total;
object o_ob, *oa_obs = ({});
mixed m_item;

s_num = args[0];
s_what = lower_case( args[1] );

if( o_ob = get_object( numeralize( s_num ) + " " + s_what ) ){ return eventCheckLight( this_player() ); }

if( !s_num || !s_what ){ return 0; }
if( ( i_amt = numeralize( s_num ) ) < 1 ){ return "You cannot do that!"; }

/* this section is to enable reference to plural and item-id forms of an item */
foreach( m_item in all_inventory( environment( this_player() ) ) ){
sa_ids = ({});
foreach( s_id in m_item->GetCanonicalId() + ({ m_item->GetName() }) ){
if( member_array( lower_case( s_id ), sa_ids ) == -1 ){
sa_ids += ({ lower_case( s_id ) });
}
}
foreach( s_id in sa_ids ){
if( member_array( m_item, oa_obs ) == -1 ){
if( s_what == s_id || s_what == pluralize( s_id ) ){ oa_obs += ({ m_item }); }
}
}
}
/*---- from that */

if( sizeof( oa_obs ) ){
if( sizeof( oa_obs ) < i_amt ){
return "There aren't that many " + s_what + " here.";
}
}
return eventCheckLight( this_player() );
}

varargs mixed can_get_obj_out_of_obj( mixed args... ){
mixed ret = eventCheckLight( this_player() );
object ob;
int which;
if( !( args[3] && ob = to_object( args[3] ) ) ){
return ret;
}else{
if( ob->GetClosed() ){
return "The " + remove_article( ob->GetShort() ) + " is closed.";
}
}
return ret;
}

mixed can_get_obj_obj( string verb, string rule, mixed item, object container ){
return can_get_obj_out_of_obj( verb, rule, item, container );
}

mixed can_get_obs_obj( string verb, string rule, mixed *item, object container ){
return can_get_obj_out_of_obj( verb, rule, item, container );
}

mixed can_get_obj_from_obj( mixed args... ){
return can_get_obj_out_of_obj( args... );
}

mixed can_get_wrd_wrd_out_of_obj( mixed args... ){
mixed m_x, *ma_xs;
mixed ret = eventCheckLight( this_player() );
int i_count, i_max;
object ob;
write( "%^GREEN%^can_get_wrd_wrd_out_of_obj() called%^RESET%^" );
if( sizeof( args ) > 5 ){
if( args[5] ){
ob = to_object( args[5] );
}else if( args[3] ){
ob = to_object( args[3] );
}
}
i_max = sizeof( args );
for( i_count = 0; i_count < i_max; i_count++){
write( sprintf( "args[%O] = %O", i_count, args[i_count] ) );
}
write( sprintf( "ob = %O", ob ) );
if( ob && ob->GetClosed() ){
return "The " + remove_article( ob->GetShort() ) + " is closed." ;
}
write( "returning " + ret );
return ret;
}

mixed can_get_wrd_wrd_from_obj( mixed args... ){
write( "%^GREEN%^can_get_wrd_wrd_from_obj() called%^RESET%^" );
args[0] = sprintf( "%d", numeralize( args[0] ) );
args[3] = args[0];
return can_get_wrd_wrd_out_of_obj( args... );
}

mixed can_get_wrd_out_of_obj( mixed args... ){
mixed ret = eventCheckLight( this_player() );
object ob;
int i_count, i_max;
write( "%^GREEN%^can_get_wrd_out_of_obj() called%^RESET%^" );
i_max = sizeof( args );
for( i_count = 0; i_count < i_max; i_count++){
write( sprintf( "args[%O] = %O", i_count, args[i_count] ) );
}
if( args[3] ){ ob = to_object( args[3] ); }

if( ob && ob->GetClosed() ){
return "The " + remove_article( ob->GetShort() ) + " is closed." ;
}
return ret;
}

mixed can_get_wrd_from_obj( mixed args... ){
int i_count, i_max;
write( "%^GREEN%^can_get_wrd_from_obj() called%^RESET%^" );
i_max = sizeof( args );
for( i_count = 0; i_count < i_max; i_count++){
write( sprintf( "args[%O] = %O", i_count, args[i_count] ) );
}
return can_get_wrd_out_of_obj( args... );
}

mixed do_get_obj( object ob ){
write( "%^GREEN%^do_get_obj() called%^RESET%^" );
write( sprintf( "ob = %O", ob ) );
return ob->eventGet( this_player() );
}

mixed do_get_wrd_wrd( mixed args... ){
string s_num, s_what, s_resource, s_id;
string *sa_resources = ({}), *sa_ids = ({});
int i_amt, i_total, i_count;
object o_ob, *oa_obs = ({}), o_pile, o_env;
mixed m_item;
int i_max;

write( "%^GREEN%^do_get_wrd_wrd() called%^RESET%^" );
i_max = sizeof( args );
for( i_count = 0; i_count < i_max; i_count++){
write( sprintf( "args[%O] = %O", i_count, args[i_count] ) );
}

s_num = args[0];
s_what = args[1];

if( o_ob = get_object( numeralize( s_num ) + " " + s_what ) ){ return do_get_obj( o_ob ); }

if( !s_num || !s_what ){ return 0; }
if( ( i_amt = numeralize( s_num ) ) < 1 ){ return "You cannot do that!"; }
o_env = environment( this_player() );

/* this section is to enable reference to plural and item-id forms of an item */
foreach( m_item in all_inventory( environment( this_player() ) ) ){
sa_ids = ({});
foreach( s_id in m_item->GetCanonicalId() + ({ m_item->GetName() }) ){
if( member_array( lower_case( s_id ), sa_ids ) == -1 ){
sa_ids += ({ lower_case( s_id ) });
}
}
foreach( s_id in sa_ids ){
if( member_array( m_item, oa_obs ) == -1 ){
if( s_what == s_id || s_what == pluralize( s_id ) ){ oa_obs += ({ m_item }); }
}
}
}
/*----*/

if( sizeof( oa_obs ) ){
oa_obs = scramble_array( oa_obs );
for( i_count = 0; i_count < i_amt; i_count++ ){
oa_obs[i_count]->eventGet( this_player() );
}
}else{
write( "What?");
return 0;
}
return 1;
//return what->eventGet(this_player());
}

mixed do_get_obj_out_of_obj( object ob, object storage ){
write( "%^GREEN%^do_get_wrd_out_of_obj() called%^RESET%^" );
write( sprintf( "ob = %O", ob ) );

if( !ob ){ return "No object"; }
if( !( environment( ob ) == storage ) ){
ob = present( ob->GetKeyName(), storage );
if( !ob ){
write( "That's not in there." );
return "";
}
}
return storage->eventGetFrom( this_player(), ({ ob }) );
}

mixed do_get_obj_from_obj( object ob, object storage ){
return do_get_obj_out_of_obj( ob, storage );
}

mixed do_get_obj_obj( object ob, object storage ){
return do_get_obj_out_of_obj( ob, storage );
}

mixed do_get_obs( mixed *targs ){
object *obs;
if( !sizeof( targs ) ){
this_player()->eventPrint( "There is no such thing to be taken." );
return 1;
}
obs = filter( targs, (: objectp :) );
if( !sizeof( obs ) ){
mapping messages = unique_mapping( targs, (: $1 :) );

foreach( string msg in keys( messages ) ){
this_player()->eventPrint( msg );
}
return 1;
}
foreach( object item in obs ){
if( item->CanGet( this_player() ) != 1 ){ continue; }
item->eventGet( this_player() );
}
return 1;
}

mixed do_get_obs_out_of_obj( mixed *targs, object storage ){
object *obs;
if( !sizeof( targs ) ){
this_player()->eventPrint( "There is no such thing to be taken." );
return 1;
}
obs = filter( targs, (: objectp :) );
if( !sizeof( obs ) ){
mapping messages = unique_mapping( targs, (: $1 :) );

foreach( string msg in keys( messages ) ){
this_player()->eventPrint( msg );
}
return 1;
}
return storage->eventGetFrom( this_player(), obs );
}

mixed do_get_obs_from_obj( mixed *obs, object storage ){
int i_count, i_max;

write( "%^GREEN%^do_get_obs_out_of_obj() called%^RESET%^" );
i_max = sizeof( obs );
for( i_count = 0; i_count < i_max; i_count++){
write( sprintf( "obs[%O] = %O", i_count, obs[i_count] ) );
}
return do_get_obs_out_of_obj( obs, storage );
}

mixed do_get_obs_obj( mixed *obs, object storage ){
return do_get_obs_out_of_obj( obs, storage );
}

mixed do_get_wrd_wrd_from_obj( mixed args... ){
string num, what;
mixed pile;
object ob1, ob2;
int i_count, i_max;

write( "%^GREEN%^do_get_wrd_wrd_from_obj() called%^RESET%^" );
i_max = sizeof( args );
for( i_count = 0; i_count < i_max; i_count++){
write( sprintf( "args[%O] = %O", i_count, args[i_count] ) );
}

if( sizeof( args[0] ) > 1 ){ args = args[0]; }
num = args[0];
what = singularize( args[1] );
pile = args[2];

ob1 = to_object( numeralize( num ) + " " + what );
ob2 = to_object( implode( args[6..], " " ) );

if( ob1 && ob2 ){ return do_get_obj_from_obj( ob1, ob2 ); }

write( "num=" + num + " (" + numeralize( num ) + ")  what=" + what + "  pile=" + pile );
if( member_array( what, ECONOMY_D->__QueryCurrencies() ) > -1 ){
return pile->eventGetMoney( this_player(), numeralize( num ), what );
}/*else{
return pile->eventGetResource( this_player(), numeralize( num ), what );
}*/
}

mixed do_get_wrd_wrd_out_of_obj( mixed args... ){
int i_count, i_max;

write( "%^GREEN%^do_get_wrd_from_obj() called%^RESET%^" );
i_max = sizeof( args );
for( i_count = 0; i_count < i_max; i_count++){
write( sprintf( "args[%O] = %O", i_count, args[i_count] ) );
}
return do_get_wrd_wrd_from_obj( args );
}

mixed do_get_wrd_from_obj( mixed args... ){
string num, what;
mixed pile;
object ob1, ob2;
int i_count, i_max;

write( "%^GREEN%^do_get_wrd_from_obj() called%^RESET%^" );
i_max = sizeof( args );
for( i_count = 0; i_count < i_max; i_count++){
write( sprintf( "args[%O] = %O", i_count, args[i_count] ) );
}

if( sizeof( args[0] ) > 1 ){ args = args[0]; }
num = args[0];
what = args[1];
pile = args[2];

ob1 = to_object( num + " " + what );
ob2 = to_object( implode( args[6..], " " ) );

if( ob1 && ob2 ){ return do_get_obj_from_obj( ob1, ob2 ); }

if( member_array( what, ECONOMY_D->__QueryCurrencies() ) ){
return pile->eventGetMoney(this_player(), to_int(num), what);
}/*else{
return pile->eventGetResource( this_player(), to_int( num ), what );
}*/
}

mixed do_get_wrd_out_of_obj( mixed args... ){
int i_count, i_max;

write( "%^GREEN%^do_get_wrd_out_of_obj() called%^RESET%^" );
i_max = sizeof( args );
for( i_count = 0; i_count < i_max; i_count++){
write( sprintf( "args[%O] = %O", i_count, args[i_count] ) );
}
return do_get_wrd_from_obj( args );
}
/* EOF */

Offline z993126

  • BFF
  • ***
  • Posts: 128
    • View Profile
Re: problem with get
« Reply #1 on: December 31, 2011, 10:26:48 pm »
here's an example of what it's doing, output-wise


Offline Sluggy

  • Friend
  • **
  • Posts: 91
    • View Profile
    • Stellarmass
Re: problem with get
« Reply #2 on: January 01, 2012, 11:43:46 am »
I actually wrote a solution to this problem a while ago but it takes a very different path from yours.

Instead of changing the verbs I changed the applies that  the verbs call. If you are interested I could probably drudge up the code. However, I can't say the my solution was elegant, clean, or efficient.

EDIT: my bad, a quick look shows me that i did change the verb code. But I also changed the applies so that I could pass a flag to them to indicate if they should print the get/drop/put messages or not.

The trick is to ONLY change the code for 'mixed do_get_obs(mixed *targs)'

« Last Edit: January 01, 2012, 11:49:57 am by Sluggy »