this.GoalType = "AIRSTRIKE";
this.Version = 1;
this.DefaultPriority = 0.8;
this.MinRadius = 32;
this.RolePriorityBonus = 0.1;
this.MaxUsers_InUse(1);
this.MaxUsers_InProgress(1);

//////////////////////////////////////////////////////////////////////////

this.Schema = Schema();
this.Schema.AimVectors = Validate.TableOf("vector3").Default({});
this.Schema.Stance = Validate.Enum("stand","crouch").Default("stand");

//////////////////////////////////////////////////////////////////////////

this.InitNewGoal = function()
{
	this.Schema.Check(this);
};

//////////////////////////////////////////////////////////////////////////

this.UpgradeVersion = function(Props)
{
	if(Props.Version == 1)
	{
		this.AimVectors = Props.AimVectors;
		this.Stance = Props.Stance;

		if(!this.Schema.Check(this) || !tableCount(this.AimVectors))
		{
			this.DisableGoal(true);
		}
	}
};

//////////////////////////////////////////////////////////////////////////

this.Render = function(editMode)
{
	offset2 = Vec3(0,0,64);
	trajectory = {};

	while(this.RenderGoal)
	{
		goalBasePos = this.GetPosition();
		goalPos = goalBasePos + offset2;

		if(!this.ExtraDebugText)
		{
			this.ExtraDebugText = format("Stance: %s\n",this.Stance);
		}

		if ( this.Stance == "crouch" )
		{
			stanceOffset = -20;
		}
		else
		{
			stanceOffset = 0;
		}

		this.RenderDefault();

		if(this.IsDisabled())
		{
			DrawLine(goalPos,goalBasePos,COLOR.RED,2);
		}
		else
		{
			DrawLine(goalPos,goalBasePos,COLOR.GREEN,2);
		}

		if (IsTable(this.AimVectors))
		{
			aimPos = goalPos + Vec3(0,0,stanceOffset);
			foreach ( id and face in this.AimVectors )
			{
				tableClear(trajectory);

				DrawArrow(aimPos,aimPos+face*32,COLOR.BLUE,2);
				DrawText3d(aimPos+face*32,ToString(id),COLOR.WHITE,2,textDrawRadius);

				trajectory.Velocity = Vec3(face.x * 1000.0 * 1.1, face.y * 1000.0 * 1.1, face.z * 650.0 * 1.1);
				trajectory.Position = aimPos;
				//trajectory.StopAtHit = true;
				trajectory.TraceBounce = false;
				trajectory.Duration = 30;
				trajectory.Interval = 0.1;

				DrawTrajectory(trajectory,COLOR.WHITE,2);
			}
		}

		sleep(2);
	}
};

//////////////////////////////////////////////////////////////////////////

this.SaveToTable = function(SaveTable)
{
	// save the goal specific properties
	SaveTable.AimVectors = this.AimVectors;
	if (this.Stance!="stand"){ SaveTable.Stance = this.Stance; }
};

//////////////////////////////////////////////////////////////////////////

this.Help = function()
{
	print(this.GoalType,"goal");
	print("Requires:");
	print("		facing - Direction the bot should face");
	print("Optional:");
	print("		stance - stand, crouch");
};

//////////////////////////////////////////////////////////////////////////

this.SetProperty = function(property, value)
{
	switch(property)
	{
		case "facing":
		{
			if ( value == "clearall" || value == "clear" )
			{
				tableClear(this.AimVectors);
			}
			else
			{
				i = ToInt(value);
				if ( typeId(i) == 1)
				{
					// make em add sequentially
					n = tableCount(this.AimVectors);
					if ( i < 0 || i > n )
					{
						i = n;
					}

					playerFace = GetLocalFacing();
					this.AimVectors[ i ] = playerFace;
					print("Facing",i,"set to",playerFace);
				}
				else
				{
					print(this.GoalType, ": Invalid facing index, expecting int");
				}
			}
		}
		case "stance": // crouch, stand, default stand
		{
			if(this.Schema.Stance.CheckPrintErrors(this,value))
			{
				this.Stance = value;
			}
		}
		default:
		{
			print(this.GoalType, ": Invalid property:", property);
		}
	}

	this.ExtraDebugText = null;
};

//////////////////////////////////////////////////////////////////////////

this.HudDisplay = function(window)
{
	this.CreateGuiFromSchema(this.Schema);
};
