Ejemplo n.º 1
0
bool EnemyBlocked( Tank * pEnemy, Tank & self, vector<Tank> & t )
{
	double my_angle = self.GetAngleTo( *pEnemy );
	double my_dist = self.GetDistanceTo( *pEnemy );

	for (int i = 0; i < t.size(); ++i)
	{
		if (t[i].id() == pEnemy->id() || t[i].id() == self.id())
		{
			continue;
		}

		double max_wh = std::max( t[i].width(), t[i].height() );

		double alpha = fabs( self.GetAngleTo(t[i]) - my_angle );
		double his_dist = self.GetDistanceTo( t[i] );
		
		if (alpha > M_PI / 4)
		{
			continue;
		}
		
		double d_size = sin(alpha) * my_dist;

		if ( d_size <= max_wh/2 && his_dist < my_dist )
		{
			return true;
		}
	}

	return false;
}
Ejemplo n.º 2
0
void GoToUnit( Unit * pBonus, Tank & self, model::Move & move )
{
	double orig_angle = self.GetAngleTo(*pBonus);
	double angle = orig_angle;
	double fangle = fabs(orig_angle);
	double dist = self.GetDistanceTo( *pBonus );

	double MIN_ANGLE_B = dist*0.0005;

	double direction = 1.0;

	if (orig_angle > PI_D_2)
	{
		angle = M_PI - fangle;
		direction = -1.0;
	}

	if (orig_angle < -PI_D_2)
	{
		angle = fangle - M_PI;
		direction = -1.0;
	}

	if (fangle > PI_D_2)
	{
		if ( angle > MIN_ANGLE_B )
		{
			move.set_left_track_power(-self.engine_power());
			move.set_right_track_power( self.engine_power() - self.engine_rear_power_factor() ); //(.75);
		}
		else if ( angle < -MIN_ANGLE_B )
		{
			move.set_left_track_power(self.engine_power() - self.engine_rear_power_factor() );//(.75);
			move.set_right_track_power(-self.engine_power());	
		}
		else
		{
			move.set_left_track_power(direction*1);
			move.set_right_track_power(direction*1);
		}
	}
	else
	{
		if ( angle > MIN_ANGLE_B )
		{
			move.set_left_track_power(self.engine_power() - self.engine_rear_power_factor() );//(.75);
			move.set_right_track_power(-self.engine_power());	
		}
		else if ( angle < -MIN_ANGLE_B )
		{
			move.set_left_track_power(-self.engine_power());
			move.set_right_track_power( self.engine_power() - self.engine_rear_power_factor() ); //(.75);
		}
		else
		{
			move.set_left_track_power(direction*1);
			move.set_right_track_power(direction*1);
		}
	}
}
Ejemplo n.º 3
0
void ForceModify(Tank & self, Unit & u, double & xForce, double & yForce, double neg_c)
{
		//double absBearing = fabs( u.angle() );
		double absBearing = self.GetAngleTo( u );

		/* from 0 to 2*PI */

		double distance = self.GetDistanceTo( u );

		xForce += neg_c * ( sin(absBearing) / (distance * distance) );
		yForce += neg_c * ( cos(absBearing) / (distance * distance) );
}
Ejemplo n.º 4
0
	Corner(Tank & self, double cx, double cy, CornerType cid)
		: Unit( 0.0, 0.0, 0.0, cx, cy, 0.0, 0.0, 0.0, 0.0 )
		, dist( self.GetDistanceTo(cx, cy) )
		, id( cid )
	{
	}