// This script is the paththrough version of goal_airstrike
/*
example setup:
global Map =
{
	Airstrike =
	{
		as1 =
		{
			Enabled = true,
			Team = Util.AllTeams, // or (1<<TEAM.AXIS) or (1<<TEAM.ALLIES)
			Facing = Vec3(-0.593,-0.392,0.703), // use this if no goto waypoint. /bot mypos shows facing
			//NoPause = true, // optional: set this if you want them throw while running
			//Waypoint = "spot_r2", // optional: defining this will have them go to given waypoint and then throw a/s
		},
	},

	sometrigger = function(trigger)
	{
		//disable the paththrough a/s
		Map.Airstrike.as1.Enabled = false;
	},
};

this is the command to use of the waypoint for the given example
/bot waypoint_setproperty paththrough Airstrike_PT:as1
*/

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

this.LimitToWeapon(WEAPON.SMOKE_MARKER);

this.OnPathThrough = function(data)
{
	if (this.Bot.GetClass() == CLASS.FIELDOPS) {
		airstrike = Map.Airstrike[data];
		if (airstrike) {
			if(airstrike.Enabled && (airstrike.Team & (1<<this.Bot.GetTeam()))
				&& this.Bot.IsWeaponCharged(WEAPON.SMOKE_MARKER))
			{
				this.airstrike = airstrike;
				return true;
			}
		}
		else {
			print("OnPathThrough no airstrike", data);
		}
	}

	return false;
};

this.Update = function()
{
	airstrike = this.airstrike;

	if (airstrike.Waypoint) {
		wp = Util.WpNameInfo(airstrike.Waypoint);
		facing = wp.facing;

		if(!wp.position || this.Goto(wp.position) == EVENT.PATH_FAILED) {
			this.Finished();
		}
	}
	else {
		facing = airstrike.Facing;
		assert(facing);

		if (!airstrike.NoPause) {
			this.Goto(this.Bot.GetPosition());
		}
	}

	this.AddAimRequest(Priority.High, "facing", facing * 1024);
	this.AddWeaponRequest(WEAPON.SMOKE_MARKER);
	this.BlockForWeaponChange(WEAPON.SMOKE_MARKER);
	this.Bot.HoldButton(BTN.ATTACK1, 0.5);
	sleep(1);
	this.Finished();
};
