<commit_before>﻿using System;
using System.Diagnostics;

namespace BulletMLLib
{
	/// <summary>
	/// This task changes the direction a little bit every frame
	/// </summary>
	public class BulletMLChangeDirection : BulletMLTask
	{
		#region Members

		/// <summary>
		/// The amount to change driection every frame
		/// </summary>
		private float DirectionChange;

		/// <summary>
		/// How long to run this task... measured in frames
		/// </summary>
		private int Duration { get; set; }

		/// <summary>
		/// Gets or sets a flag indicating whether this is the <see cref="BulletMLLib.BulletMLAccel"/> initial run.
		/// </summary>
		/// <value><c>true</c> if initial run; otherwise, <c>false</c>.</value>
		private bool InitialRun { get; set; }

		/// <summary>
		/// The type of direction change...
		/// </summary>
		ENodeType ChangeType = ENodeType.none;

		#endregion //Members

		#region Methods

		/// <summary>
		/// Initializes a new instance of the <see cref="BulletMLLib.BulletMLTask"/> class.
		/// </summary>
		/// <param name="node">Node.</param>
		/// <param name="owner">Owner.</param>
		public BulletMLChangeDirection(BulletMLNode node, BulletMLTask owner) : base(node, owner)
		{
			Debug.Assert(null != Node);
			Debug.Assert(null != Owner);
		}

		protected override void Init()
		{
			base.Init();
			InitialRun = true;
			Duration = (int)Node.GetChildValue(ENodeName.term, this);
		}
		
		public override ERunStatus Run(Bullet bullet)
		{
			if (InitialRun)
			{
				InitialRun = false;

				//Get the amount to change direction from the nodes
				float value = (float)(Node.GetChildValue(ENodeName.direction, this) * Math.PI / 180);

				//How do we want to change direction?
				ChangeType = Node.GetChild(ENodeName.direction).NodeType;
				switch (ChangeType)
				{
					case ENodeType.sequence:
					{
						//We are going to add this amount to the direction every frame
						DirectionChange = value;
					}
					break;

					case ENodeType.absolute:
					{
						//We are going to go in the direction we are given, regardless of where we are pointing right now
						DirectionChange = (float)(value - bullet.Direction) / Duration; //Divide by the duration so we ease into the direction change
					}
					break;

					case ENodeType.relative:
					{
						//The direction change will be relative to our current direction
						DirectionChange = (float)(value) / Duration;
					}
					break;

					default:
					{
						//the direction change is to aim at the enemy
						DirectionChange = (float)(bullet.GetAimDir() + value - bullet.Direction) / Duration;
					}
					break;
				}

				//keep the direction between 0 and 360
				if (DirectionChange > Math.PI)<commit_msg>trying to fix homing missiles<commit_after>﻿using System;
using System.Diagnostics;

namespace BulletMLLib
{
	/// <summary>
	/// This task changes the direction a little bit every frame
	/// </summary>
	public class BulletMLChangeDirection : BulletMLTask
	{
		#region Members

		/// <summary>
		/// The amount to change driection every frame
		/// </summary>
		private float DirectionChange;

		/// <summary>
		/// How long to run this task... measured in frames
		/// </summary>
		private int Duration { get; set; }

		/// <summary>
		/// Gets or sets a flag indicating whether this is the <see cref="BulletMLLib.BulletMLAccel"/> initial run.
		/// </summary>
		/// <value><c>true</c> if initial run; otherwise, <c>false</c>.</value>
		private bool InitialRun { get; set; }

		/// <summary>
		/// The type of direction change...
		/// </summary>
		ENodeType ChangeType = ENodeType.none;

		#endregion //Members

		#region Methods

		/// <summary>
		/// Initializes a new instance of the <see cref="BulletMLLib.BulletMLTask"/> class.
		/// </summary>
		/// <param name="node">Node.</param>
		/// <param name="owner">Owner.</param>
		public BulletMLChangeDirection(BulletMLNode node, BulletMLTask owner) : base(node, owner)
		{
			Debug.Assert(null != Node);
			Debug.Assert(null != Owner);
		}

		protected override void Init()
		{
			base.Init();
			InitialRun = true;
			Duration = (int)Node.GetChildValue(ENodeName.term, this);
		}
		
		public override ERunStatus Run(Bullet bullet)
		{
			if (InitialRun)
			{
				InitialRun = false;

				//Get the amount to change direction from the nodes
				float value = (float)(Node.GetChildValue(ENodeName.direction, this) * Math.PI / 180); //also make sure to convert to radians

				//How do we want to change direction?
				ChangeType = Node.GetChild(ENodeName.direction).NodeType;
				switch (ChangeType)
				{
					case ENodeType.sequence:
					{
						//We are going to add this amount to the direction every frame
						DirectionChange = value;
					}
					break;

					case ENodeType.absolute:
					{
						//We are going to go in the direction we are given, regardless of where we are pointing right now
						DirectionChange = (float)(value - bullet.Direction) / Duration; //Divide by the duration so we ease into the direction change
					}
					break;

					case ENodeType.relative:
					{
						//The direction change will be relative to our current direction
						DirectionChange = (float)(value) / Duration;
					}
					break;

					default:
					{
						//the direction change is to aim at the enemy
						DirectionChange = (bullet.GetAimDir() + value) / (float)Duration;
						//DirectionChange = ((bullet.GetAimDir() + value) - bullet.Direction) / (float)Duration;
					}
					break;
				}

				//keep the direction between 0 and 360
				if (DirectionChange > Math.PI)
{'fraction_non_alphanumeric': 0.1198698246248418, 'fraction_numerical': 0.0025311878502983186, 'mean_word_length': 2.68063872255489, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6622177', 'n_tokens_mistral': 2032, 'n_tokens_neox': 1601, 'n_words': 534}