// This script is a generic paththrough goal that allows map scripts to define specific behaviors

this.Name = "Navigation_PT";
this.Parent = "LowLevel";		// PathThrough states must be low level or they will not be used.

this.Initialize = function()
{
	if (!Map.Navigation) {
		Map.Navigation = {};
	}
};

this.OnPathThrough = function(data)
{
	navigation = Map.Navigation[data];
	if (navigation)
	{
		f = navigation.EvalFunc;
		if (f && this:f(this) == false) {
			return false;  // script will not activate
		}
		this.CurrentNavigation = data; //some map scripts need it
		this.navigation = navigation;
		return true;
	}
	print("^1OnPathThrough no navigation table", data);
	Map.Navigation[data] = {};
	return false;
};

this.Exit = function()
{
	f = this.navigation.OnExit;
	if (f) {
		this:f(this);
	}
};

this.Update = function()
{
	navigation = this.navigation;
	if (navigation.gotowp) {
		if (navigation.wpinfo == null) {
			navigation.wpinfo = Util.WpNameInfo(navigation.gotowp);
		}
		if (navigation.wpinfo && this.Goto(navigation.wpinfo.position) == EVENT.PATH_FAILED) {
			this.Finished();
		}
	}
	f = navigation.navigate;
	if (f) {
		this:f(this);
	}

	this.Finished();
};
