// kd: Idea is same as Stan's acs, but apparently I go my own way finding the
// rotated ellipse axes.

// Usage is pretty straight forward. If you want angle and pitch of your actor
// to determine the shockwave orientation, do Orient(angle, pitch).

// Note this will respect spawn angle and pitch on the ellipse, too.

// Ownership is transferred by default over the spawned actor's master field.

class Gc_TestWave : Gc_ShockwavePattern {
	states {
	spawn:
		TNT1 A 0 nodelay Orient(random(0, 359), random(-90, 90));
		TNT1 A 0 SpawnShock("Fatshot", 25, 25, 25);
		stop;
	}
}

class Gc_ShockwavePattern : Actor {
	private Gc_TiltedRing local_sys;
	
	// kd: You'll call this once or whenever you think the angle changed, so
	// as to set up the axes. Then you call SpawnShock how ever often you like.
	
	// kd: Also derpy thin wrapper after changing local coordinate handling, hu.
	void Orient (float ang, float vang) {
		local_sys.Orient(ang, vang);
	}
	
	void SpawnShock (
		name spawn_type, uint count,
		float forw_vel, float right_vel, int aaptr_owner = AAPTR_MASTER) {
		
		count = max(1, count);
		float ang_inv = 360.0f / count;
		float tang = 0;
		Actor ptr_type = GetPointer(aaptr_owner);
		
		for(int i = 0; i < count; i++) {
			vector3 spawn_vel =local_sys.EllipticPos(tang, forw_vel, right_vel);
			
			Actor mobj = Spawn(spawn_type, pos);
			
			if(mobj) {
				mobj.vel = spawn_vel;
				mobj.target = ptr_type;
				mobj.angle = atan2(spawn_vel.y, spawn_vel.x);
				mobj.pitch = atan2(spawn_vel.z, spawn_vel.xy.length());
			}
			
			tang += ang_inv;
		}
	}
}