xget2.c

gurba-0.40/lib/cmds/player/xget2.c · 2.6 KB

From the archive gurba.tgz

Download the archive   « Back to the archive contents

void main( string arg ) {
   object ob;
   object *inv;
   int i;
   object *objs;
   

   if( arg == "" ) {
      write( "Get what?\n" );
      return;
   }
  
   if( arg == "all" ) {
      inv = this_environment()->query_inventory();
      for( i=0; i < sizeof( inv ); i++ ) {
         if( inv[i]->is_gettable() ) {
            if( inv[i]->move( this_player() ) ) {
               this_player()->targetted_action( "$N $vpick up $o.", 0, inv[i] );
            } 
            else {
               this_player()->targetted_action( "$N $vtry to pick up $o, but $vfail.", 0, inv[i] ); 
            }
         } 
         else {
            if( !inv[i]->is_player() ) {
               this_player()->targetted_action( "$N $vare unable to get $o.", 0, inv[i] ); 
            }
         }
      } 
      return;
   }   
  
   ob = this_environment()->find_object( arg );
   if( ob == 0 ) {  
      /* Hmm. Not a real object. Maybe it's a fake one. */

      /* Check the players inventory */
      objs = this_player()->query_inventory();
      for( i = 0; i < sizeof( objs ); i++ ) {
         if( objs[i]->query_items() != 0 ) {
            if( member_array( arg, objs[i]->query_items() ) != -1 ) {
               /* Found a fake object */
               
               write(" You are unable to get the "+arg+".\n"); 
               return;
            }
         }
      }
      /* Check if it's in the room */
      if( member_array( arg, this_environment()->query_items() ) != -1 ) {
         /* Found a fake object */
         this_player()->targetted_action( "$N $vare unable to get the "+arg+".", 0, ob ); 
        return;
      }
      /* Check the rooms inventory */
      objs = this_environment()->query_inventory();
      for( i = 0; i < sizeof( objs ); i++ ) {
         if( objs[i]->query_items() != 0 ) {
            if( member_array( arg, objs[i]->query_items() ) != -1 ) {
               /* Found a fake object */
               write(" You are unable to get the "+arg+".\n"); 
               return;
            }
         }
      }
     
      /* There is nothing at all like that here to try to get */
      write( "You can't seem to find the " + arg + ".\n" );
      return;
   }
    
   else {
      /* try to get a real item */
      if( ob->is_gettable() ) {
         if( ob->move( this_player() ) ) {
            this_player()->targetted_action( "$N $vpick up $o.", 0, ob );
         } 
         else {
            this_player()->targetted_action( "$N $vtry to pick up $o, but $vfail.", 0, ob ); 
         }
      } 
      else {
         this_player()->targetted_action( "$N $vare unable to get $o.", 0, ob ); 
      }
   }
}

Site Stats

Snippets: 1791
Codebases: 571