#include "stdafx.h"
#include"TCTTerrainData.h"
#include<string.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

TCTTerrainData::TCTTerrainData() 
{
//	for(int i=0;i<MAX_LAYERS;i++)	Lay[i]=NULL;
//	Lay[0]=(Layer *)new HeightFieldLayer;
//	Lay[1]=(Layer *)new TextureLayer;
//	Lay[2]=(Layer *)new TextureLayer;
	Image timg;
	timg.CreateSolid(256,256,ImgRGBColor(0,0,0),ITYPE_INDEXED,8);
	HFLayer.Import(timg);
	HField=0;
	ViewedLayer=0;
	
}

void TCTTerrainData::LoadHeightField(CString &str)
{
//	if(Lay[0]!=NULL) delete Lay[0];
//	Lay[0]=(Layer *)new HeightFieldLayer;
	char fname[512];
	strcpy(fname,str);
	
	HFLayer.Import(fname);
	HField->Create(HFLayer.Img);
}

void TCTTerrainData::LoadHeightField(Image &img)
{
//	if(Lay[0]!=NULL) delete Lay[0];
//	Lay[0]=(Layer *)new HeightFieldLayer;
	
	HFLayer.Import(img);
	HField->Create(HFLayer.Img);
}

void TCTTerrainData::Initalize()
{
//	Verify(PlatformFunctions::PlatformInitialized==true);
	if(!HField)
		HField=new TCTHeightField();
	HField->Create(HFLayer.Img);
	
	//for(int i=0;i<MAX_LAYERS;i++)	Lay[i]=NULL;
	
}

void TCTTerrainData::UnInitalize()
{
	if(HField)
		delete HField;
}

TCTTerrainData::~TCTTerrainData() 
{
	
	
}

/*
void TCTTerrainData::CreateHeightField(ElementRenderer::ListElement *Scene,MidLevelRenderer::MLRState state1,MidLevelRenderer::MLRState state2)
{
heightField->Create(Scene,HFBmp,state1,state2);
}
*/

TCTTerrainData &TCTTerrainData::operator =(TCTTerrainData &tdat)
{
	Initalize();
	*HField=*(tdat.HField);
	LayTotal=tdat.LayTotal;
	BaseTexture=tdat.BaseTexture;
	DetailTexture=tdat.DetailTexture;
	HFLayer=tdat.HFLayer;
	HField->SetState(BaseTexture.State,0);
	HField->SetState(DetailTexture.State,1);

	/*
	for(int i=0;i<LayTotal;i++) 
    {
		Lay[i]=tdat.Lay[i];
		HField->SetState(Lay[i]->State,i);
    }
	*/
	return *this;
}

Layer * TCTTerrainData::GetViewedLayer()
{
//	ViewedLayer=0;
//	return Lay[ViewedLayer];
	return &HFLayer;
}

bool TCTTerrainData::SetViewedLayer(int lay)
{
	ViewedLayer=0;
	return 0;
/*
	bool ret;
	ret=ViewedLayer!=lay?true:false;
	ViewedLayer=lay;
	return ret;
*/
 }
