
--
-- Copyright (C) 2019  <fastrgv@gmail.com>
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-- GNU General Public License for more details.
--
-- You may read the full text of the GNU General Public License
-- at <http://www.gnu.org/licenses/>.
--



separate (avent)


procedure setup_maze6 is 
--   scene #   6 (exit + 2 below)

	zar,zac,
	yr,yc, xr,xc, zr,zc: float;
	hwdoor : constant float := 0.8; --halfWidth
	fhdoor : constant float := 1.8; --fullHeight

begin

	-- define initial location of portable gate
	sgate:=6;  --scene#
	rgate:=-2; --row
	cgate:=+5; --col
	gateheld:=false;

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

	--walls
	droomobj.setroomwithZPdoor( mdo6,
		hwdoor, fhdoor,
		0.0, 0.0, 0.0,
		ixmax,iymax,izmax-0.01,
		ixmax/2.0,iymax,izmax/2.0); --scaled for 16 mirrored copies each wall



	--floor (grass covered)
	rectobj.setrect( 
		mfloor, 
		0.0, -iymax+0.01, 0.0, --xc,yc,zc
		ixmax, 0.0, izmax, --xr,yr,zr
		j1,j2,j3,j4,j5,j6);



-- begin maze walls => x,z within [-10,+10]

	yr:=0.3; -- 0.3 *2  is high enough
	yc:=-iymax+yr;
	xr:=0.5;
	zr:=0.5;
---------------------------------begin maze def

	for row in -mrows..mrows loop
	for col in -mcols..mcols loop
		if iswall(6,row,col) then

			xc:=float(row);
			zc:=float(col);

			--assure that maze does NOT intrude
			--into Leonidas' Temple
			if zc+zr>izmax then
				zar := (izmax-(zc-zr))*0.5;
				zac := (izmax+(zc-zr))*0.5;
			else
				zar:=zr;
				zac:=zc;
			end if;


			nko:=nko+1;
			koscene(nko):=6;
			pictobj.setrect( mzwall(6,row,col), 
				xc,yc,zac,  xr,yr,zar,
					koxlo(nko),koxhi(nko), koylo(nko),
						koyhi(nko), kozlo(nko),kozhi(nko) );

			korow(nko):=row;
			kocol(nko):=col;
			mazewall(nko):=true;


			if 6=sgate and row=rgate and col=cgate then --(r,c)=(-2,5)
				insertgate(nko);
				insertable:=0;
				--"insert" moveable gate here
			end if;


		end if;
	end loop; --col
	end loop; --row

---------------------------------end maze def








----------- begin exit-to-temple door --------------------------------

	xtmpl:=0.0; --ixmax;
	ytmpl:=iymaze;
	ztmpl:=izmax;

   -- lift-open-lion-door
	xlion:=xtmpl; --ixmax-0.3;
	zlion:=ztmpl-0.3; --izmax-0.3;
	ylion:=ytmpl; --ymaze;
	nko:=nko+1;
	koscene(nko):=6;
	lko:=nko;
	pictobj.setrect( 
		dungdoor,
		xlion, ylion, zlion,
		hwdoor-0.05, fhdoor/2.0, 0.05,
		koxlo(lko),koxhi(lko),koylo(lko),
		koyhi(lko),kozlo(lko),kozhi(lko) );


-- marble top
	pictobj.setrect( 
		beam12,
		xtmpl, ytmpl+fhdoor/2.0, ztmpl-0.3,
		hwdoor+0.6, 0.3, 0.3,
		j1,j2,j3,j4,j5,j6);

-- need frame for temple entrance...
-- 2 cylindrical marble pillars with flat b crossbeam
-- centered at 
-- (ixmax, izmax-1.5*wdoor)
-- (ixmax-1.5*wdoor, izmax)

	nko:=nko+1;
	koscene(nko):=6;
	cylobj.setcyl(
		pillar1,
		xtmpl-hwdoor-0.2, ytmpl, ztmpl-0.3,
		fhdoor/2.0, 0.25,
		koxlo(nko),koxhi(nko), koylo(nko),
		koyhi(nko), kozlo(nko),kozhi(nko) );

	nko:=nko+1;
	koscene(nko):=6;
	cylobj.setcyl(
		pillar2,
		xtmpl+hwdoor+0.2, ytmpl, ztmpl-0.3,
		fhdoor/2.0, 0.25,
		koxlo(nko),koxhi(nko), koylo(nko),
		koyhi(nko), kozlo(nko),kozhi(nko) );


----------- end exit-to-temple door --------------------------------









-- setup ceiling for fancy fragshader:
rectxobj.setrect(rox,0.0,iymax-0.01,0.0, ixmax,0.01,izmax);
-- no texture needed here;  fancy fragshader used instead
	
--------------------------------------------------------


	--A1
	pictobj.setrect( 
		doora1,
		10.0-eps, iymaze, 9.0,
		0.0, fhdoor/2.0, hwdoor,
		j1,j2,j3,j4,j5,j6);

	--B1
	pictobj.setrect( 
		doorb1,
		10.0-eps, iymaze, 4.0,
		0.0, fhdoor/2.0, hwdoor,
		j1,j2,j3,j4,j5,j6);

	--V6
	pictobj.setrect( 
		doorv6,
		10.0-eps, iymaze, 2.0,
		0.0, fhdoor/2.0, hwdoor,
		j1,j2,j3,j4,j5,j6);

	--W6
	pictobj.setrect( 
		doorw6,
		10.0-eps, iymaze, 0.0,
		0.0, fhdoor/2.0, hwdoor,
		j1,j2,j3,j4,j5,j6);

	--X6
	pictobj.setrect( 
		doorx6,
		10.0-eps, iymaze,-2.0,
		0.0, fhdoor/2.0, hwdoor,
		j1,j2,j3,j4,j5,j6);

	--Y6
	pictobj.setrect( 
		doory6,
		10.0-eps, iymaze,-4.0,
		0.0, fhdoor/2.0, hwdoor,
		j1,j2,j3,j4,j5,j6);

	--Z6
	pictobj.setrect( 
		doorz6,
		10.0-eps, iymaze,-9.0,
		0.0, fhdoor/2.0, hwdoor,
		j1,j2,j3,j4,j5,j6);

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

	--C6
	pictobj.setrect( 
		doorc6,
		-10.0+eps, iymaze, 9.0,
		0.0, fhdoor/2.0, hwdoor,
		j1,j2,j3,j4,j5,j6);

	--D6
	pictobj.setrect( 
		doord6,
		-10.0+eps, iymaze, 4.0,
		0.0, fhdoor/2.0, hwdoor,
		j1,j2,j3,j4,j5,j6);

	--E6
	pictobj.setrect( 
		doore6,
		-10.0+eps, iymaze, 2.0,
		0.0, fhdoor/2.0, hwdoor,
		j1,j2,j3,j4,j5,j6);

	--F6
	pictobj.setrect( 
		doorf6,
		-10.0+eps, iymaze, 0.0,
		0.0, fhdoor/2.0, hwdoor,
		j1,j2,j3,j4,j5,j6);

	--G6
	pictobj.setrect( 
		doorg6,
		-10.0+eps, iymaze,-2.0,
		0.0, fhdoor/2.0, hwdoor,
		j1,j2,j3,j4,j5,j6);

	--A2
	pictobj.setrect( 
		doora2,
		-10.0+eps, iymaze,-4.0,
		0.0, fhdoor/2.0, hwdoor,
		j1,j2,j3,j4,j5,j6);

	--B2
	pictobj.setrect( 
		doorb2,
		-10.0+eps, iymaze,-9.0,
		0.0, fhdoor/2.0, hwdoor,
		j1,j2,j3,j4,j5,j6);


end setup_maze6;



