/**
 * Checks ship-weapon collisions.
 * @param pair obj_pair pointer to the two objects. pair->a is ship and pair->b is weapon.
 * @return 1 if all future collisions between these can be ignored
 */
int collide_ship_weapon( obj_pair * pair )
{
    int		did_hit;
    object *ship = pair->a;
    object *weapon_obj = pair->b;

    Assert( ship->type == OBJ_SHIP );
    Assert( weapon_obj->type == OBJ_WEAPON );

    ship_info *sip = &Ship_info[Ships[ship->instance].ship_info_index];

    // Don't check collisions for player if past first warpout stage.
    if ( Player->control_mode > PCM_WARPOUT_STAGE1)	{
        if ( ship == Player_obj )
            return 0;
    }

    if (reject_due_collision_groups(ship, weapon_obj))
        return 0;

    // Cull lasers within big ship spheres by casting a vector forward for (1) exit sphere or (2) lifetime of laser
    // If it does hit, don't check the pair until about 200 ms before collision.
    // If it does not hit and is within error tolerance, cull the pair.

    if ( (sip->is_big_or_huge()) && (Weapon_info[Weapons[weapon_obj->instance].weapon_info_index].subtype == WP_LASER) ) {
        // Check when within ~1.1 radii.
        // This allows good transition between sphere checking (leaving the laser about 200 ms from radius) and checking
        // within the sphere with little time between.  There may be some time for "small" big ships
        // Note: culling ships with auto spread shields seems to waste more performance than it saves,
        // so we're not doing that here
        if ( !(sip->flags[Ship::Info_Flags::Auto_spread_shields]) && vm_vec_dist_squared(&ship->pos, &weapon_obj->pos) < (1.2f*ship->radius*ship->radius) ) {
            return check_inside_radius_for_big_ships( ship, weapon_obj, pair );
        }
    }

    did_hit = ship_weapon_check_collision( ship, weapon_obj );

    if ( !did_hit )	{
        // Since we didn't hit, check to see if we can disable all future collisions
        // between these two.
        return weapon_will_never_hit( weapon_obj, ship, pair );
    }

    return 0;
}
// Checks ship-weapon collisions.  pair->a is ship and pair->b is weapon.
// Returns 1 if all future collisions between these can be ignored
int collide_ship_weapon( obj_pair * pair )
{
	int		did_hit;
	object *ship = pair->a;
	object *weapon = pair->b;
	
	Assert( ship->type == OBJ_SHIP );
	Assert( weapon->type == OBJ_WEAPON );

	// Don't check collisions for player if past first warpout stage.
	if ( Player->control_mode > PCM_WARPOUT_STAGE1)	{
		if ( ship == Player_obj )
			return 0;
	}

	// Cull lasers within big ship spheres by casting a vector forward for (1) exit sphere or (2) lifetime of laser
	// If it does hit, don't check the pair until about 200 ms before collision.  
	// If it does not hit and is within error tolerance, cull the pair.

	if ( (Ship_info[Ships[ship->instance].ship_info_index].flags & (SIF_BIG_SHIP | SIF_HUGE_SHIP)) && (Weapon_info[Weapons[weapon->instance].weapon_info_index].subtype == WP_LASER) ) {
//	if (  (ship->radius > 50) && (Weapon_info[Weapons[weapon->instance].weapon_info_index].subtype == WP_LASER) ) {
		// Check when within ~1.1 radii.  
		// This allows good transition between sphere checking (leaving the laser about 200 ms from radius) and checking
		// within the sphere with little time between.  There may be some time for "small" big ships
		if ( vm_vec_dist_squared(&ship->pos, &weapon->pos) < (1.2f*ship->radius*ship->radius) ) {
			return check_inside_radius_for_big_ships( ship, weapon, pair );
		}
	}


//	demo_do_rand_test();
	did_hit = ship_weapon_check_collision( ship, weapon );
//	demo_do_rand_test();
	if ( !did_hit )	{
		// Since we didn't hit, check to see if we can disable all future collisions
		// between these two.
		return weapon_will_never_hit( weapon, ship, pair );
	}

	return 0;
}