this.GoalType = "SMOKEBOMB";
this.Version = 1;
this.DefaultPriority = 0.8;
this.MinRadius = 30;
this.RolePriorityBonus = 0.1;

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

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

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

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

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

this.UpgradeVersion = function(Props)
{
	// version 0 is string,string key/values from the old waypoint format
	if(Props.Version==0)
	{
		// Version 1 Schema, upgrade from waypoint format
		this.Schema.Check(Props);
		Props.Version = 1;
	}
	else if(Props.Version == this.Version)
	{
		this.Schema.Check(Props);
		this.AimVectors = Props.AimVectors;
		this.Stance = Props.Stance;

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

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

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

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

		if(this.ExtraDebugText==null)
		{
			this.ExtraDebugText = "";
			if ( this.Stance )
			{
				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 ( typeId(this.AimVectors) != 6 )
		{
			print(this.GetName(), "no aim vector table" );
			block(0);
		}
		else
		{
			aimPos = goalPos + Vector3(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 = Vector3(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, version",this.Version);
	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;
};

//////////////////////////////////////////////////////////////////////////
global CreateGui = function(object, guidef)
{
};
//////////////////////////////////////////////////////////////////////////
this.HudDisplay = function(window)
{
	this.CreateGuiFromSchema(this.Schema);
};
