this.GoalType = "CALLARTILLERY";
this.Version = 1;
this.DefaultPriority = 0.8;
this.MinRadius = 32;
this.DefaultMinCampTime = 2;
this.DefaultMaxCampTime = 6;
this.RolePriorityBonus = 0.1;
this.MaxUsers_InUse(1);
this.MaxUsers_InProgress(1);

//////////////////////////////////////////////////////////////////////////
// Couple callbacks to enforce additional constraints on property values.
CheckMinCamp = function(var)
{
	if(var <= this.MaxCampTime)
	{
		return true;
	}
	// returning any string is an error string
	return "MinCampTime must be <= MaxCampTime";
};
CheckMaxCamp = function(var)
{
	if(var >= this.MinCampTime)
	{
		return true;
	}
	// returning any string is an error string
	return "MaxCampTime must be >= MinCampTime";
};

this.Schema = Schema();
this.Schema.Stance = Validate.Enum("stand","crouch","prone").Default("stand");
this.Schema.MinCampTime = Validate.NumRange(0,90).Default(this.DefaultMinCampTime).CheckCallback(CheckMinCamp);
this.Schema.MaxCampTime = Validate.NumRange(0,90).Default(this.DefaultMaxCampTime).CheckCallback(CheckMaxCamp);

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

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

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

this.UpgradeVersion = function(Props)
{
	if(Props.Version==0)
	{
		// upgrade from old waypoint format
		Props.Version = 1;
		this.SetPosition(this.GetPosition() + Util.WaypointGoalOffset);
	}
	else if(Props.Version == 1)
	{
		this.Stance = Props.Stance;
		this.MinCampTime = Props.MinCampTime;
		this.MaxCampTime = Props.MaxCampTime;

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

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

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

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

		if(!this.ExtraDebugText)
		{
			this.ExtraDebugText = format("Stance: %s\nCampTime: %g to %g secs.", this.Stance, ToFloat(this.MinCampTime),ToFloat(this.MaxCampTime));
		}

		this.RenderDefault();

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

		sleep(2);
	}
};

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

this.SaveToTable = function(SaveTable)
{
	// save the goal specific properties
	if (!IsInt(Map.SaveCampTime) || Map.SaveCampTime)
	{
		if(this.MaxCampTime != this.DefaultMaxCampTime){ SaveTable.MaxCampTime = this.MaxCampTime; }
		if(this.MinCampTime != this.DefaultMinCampTime){ SaveTable.MinCampTime = this.MinCampTime; }
	}
};

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

this.Help = function()
{
	print(this.GoalType,"goal");
	print("Optional:");
	print("		mincamptime - minimum time a bot should camp at the goal");
	print("		maxcamptime - maximum time a bot should camp at the goal");
};

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

this.SetProperty = function(property, value)
{
	switch(property)
	{
		case "stance": // crouch, stand, default stand
		{
			this.Stance = value;
		}
		case "mincamptime":
		{
			v = ToFloat(value);
			if(this.Schema.MinCampTime.CheckPrintErrors(this,v))
			{
				this.MinCampTime = v;
			}
		}
		case "maxcamptime":
		{
			v = ToFloat(value);
			if(this.Schema.MaxCampTime.CheckPrintErrors(this,v))
			{
				this.MaxCampTime = v;
			}
		}
		default:
		{
			print(this.GoalType, ": Invalid property:", property);
		}
	}

	this.ExtraDebugText = null;
};

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

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