
#include <exec/types.h>
#include <inline/wild.h>
#include <inline/exec.h>
#include <inline/dos.h>
#include <wild/wild.h>
#include <wild/tdcore.h>
#include <exec/execbase.h>
#include <gcc/compiler.h>
#include <utility/hooks.h>
#include <gcc/debug.h>
#include <debugoutput.h>

extern struct WildBase 	*WildBase;
extern struct WildScene	*KubeScene;
extern struct WildApp	*KubeApp;
extern	ULONG		*debugfh;

struct	WildSector	*KubeSector;

#define DOSBase		WildBase->wi_DOSBase

static const char	tiger_chu[]=	{"images/tiger.chu\0"};
static const char	eagle_chu[]=	{"images/eagle.chu\0"};
static const char	py_chu[]=	{"images/py.chu\0"};
static const char	wild_chu[]=	{"images/wild.chu\0"};
static const char	sunset_chu[]=	{"images/sunset.chu\0"};
static const char	canyon_chu[]=	{"images/canyon.chu\0"};

static const char	tiger_pal[]=	{"images/tiger.pal\0"};
static const char	eagle_pal[]=	{"images/eagle.pal\0"};
static const char	py_pal[]=	{"images/py.pal\0"};
static const char	wild_pal[]=	{"images/wild.pal\0"};
static const char	sunset_pal[]=	{"images/sunset.pal\0"};
static const char	canyon_pal[]=	{"images/canyon.pal\0"};
static const char	kube_pal[]=	{"images/kube.pal\0"};

void	KubeTextureHook(LIB_FCT(struct WildTexture,*tex,a2),LIB_FCT(ULONG,action,a1),LIB_FCT(struct Hook,*hook,a0))
{
 switch (action)
  {
   case TEXACTION_Load:
    {
     tex->tex_Raw=LoadFile(NULL,hook->h_Data);
     break;
    }
   case TEXACTION_Free:
    {
     FreeVecPooled(tex->tex_Raw);
     break;
    }
  }
}

void InitScene()
{
 static ULONG	normal[]={	0,0,0,
 				1<<16,0,0,
 				0,1<<16,0,
 				0,0,1<<16};	// normal ref in O(0,0,0)
 static ULONG	camera[]={	0,0,-200,
 				1<<16,0,0,
 				0,1<<16,0,
 				0,0,1<<16};	// normal ref in O(0,0,-200)
 static ULONG	pointA[]={	 100, 100,-100};
 static ULONG	pointB[]={	 100, 100, 100};
 static ULONG	pointC[]={	-100, 100, 100};
 static ULONG	pointD[]={	-100, 100,-100};
 static ULONG	pointE[]={	 100,-100,-100};
 static ULONG	pointF[]={	 100,-100, 100};
 static ULONG	pointG[]={	-100,-100, 100};
 static ULONG	pointH[]={	-100,-100,-100};
 static ULONG	pointLight[]={	 200,-150, -10};
 
 static ULONG	hook[]={	0,0,&KubeTextureHook,0,0};

 static ULONG 	*world,*arena,*alien,*pa,*pb,*pc,*pd,*pe,*pf,*pg,*ph,
	 	*ea,*eb,*ec,*ed,*ee,*ef,*eg,*eh,*ei,*ej,*ek,*el,*em,*en,*eo,*ep,*eq,*er,
	 	*fa,*fb,*fc,*fd,*fe,*ff,*fg,*fh,*fi,*fj,*fk,*fl,
	 	*tiger,*eagle,*py,*wild,*sunset,*canyon,
	 	*tiger_palette,*eagle_palette,*py_palette,*wild_palette,*sunset_palette,*canyon_palette,*kube_palette,
	 	*light,*lightsector,*lightpoint;

 kube_palette=LoadFile(NULL,tiger_pal);
DebugOut("Loaded kube palette.\n\0");
 if (KubeScene=BuildWildObjectTags(	WIBU_ObjectType,BUILD_Scene,
 					WIBU_BuildObject,TRUE,
 					WIBU_WildApp,KubeApp,
 					WIBU_Palette,kube_palette,
 					WIBU_Ref,&camera,0,0))
  {
DebugOut("Made scene.\n\0");
   if (world=BuildWildObjectTags(	WIBU_ObjectType,BUILD_World,
   					WIBU_BuildObject,TRUE,
   					WIBU_WildApp,KubeApp,
   					WIBU_Parent,KubeScene,0,0))
    {
DebugOut("Made world.\n\0");
     if (arena=BuildWildObjectTags(	WIBU_ObjectType,BUILD_Arena,
     					WIBU_BuildObject,TRUE,
     					WIBU_WildApp,KubeApp,
     					WIBU_Parent,world,
     					WIBU_Ref,&normal,0,0))
      {
DebugOut("Made arena.\n\0");
       if (alien=BuildWildObjectTags(	WIBU_ObjectType,BUILD_Alien,
       					WIBU_BuildObject,TRUE,
       					WIBU_WildApp,KubeApp,
       					WIBU_Parent,arena,
       					WIBU_Ref,&normal,0,0))
        {
DebugOut("Made alien.\n\0");
         if (KubeSector=BuildWildObjectTags(WIBU_ObjectType,BUILD_Sector,
         				WIBU_BuildObject,TRUE,
         				WIBU_WildApp,KubeApp,
         				WIBU_Parent,alien,
         				WIBU_Alien,alien,
         				WIBU_Ref,&normal,0,0))
          {
DebugOut("Made KubeSector.\n\0");
           pa=BuildWildObjectTags(	WIBU_ObjectType,BUILD_Point,
           				WIBU_BuildObject,TRUE,
           				WIBU_WildApp,KubeApp,
           				WIBU_Parent,KubeSector,
           				WIBU_Color,0xff0000,
           				WIBU_Vek,&pointA,0,0);	// No more checking!! Boring !!

           pb=BuildWildObjectTags(	WIBU_ObjectType,BUILD_Point,
           				WIBU_BuildObject,TRUE,
           				WIBU_WildApp,KubeApp,
           				WIBU_Parent,KubeSector,
           				WIBU_Color,0xff0000,
           				WIBU_Vek,&pointB,0,0);	// No more checking!! Boring !!
           			
           pc=BuildWildObjectTags(	WIBU_ObjectType,BUILD_Point,
           				WIBU_BuildObject,TRUE,
           				WIBU_WildApp,KubeApp,
           				WIBU_Parent,KubeSector,
           				WIBU_Color,0xff0000,
           				WIBU_Vek,&pointC,0,0);	// No more checking!! Boring !!

           pd=BuildWildObjectTags(	WIBU_ObjectType,BUILD_Point,
           				WIBU_BuildObject,TRUE,
           				WIBU_WildApp,KubeApp,
           				WIBU_Parent,KubeSector,
           				WIBU_Color,0xff0000,
           				WIBU_Vek,&pointD,0,0);	// No more checking!! Boring !!

           pe=BuildWildObjectTags(	WIBU_ObjectType,BUILD_Point,
           				WIBU_BuildObject,TRUE,
           				WIBU_WildApp,KubeApp,
           				WIBU_Parent,KubeSector,
           				WIBU_Color,0xff0000,
           				WIBU_Vek,&pointE,0,0);	// No more checking!! Boring !!

           pf=BuildWildObjectTags(	WIBU_ObjectType,BUILD_Point,
           				WIBU_BuildObject,TRUE,
           				WIBU_WildApp,KubeApp,
           				WIBU_Parent,KubeSector,
           				WIBU_Color,0xff0000,
           				WIBU_Vek,&pointF,0,0);	// No more checking!! Boring !!

           pg=BuildWildObjectTags(	WIBU_ObjectType,BUILD_Point,
           				WIBU_BuildObject,TRUE,
           				WIBU_WildApp,KubeApp,
           				WIBU_Parent,KubeSector,
           				WIBU_Color,0xff0000,
           				WIBU_Vek,&pointG,0,0);	// No more checking!! Boring !!

           ph=BuildWildObjectTags(	WIBU_ObjectType,BUILD_Point,
           				WIBU_BuildObject,TRUE,
           				WIBU_WildApp,KubeApp,
           				WIBU_Parent,KubeSector,
           				WIBU_Color,0xff0000,
           				WIBU_Vek,&pointH,0,0);

DebugOut("Made points. :)\n\0");

           lightsector=BuildWildObjectTags(WIBU_ObjectType,BUILD_Sector,
         				WIBU_BuildObject,TRUE,
         				WIBU_WildApp,KubeApp,
         				WIBU_Parent,arena,
         				WIBU_Alien,arena,
         				WIBU_Ref,&normal,0,0);
         				
           lightpoint=BuildWildObjectTags(WIBU_ObjectType,BUILD_Point,
           				WIBU_BuildObject,TRUE,
           				WIBU_WildApp,KubeApp,
           				WIBU_Parent,lightsector,
           				WIBU_Vek,&pointLight,0,0);

	   light=BuildWildObjectTags(	WIBU_ObjectType,BUILD_Light,
	   				WIBU_BuildObject,TRUE,
	   				WIBU_WildApp,KubeApp,
	   				WIBU_Parent,arena,
	   				WIBU_Color,0xffffff,
	   				WIBU_Intensity,203,
	   				WIBU_PointA,lightpoint,0,0);

DebugOut("Made light and his own sector.\n\0");
 

	   ea=BuildWildObjectTags(	WIBU_ObjectType,BUILD_Edge,
	   				WIBU_BuildObject,TRUE,
	   				WIBU_WildApp,KubeApp,
	   				WIBU_Parent,KubeSector,
	   				WIBU_PointA,pa,
	   				WIBU_PointB,pd,0,0);
	   				
	   eb=BuildWildObjectTags(	WIBU_ObjectType,BUILD_Edge,
	   				WIBU_BuildObject,TRUE,
	   				WIBU_WildApp,KubeApp,
	   				WIBU_Parent,KubeSector,
	   				WIBU_PointA,pa,
	   				WIBU_PointB,pb,0,0);

	   ec=BuildWildObjectTags(	WIBU_ObjectType,BUILD_Edge,
	   				WIBU_BuildObject,TRUE,
	   				WIBU_WildApp,KubeApp,
	   				WIBU_Parent,KubeSector,
	   				WIBU_PointA,pb,
	   				WIBU_PointB,pc,0,0);

	   ed=BuildWildObjectTags(	WIBU_ObjectType,BUILD_Edge,
	   				WIBU_BuildObject,TRUE,
	   				WIBU_WildApp,KubeApp,
	   				WIBU_Parent,KubeSector,
	   				WIBU_PointA,pc,
	   				WIBU_PointB,pd,0,0);

	   ee=BuildWildObjectTags(	WIBU_ObjectType,BUILD_Edge,
	   				WIBU_BuildObject,TRUE,
	   				WIBU_WildApp,KubeApp,
	   				WIBU_Parent,KubeSector,
	   				WIBU_PointA,pe,
	   				WIBU_PointB,ph,0,0);

	   ef=BuildWildObjectTags(	WIBU_ObjectType,BUILD_Edge,
	   				WIBU_BuildObject,TRUE,
	   				WIBU_WildApp,KubeApp,
	   				WIBU_Parent,KubeSector,
	   				WIBU_PointA,pe,
	   				WIBU_PointB,pf,0,0);

	   eg=BuildWildObjectTags(	WIBU_ObjectType,BUILD_Edge,
	   				WIBU_BuildObject,TRUE,
	   				WIBU_WildApp,KubeApp,
	   				WIBU_Parent,KubeSector,
	   				WIBU_PointA,pf,
	   				WIBU_PointB,pg,0,0);

	   eh=BuildWildObjectTags(	WIBU_ObjectType,BUILD_Edge,
	   				WIBU_BuildObject,TRUE,
	   				WIBU_WildApp,KubeApp,
	   				WIBU_Parent,KubeSector,
	   				WIBU_PointA,pg,
	   				WIBU_PointB,ph,0,0);

	   ei=BuildWildObjectTags(	WIBU_ObjectType,BUILD_Edge,
	   				WIBU_BuildObject,TRUE,
	   				WIBU_WildApp,KubeApp,
	   				WIBU_Parent,KubeSector,
	   				WIBU_PointA,pa,
	   				WIBU_PointB,pe,0,0);

	   ej=BuildWildObjectTags(	WIBU_ObjectType,BUILD_Edge,
	   				WIBU_BuildObject,TRUE,
	   				WIBU_WildApp,KubeApp,
	   				WIBU_Parent,KubeSector,
	   				WIBU_PointA,pf,
	   				WIBU_PointB,pb,0,0);

	   ek=BuildWildObjectTags(	WIBU_ObjectType,BUILD_Edge,
	   				WIBU_BuildObject,TRUE,
	   				WIBU_WildApp,KubeApp,
	   				WIBU_Parent,KubeSector,
	   				WIBU_PointA,pg,
	   				WIBU_PointB,pc,0,0);

	   el=BuildWildObjectTags(	WIBU_ObjectType,BUILD_Edge,
	   				WIBU_BuildObject,TRUE,
	   				WIBU_WildApp,KubeApp,
	   				WIBU_Parent,KubeSector,
	   				WIBU_PointA,ph,
	   				WIBU_PointB,pd,0,0);

	   em=BuildWildObjectTags(	WIBU_ObjectType,BUILD_Edge,
	   				WIBU_BuildObject,TRUE,
	   				WIBU_WildApp,KubeApp,
	   				WIBU_Parent,KubeSector,
	   				WIBU_PointA,pe,
	   				WIBU_PointB,pg,0,0);

	   en=BuildWildObjectTags(	WIBU_ObjectType,BUILD_Edge,
	   				WIBU_BuildObject,TRUE,
	   				WIBU_WildApp,KubeApp,
	   				WIBU_Parent,KubeSector,
	   				WIBU_PointA,pe,
	   				WIBU_PointB,pb,0,0);

	   eo=BuildWildObjectTags(	WIBU_ObjectType,BUILD_Edge,
	   				WIBU_BuildObject,TRUE,
	   				WIBU_WildApp,KubeApp,
	   				WIBU_Parent,KubeSector,
	   				WIBU_PointA,pb,
	   				WIBU_PointB,pd,0,0);

	   ep=BuildWildObjectTags(	WIBU_ObjectType,BUILD_Edge,
	   				WIBU_BuildObject,TRUE,
	   				WIBU_WildApp,KubeApp,
	   				WIBU_Parent,KubeSector,
	   				WIBU_PointA,pd,
	   				WIBU_PointB,ph,0,0);

	   eq=BuildWildObjectTags(	WIBU_ObjectType,BUILD_Edge,
	   				WIBU_BuildObject,TRUE,
	   				WIBU_WildApp,KubeApp,
	   				WIBU_Parent,KubeSector,
	   				WIBU_PointA,pf,
	   				WIBU_PointB,pc,0,0);

	   er=BuildWildObjectTags(	WIBU_ObjectType,BUILD_Edge,
	   				WIBU_BuildObject,TRUE,
	   				WIBU_WildApp,KubeApp,
	   				WIBU_Parent,KubeSector,
	   				WIBU_PointA,pe,
	   				WIBU_PointB,pd,0,0);
DebugOut("Made edges.\n\0");

	   hook[4]=&eagle_chu;
	   eagle_palette=LoadFile(NULL,eagle_pal);
	   eagle=BuildWildObjectTags(	WIBU_ObjectType,BUILD_Texture,
	   				WIBU_BuildObject,TRUE,
	   				WIBU_WildApp,KubeApp,
					WIBU_TexHook,hook,		//check
					WIBU_InitTexture,TRUE,
					WIBU_Palette,eagle_palette,
					WIBU_Width,256,
					WIBU_Height,256,0,0);
					
	   hook[4]=&py_chu;
	   py_palette=LoadFile(NULL,py_pal);
	   py=BuildWildObjectTags(	WIBU_ObjectType,BUILD_Texture,
	   				WIBU_BuildObject,TRUE,
	   				WIBU_WildApp,KubeApp,
					WIBU_TexHook,hook,		//check
					WIBU_InitTexture,TRUE,
					WIBU_Palette,py_palette,
					WIBU_Width,256,
					WIBU_Height,256,0,0);

	   hook[4]=&wild_chu;
	   wild_palette=LoadFile(NULL,wild_pal);
	   wild=BuildWildObjectTags(	WIBU_ObjectType,BUILD_Texture,
	   				WIBU_BuildObject,TRUE,
	   				WIBU_WildApp,KubeApp,
					WIBU_TexHook,hook,		//check
					WIBU_InitTexture,TRUE,
					WIBU_Palette,wild_palette,
					WIBU_Width,256,
					WIBU_Height,256,0,0);

	   hook[4]=&sunset_chu;
	   sunset_palette=LoadFile(NULL,sunset_pal);
	   sunset=BuildWildObjectTags(	WIBU_ObjectType,BUILD_Texture,
	   				WIBU_BuildObject,TRUE,
	   				WIBU_WildApp,KubeApp,
					WIBU_TexHook,hook,		//check
					WIBU_InitTexture,TRUE,
					WIBU_Palette,sunset_palette,
					WIBU_Width,256,
					WIBU_Height,256,0,0);

	   hook[4]=&canyon_chu;
	   canyon_palette=LoadFile(NULL,canyon_pal);
	   canyon=BuildWildObjectTags(	WIBU_ObjectType,BUILD_Texture,
	   				WIBU_BuildObject,TRUE,
	   				WIBU_WildApp,KubeApp,
					WIBU_TexHook,hook,		//check
					WIBU_InitTexture,TRUE,
					WIBU_Palette,canyon_palette,
					WIBU_Width,256,
					WIBU_Height,256,0,0);
					
	   hook[4]=&tiger_chu;
	   tiger_palette=LoadFile(NULL,tiger_pal);
	   tiger=BuildWildObjectTags(	WIBU_ObjectType,BUILD_Texture,
	   				WIBU_BuildObject,TRUE,
	   				WIBU_WildApp,KubeApp,
					WIBU_TexHook,hook,		//check
					WIBU_InitTexture,TRUE,
					WIBU_Palette,tiger_palette,
					WIBU_Width,256,
					WIBU_Height,256,0,0);
DebugOut("Loaded texture and palettes.\n\0");
	   
	   fa=BuildWildObjectTags(	WIBU_ObjectType,BUILD_Face,
	   				WIBU_BuildObject,TRUE,
	   				WIBU_WildApp,KubeApp,
	   				WIBU_Parent,KubeSector,
	   				WIBU_PointA,pe,
	   				WIBU_PointB,pa,
	   				WIBU_PointC,pd,
	   				WIBU_EdgeA,ei,
	   				WIBU_EdgeB,er,
	   				WIBU_EdgeC,ea,
	   				WIBU_Texture,tiger,
	   				WIBU_TxA,255,
	   				WIBU_TyA,0,
	   				WIBU_TxB,255,
	   				WIBU_TyB,255,
	   				WIBU_TxC,0,
	   				WIBU_TyC,255,
	   				WIBU_Flags,0,0,0);

	   fb=BuildWildObjectTags(	WIBU_ObjectType,BUILD_Face,
	   				WIBU_BuildObject,TRUE,
	   				WIBU_WildApp,KubeApp,
	   				WIBU_Parent,KubeSector,
	   				WIBU_PointA,ph,
	   				WIBU_PointB,pe,
	   				WIBU_PointC,pd,
	   				WIBU_EdgeA,el,
	   				WIBU_EdgeB,ee,
	   				WIBU_EdgeC,er,
	   				WIBU_Texture,tiger,
	   				WIBU_TxA,0,
	   				WIBU_TyA,0,
	   				WIBU_TxB,255,
	   				WIBU_TyB,0,
	   				WIBU_TxC,0,
	   				WIBU_TyC,255,
	   				WIBU_Flags,0,0,0);

	   fc=BuildWildObjectTags(	WIBU_ObjectType,BUILD_Face,
	   				WIBU_BuildObject,TRUE,
	   				WIBU_WildApp,KubeApp,
	   				WIBU_Parent,KubeSector,
	   				WIBU_PointA,pf,
	   				WIBU_PointB,pc,
	   				WIBU_PointC,pb,
	   				WIBU_EdgeA,ej,
	   				WIBU_EdgeB,ec,
	   				WIBU_EdgeC,eq,
	   				WIBU_Texture,eagle,
	   				WIBU_TxA,0,
	   				WIBU_TyA,0,
	   				WIBU_TxB,255,
	   				WIBU_TyB,255,
	   				WIBU_TxC,0,
	   				WIBU_TyC,255,
	   				WIBU_Flags,0,0,0);

	   fd=BuildWildObjectTags(	WIBU_ObjectType,BUILD_Face,
	   				WIBU_BuildObject,TRUE,
	   				WIBU_WildApp,KubeApp,
	   				WIBU_Parent,KubeSector,
	   				WIBU_PointA,pg,
	   				WIBU_PointB,pc,
	   				WIBU_PointC,pf,
	   				WIBU_EdgeA,ek,
	   				WIBU_EdgeB,eg,
	   				WIBU_EdgeC,eq,
	   				WIBU_Texture,eagle,
	   				WIBU_TxA,255,
	   				WIBU_TyA,0,
	   				WIBU_TxB,255,
	   				WIBU_TyB,255,
	   				WIBU_TxC,0,
	   				WIBU_TyC,0,
	   				WIBU_Flags,0,0,0);

	   fe=BuildWildObjectTags(	WIBU_ObjectType,BUILD_Face,
	   				WIBU_BuildObject,TRUE,
	   				WIBU_WildApp,KubeApp,
	   				WIBU_Parent,KubeSector,
	   				WIBU_PointA,pe,
	   				WIBU_PointB,ph,
	   				WIBU_PointC,pg,
	   				WIBU_EdgeA,eh,
	   				WIBU_EdgeB,ee,
	   				WIBU_EdgeC,em,
	   				WIBU_Texture,py,
	   				WIBU_TxA,255,
	   				WIBU_TyA,255,
	   				WIBU_TxB,0,
	   				WIBU_TyB,255,
	   				WIBU_TxC,0,
	   				WIBU_TyC,0,
	   				WIBU_Flags,0,0,0);

	   ff=BuildWildObjectTags(	WIBU_ObjectType,BUILD_Face,
	   				WIBU_BuildObject,TRUE,
	   				WIBU_WildApp,KubeApp,
	   				WIBU_Parent,KubeSector,
	   				WIBU_PointA,pe,
	   				WIBU_PointB,pg,
	   				WIBU_PointC,pf,
	   				WIBU_EdgeA,eg,
	   				WIBU_EdgeB,ef,
	   				WIBU_EdgeC,em,
	   				WIBU_Texture,py,
	   				WIBU_TxA,255,
	   				WIBU_TyA,255,
	   				WIBU_TxB,0,
	   				WIBU_TyB,0,
	   				WIBU_TxC,255,
	   				WIBU_TyC,0,
	   				WIBU_Flags,0,0,0);

	   fg=BuildWildObjectTags(	WIBU_ObjectType,BUILD_Face,
	   				WIBU_BuildObject,TRUE,
	   				WIBU_WildApp,KubeApp,
	   				WIBU_Parent,KubeSector,
	   				WIBU_PointA,pb,
	   				WIBU_PointB,pd,
	   				WIBU_PointC,pa,
	   				WIBU_EdgeA,ea,
	   				WIBU_EdgeB,eb,
	   				WIBU_EdgeC,eo,
	   				WIBU_Texture,wild,
	   				WIBU_TxA,0,
	   				WIBU_TyA,0,
	   				WIBU_TxB,255,
	   				WIBU_TyB,255,
	   				WIBU_TxC,255,
	   				WIBU_TyC,0,
	   				WIBU_Flags,0,0,0);

	   fh=BuildWildObjectTags(	WIBU_ObjectType,BUILD_Face,
	   				WIBU_BuildObject,TRUE,
	   				WIBU_WildApp,KubeApp,
	   				WIBU_Parent,KubeSector,
	   				WIBU_PointA,pd,
	   				WIBU_PointB,pb,
	   				WIBU_PointC,pc,
	   				WIBU_EdgeA,eo,
	   				WIBU_EdgeB,ec,
	   				WIBU_EdgeC,ed,
	   				WIBU_Texture,wild,
	   				WIBU_TxA,0,
	   				WIBU_TyA,0,
	   				WIBU_TxB,255,
	   				WIBU_TyB,255,
	   				WIBU_TxC,0,
	   				WIBU_TyC,255,
	   				WIBU_Flags,0,0,0);

	   fi=BuildWildObjectTags(	WIBU_ObjectType,BUILD_Face,
	   				WIBU_BuildObject,TRUE,
	   				WIBU_WildApp,KubeApp,
	   				WIBU_Parent,KubeSector,
	   				WIBU_PointA,pe,
	   				WIBU_PointB,pf,
	   				WIBU_PointC,pb,
	   				WIBU_EdgeA,ej,
	   				WIBU_EdgeB,ef,
	   				WIBU_EdgeC,en,
	   				WIBU_Texture,canyon,
	   				WIBU_TxA,0,
	   				WIBU_TyA,0,
	   				WIBU_TxB,255,
	   				WIBU_TyB,0,
	   				WIBU_TxC,255,
	   				WIBU_TyC,255,
	   				WIBU_Flags,0,0,0);

	   fj=BuildWildObjectTags(	WIBU_ObjectType,BUILD_Face,
	   				WIBU_BuildObject,TRUE,
	   				WIBU_WildApp,KubeApp,
	   				WIBU_Parent,KubeSector,
	   				WIBU_PointA,pe,
	   				WIBU_PointB,pb,
	   				WIBU_PointC,pa,
	   				WIBU_EdgeA,ei,
	   				WIBU_EdgeB,eb,
	   				WIBU_EdgeC,en,
	   				WIBU_Texture,canyon,
	   				WIBU_TxA,0,
	   				WIBU_TyA,0,
	   				WIBU_TxB,255,
	   				WIBU_TyB,255,
	   				WIBU_TxC,0,
	   				WIBU_TyC,255,
	   				WIBU_Flags,0,0,0);

	   fk=BuildWildObjectTags(	WIBU_ObjectType,BUILD_Face,
	   				WIBU_BuildObject,TRUE,
	   				WIBU_WildApp,KubeApp,
	   				WIBU_Parent,KubeSector,
	   				WIBU_PointA,ph,
	   				WIBU_PointB,pd,
	   				WIBU_PointC,pg,
	   				WIBU_EdgeA,ep,
	   				WIBU_EdgeB,eh,
	   				WIBU_EdgeC,el,
	   				WIBU_Texture,sunset,
	   				WIBU_TxA,255,
	   				WIBU_TyA,0,
	   				WIBU_TxB,255,
	   				WIBU_TyB,255,
	   				WIBU_TxC,0,
	   				WIBU_TyC,0,
	   				WIBU_Flags,0,0,0);

	   fl=BuildWildObjectTags(	WIBU_ObjectType,BUILD_Face,
	   				WIBU_BuildObject,TRUE,
	   				WIBU_WildApp,KubeApp,
	   				WIBU_Parent,KubeSector,
	   				WIBU_PointA,pd,
	   				WIBU_PointB,pc,
	   				WIBU_PointC,pg,
	   				WIBU_EdgeA,ed,
	   				WIBU_EdgeB,ek,
	   				WIBU_EdgeC,ep,
	   				WIBU_Texture,sunset,
	   				WIBU_TxA,255,
	   				WIBU_TyA,255,
	   				WIBU_TxB,0,
	   				WIBU_TyB,255,
	   				WIBU_TxC,0,
	   				WIBU_TyC,0,
	   				WIBU_Flags,0,0,0);
DebugOut("Made faces.\n\0");
	   
	   BuildWildObjectTags(		WIBU_ObjectType,BUILD_Face,
	   				WIBU_ModifyObject,fa,
	   				WIBU_Plus,fb,
	   				WIBU_Minus,fc,0,0);

	   BuildWildObjectTags(		WIBU_ObjectType,BUILD_Face,
	   				WIBU_ModifyObject,fb,
	   				WIBU_Plus,0,
	   				WIBU_Minus,0,0,0);

	   BuildWildObjectTags(		WIBU_ObjectType,BUILD_Face,
	   				WIBU_ModifyObject,fc,
	   				WIBU_Plus,fd,
	   				WIBU_Minus,fe,0,0);

	   BuildWildObjectTags(		WIBU_ObjectType,BUILD_Face,
	   				WIBU_ModifyObject,fd,
	   				WIBU_Plus,0,
	   				WIBU_Minus,0,0,0);

	   BuildWildObjectTags(		WIBU_ObjectType,BUILD_Face,
	   				WIBU_ModifyObject,fe,
	   				WIBU_Plus,ff,
	   				WIBU_Minus,fg,0,0);

	   BuildWildObjectTags(		WIBU_ObjectType,BUILD_Face,
	   				WIBU_ModifyObject,ff,
	   				WIBU_Plus,0,
	   				WIBU_Minus,0,0,0);

	   BuildWildObjectTags(		WIBU_ObjectType,BUILD_Face,
	   				WIBU_ModifyObject,fg,
	   				WIBU_Plus,fh,
	   				WIBU_Minus,fi,0,0);

	   BuildWildObjectTags(		WIBU_ObjectType,BUILD_Face,
	   				WIBU_ModifyObject,fh,
	   				WIBU_Plus,0,
	   				WIBU_Minus,0,0,0);

	   BuildWildObjectTags(		WIBU_ObjectType,BUILD_Face,
	   				WIBU_ModifyObject,fi,
	   				WIBU_Plus,fj,
	   				WIBU_Minus,fk,0,0);

	   BuildWildObjectTags(		WIBU_ObjectType,BUILD_Face,
	   				WIBU_ModifyObject,fj,
	   				WIBU_Plus,0,
	   				WIBU_Minus,0,0,0);

	   BuildWildObjectTags(		WIBU_ObjectType,BUILD_Face,
	   				WIBU_ModifyObject,fk,
	   				WIBU_Plus,fl,
	   				WIBU_Minus,0,0,0);

	   BuildWildObjectTags(		WIBU_ObjectType,BUILD_Face,
	   				WIBU_ModifyObject,fl,
	   				WIBU_Plus,0,
	   				WIBU_Minus,0,0,0);

	   BuildWildObjectTags(		WIBU_ObjectType,BUILD_Sector,
	   				WIBU_ModifyObject,KubeSector,
	   				WIBU_Root,fa,0,0);
DebugOut("Made BSP-Tree.\n\0");
	   				
          }//Sector
        }//Alien
      }//Arena					   
    }//World
  }//Scene
}
