This snippet will allow ships with tractorbeams AND hangers to tractor
ships into thier hanger when in normal landing range. This will be taken
as an offensive move by autopiloted ships.

Enjoy

Gendi.



/* This procedure replaces the empty one in space.c */

void do_tractorbeam( CHAR_DATA *ch, char *argument )
{

    char arg[MAX_INPUT_LENGTH];
    int chance;
    SHIP_DATA *ship;
    SHIP_DATA *target;
	char buf[MAX_STRING_LENGTH];
    
    strcpy( arg, argument );

	if ( (ship = ship_from_cockpit(ch->in_room->vnum)) == NULL )
	{
		send_to_char("&RYou must be in the cockpit of a ship to do that!\n\r",ch);
		return;
	}
    	    
	if ( ship->class > SHIP_PLATFORM )
	{
		send_to_char("&RThis isn't a spacecraft!\n\r",ch);
		return;
	}


	if ( !check_pilot( ch , ship ) )
	{
		send_to_char("This isn't your ship!\n\r" , ch );
		return;
	}

	if ( ship->tractorbeam == 0 )
	{
		send_to_char("You might want to install a tractorbeam!\n\r" , ch );
		return;
	}
    
	if ( ship->hanger == 0 )
	{
		send_to_char("No hanger available.\n\r",ch);
		return;
	}

	if ( !ship->bayopen )
	{
		send_to_char("Your hanger is closed.\n\r",ch);
		return;
	}

   	        
	if ( (ship = ship_from_pilotseat(ch->in_room->vnum)) == NULL )
	{
		send_to_char("&RYou need to be in the pilot seat!\n\r",ch);
		return;
	}
    	        
    	            	        
	if (ship->shipstate == SHIP_DISABLED)
	{
		send_to_char("&RThe ships drive is disabled. No power available.\n\r",ch);
		return;
	}

	if (ship->shipstate == SHIP_DOCKED)
	{
		send_to_char("&RYour ship is docked!\n\r",ch);    
		return;	        
	}
    	                			
	if (ship->shipstate == SHIP_HYPERSPACE)		   
	{
					
		send_to_char("&RYou can only do that in realspace!\n\r",ch);
		return;   			
	}

	if (ship->shipstate != SHIP_READY)
	{
		send_to_char("&RPlease wait until the ship has finished its current manouver.\n\r",ch);
		return;	    
	}



    	        
	if ( argument[0] == '\0' )	        
	{  	
		send_to_char("&RCapture what?\n\r",ch);	
		return;				
	}
   	            
	target = get_ship_here( argument , ship->starsystem );

	if ( target == NULL )            
	{   	                
		send_to_char("&RI don't see that here.\n\r",ch);   	 
		return;             
	} 
   	           
	if ( target == ship )   	
	{   	               
		send_to_char("&RYou can't yourself!\n\r",ch);   	 
		return;              
	}   	           
   	         
	if ( target->shipstate == SHIP_LAND )
	{
		send_to_char("&RThat ship is already in a landing sequence.\n\r", ch);
		return;
	}

	if (  (target->vx > ship->vx + 200) || (target->vx < ship->vx - 200) ||
	   (target->vy > ship->vy + 200) || (target->vy < ship->vy - 200) ||
	   (target->vz > ship->vz + 200) || (target->vz < ship->vz - 200) )
	{
		send_to_char("&R That ship is too far away! You'll have to fly a litlle closer.\n\r",ch);
		return;
	}   
    
	if (ship->class <= target->class)
	{
		send_to_char("&RThat ship is too big for your hanger.\n\r",ch);
		return;
	}
    	        
	if  ( target->class == SHIP_PLATFORM )
	{
		send_to_char( "&RYou can't capture platforms.\n\r" , ch );
		return;
	}   
    
	if ( target->class == CAPITAL_SHIP)
	{
		send_to_char("&RYou can't capture capital ships.\n\r",ch);
		return;
	}


	if ( ship->energy < (25 + 25*target->class) )
	{
		send_to_char("&RTheres not enough fuel!\n\r",ch);
		return;
	}



				           
	chance = IS_NPC(ch) ? ch->top_level
	: (int)  (ch->pcdata->learned[gsn_tractorbeams]);

	/* This is just a first guess chance modifier, feel free to change if needed */

	chance = chance * ( ship->tractorbeam / (target->currspeed+1 ) );
 
	if ( number_percent( ) < chance )
	{    		   
		set_char_color( AT_GREEN, ch );    
		send_to_char( "Capture sequence initiated.\n\r", ch);    		   
		act( AT_PLAIN, "$n begins the capture sequence.", ch,		        
			NULL, argument , TO_ROOM );
		echo_to_ship( AT_YELLOW , ship , "ALERT: Ship is being captured, all hands to docking bay." );
    	echo_to_ship( AT_YELLOW , target , "The ship shudders as a tractorbeam locks on." );
		sprintf( buf , "You are being captured by %s." , ship->name);  
		echo_to_cockpit( AT_BLOOD , target , buf );

		if ( autofly(target) && !target->target0)
			target->target0 = ship;

		target->dest = STRALLOC(ship->name);    		   
		target->shipstate = SHIP_LAND;    		   
		target->currspeed = 0;	           
	                     
		learn_from_success( ch, gsn_tractorbeams );	
		return;
	                  
	}	       
	send_to_char("You fail to work the controls properly.\n\r",ch);
   	echo_to_ship( AT_YELLOW , target , "The ship shudders and then stops as a tractorbeam attemps to lock on." );
	sprintf( buf , "The %s attempted to capture your ship!" , ship->name);  
	echo_to_cockpit( AT_BLOOD , target , buf );
	if ( autofly(target) && !target->target0)
		target->target0 = ship;

                  
	learn_from_failure( ch, gsn_tractorbeams );                
	  	
   	return;	
}