-------------------------------------------------------
------- Initialise any globals for these functions ----
-------------------------------------------------------


-------------------------------------------------------
------- AuctionIntroCam function ----------------------
-------------------------------------------------------
function EVENTINITIALISE_AuctionIntroCamera()
	-- the auction camera consists of three cameras one after another
	intro_camnum = 1;	-- was 3 -- KAT 19/01/01 keeps a record of which camera to be running
	first_time = 1;		-- tells the sub cameras that this is the first time they are being run, 
						-- so they can initialise
	bezu = 0;			-- used to control bezier progression
	maxspeed = 0.1;		-- sets the maxspeed of the camera movement along the bezier path
	speed = 0.01;		-- current speed along bezier path
	acceleration = 0;	-- change in speed
	Camera.SetMode(FREECAM); -- set the camera mode to one we can control
	Camera.posinertia = FALSE;	-- set up initial camera variables
	Camera.targinertia = FALSE;
	Camera.inertiavalue = 1;
end;

function EVENT_AuctionIntroCamera()
	if intro_camnum == 3 then
		if LUA_AuctionIntro1() == 0 then 
			intro_camnum = intro_camnum - 1 
		end;
	end;
	if intro_camnum == 2 then
		if LUA_AuctionIntro2() == 0 then 
			intro_camnum = intro_camnum - 1 
		end;
	end;

	if intro_camnum == 1 then
		return LUA_AuctionIntroFinal();
	end;
	return 1;
end;

function LUA_AuctionIntro1()

	if firsttime == 1 then
		firsttime = 0;	-- switch it off
		maxspeed = 0.005;
		speed = 0.0000000000000001;
		acceleration = 0.0001;

		Camera.SetPositionPath	-- call c function to create position path
		(0.6,	4.8,	33,
		11,	10.4,	12.3,
		11,	10.4,	12.3,
		11,	10.4,	12.3);

		Camera.SetLookatPath	-- call c function to create lookat path
		(-15,	0.8,	131.8,
		-25.9,	7.4,	105.2,
		-25.9,	7.4,	105.2,
		-25.9,	7.4,	105.2);
	end;

	Camera.BezCalcPosition(bezu);	-- call c function to update camera position based on bezier path
	Camera.BezCalcLookat(bezu);	-- call c function to update camera lookat based on bezier path
	bezu = bezu + speed;			-- update bezu ( position along bezier curve from 0 to 1 )
	speed = speed + acceleration;	-- update speed
	if speed > maxspeed then		-- make sure we haven't gone over maxspeed
		speed = maxspeed;			-- if we have, then clamp
	end;

	if bezu > 1 then				-- test to see if we have reached the end of the curve
		firsttime = 1;				-- rest first time, for the next camera
		return 0;					-- return 0 to the calling function to let it know this camera is done
	else
		return 1;					-- return 1 to the calling 
	end;
end;

function LUA_AuctionIntro2()

	if firsttime == 1 then
		firsttime = 0;
		bezu = 0;
		speed = 0.003;
		acceleration = 0;

		Camera.SetPositionPath
		(-5,	4.7,	39.5,
	     -2,	4.7,	40,
		5.8,	4.7,	37.5,
		8.2,	3.7,	31.1);

		Camera.SetLookatPath
		(7.7,	-17.2,	-62.2,
		-5.1,	-12.2,	-62.8,
		-33.1,	-16.2,	-57.5,
		-61.7,	-14.2,	-44.1);
	end;
	
	Camera.BezCalcPosition(bezu);
	Camera.BezCalcLookat(bezu);
	bezu = bezu + speed;
	speed = speed + acceleration;
	if speed > maxspeed then
		speed = maxspeed;
	end;

	if bezu > 1 then
		firsttime = 1;
		return 0;	
	else
		return 1;
	end;
end;

function LUA_AuctionIntroFinal()
	Camera.x,	Camera.y,	Camera.z = Camera.GetActorPosition(0);
	Camera.x =	Camera.x - 1;
	Camera.y =	Camera.y + 5;
	Camera.z =	Camera.z + 5;
	Camera.lx,	Camera.ly,	Camera.lz = Camera.GetActorPosition(0);
	Camera.lx = Camera.lx - 0.5;
	Camera.ly = 2;
	Camera.lz = Camera.lz - 12;
	return 0;
end;


-------------------------------------------------------
-------------------------------------------------------
-------------------------------------------------------
