/*
///////////////////////////////////////////////////////////////////////////////////////////////////
// Description : Inter.cpp
//
// Interface DLL class.
// This class is implement the DLL class.
//
///////////////////////////////////////////////////////////////////////////////////////////////////
// inherit from CPA_ObjectDLLBase
//
///////////////////////////////////////////////////////////////////////////////////////////////////
// Creation date: 11 feb 1997                        Author: J Thénoz
///////////////////////////////////////////////////////////////////////////////////////////////////
// Modification date:			                      Author:
//
//
//
//
///////////////////////////////////////////////////////////////////////////////////////////////////
*/

#include "stdafx.h"
#include "acp_base.h"
#include "resource.h"
#include "itf.h"
#include "ogd.h"
#include "dpt.h"
#include "incsct.h"
#include "incgam.h"

#include "LightDia.hpp"
#include "RliDia.hpp"
#include "Inter.hpp"
#include "LightObj.hpp"
#include "EdLight.h"
#include "po.h"
#include "ipo.h"
#include "isi.h"
#include "x:\cpa\main\inc\_editid.h"
#include <direct.h>
#include "ray.h"
#include "tut.h"

// infos
static CString g_csOLGName = "Light";
static CString g_csOLGAuthor = "Jacques Thénoz";
static CString g_csOLGVersion = "V 4.0.4   01/04/99";
static CString g_csOLGFrenchHelpFile = "Lumiere.hlp";
static CString g_csOLGEnglishHelpFile = "";

BOOL g_bTipFirstTime = TRUE;

//----------------------------------------------------------------------
// submenu commands
#define c_Light_Submenu_Activate			1939
#define c_Light_SubMenu_Compute_RLI			1945
#define c_Light_SubMenu_Save_Preference		1914
#define c_Light_SubMenu_UpDate_Light		1918
//----------------------------------------------------------------------


//----------------------------------------------------------------------
// popup menu command
#define c_Light_Popup_On			1234
#define c_Light_Popup_Off			1235
#define c_Light_Popup_Goto			1236
#define c_Light_Popup_Exit          1237
#define c_light_Popup_Update        1238
#define c_light_Popup_RealTime_On	1239
#define c_light_Popup_RealTime_Off	1240
//----------------------------------------------------------------------


//----------------------------------------------------------------------
// Definition of lists names
	static CString csHierarchyList = "Hierarchy";
	static CString csCurrentList = "Current model";
	static CString csLightList = "Light";
//----------------------------------------------------------------------



//---- provisoire
#define HIE_M_p_stGetSuperObject(_hSprObj) (_hSprObj)
#define HIE_M_xGetSuperObjectMember(_hSprObj,_member) ((_hSprObj)->_member)
#define HIE_M_vSetSuperObjectMember(_hSprObj,_member,_value) {(_hSprObj)->_member=(_value);}
//---- fin provisoire


//----------- Keyboard mapping
//CPA2 Corneliu Babiuc 26-05-98
//#define KA_LIGHT_NEAR		1
//#define	KA_LIGHT_FAR		2
//#define	KA_LIGHT_FREE_MOVE	3
//END CPA2 Corneliu Babiuc 21-05-98
#define KA_LIGHT_ORIENT     5
//CPA2 Corneliu Babiuc 26-05-98
#define KA_LIGHT_SWITCH		6
#define KA_REAL_TIME		7
//END CPA2 Corneliu Babiuc 21-05-98
#define KA_CONTROL			10

tdstKeyboardActionDef Light_Interface::ms_a_stLightKeys [] =
{
//CPA2 Corneliu Babiuc 26-05-98
//	{ "Near",			KA_LIGHT_NEAR},
//	{ "Far",			KA_LIGHT_FAR },
//	{ "Free move",		KA_LIGHT_FREE_MOVE },
//END CPA2 Corneliu Babiuc 26-05-98
	{ "Orient light",  KA_LIGHT_ORIENT },
//CPA2 Corneliu Babiuc 21-05-98
	{ "Active light",	KA_LIGHT_SWITCH },
	{ "Real time",		KA_REAL_TIME },
//END CPA2 Corneliu Babiuc 21-05-98
	{ "Ctrl",			KA_CONTROL },
	{ NULL, 0 }
};
//-------------
BOOL g_bKeyUsed = FALSE;

// the DLL global definition
tdstDLLIdentity		g_stLightIdentity;

#define C_szLightIniFile "Light\\Light.ini"

CString g_csPreviousList;
BOOL	g_bEditorMode = FALSE;

//--------------------------------------------------------------------------------
// CONSTRUCTOR.
// You must put here all your DLL interface definitions.
//--------------------------------------------------------------------------------
Light_Interface::Light_Interface(void)
{
	// ************************** private internal
	m_p_stDLLIdentity = &g_stLightIdentity;

    // Does your DLL can output in main game view ?
	m_stBaseDLLDefinition.bCanOutputIn3DView = TRUE;

    // Does your DLL can be refresh by engine ?
	m_stBaseDLLDefinition.bCanBeRefreshedByEngine = TRUE;

	m_bDialogOnScreen=FALSE;
	m_o_ModifRadiusLight=NULL;
	m_poRClicLight=NULL;
	m_poLight=NULL;
	m_bMainDll=FALSE;
	m_bExistSaveFile=FALSE;
	m_bFirstBeforeEditor=TRUE;
	m_bLoadLight=FALSE;
	m_bSaveRLI=FALSE;
	m_bNotifyIPO=FALSE;
	m_bSkipOnModifDelete=FALSE;
	m_bOrientLight=FALSE;
	m_ListDeleteLightBeforeEngine.RemoveAll ();
	m_bModifyAll=FALSE;
	m_oModifSectorList.RemoveAll ();
//ROMTEAM SelectMode (Ionut Grozea 25/02/98)
	m_bSelectModeIsLight = 0;
//ENDROMTEAM SelectMode (Ionut Grozea)
//ROMTEAM RealLights (Ionut Grozea 05/03/98)
	m_ListDeleteLight.RemoveAll ();
	m_bEditOnlyRealLights = FALSE;
//ENDROMTEAM RealLights (Ionut Grozea)
//ROMTEAM color lights Ionut Grozea 10-08-1998
	m_bIs2ColorMode = TRUE;
//ROMTEAM color lights Ionut Grozea 10-08-1998
	//--- help menu
    SetEditorInfo(g_csOLGName, g_csOLGAuthor, g_csOLGVersion, g_csOLGFrenchHelpFile, g_csOLGEnglishHelpFile);


	//--- mapping keyboard
	m_poKeyboard = new CPA_KeyActionConfiguration (CString("objects\\Light\\Light.ini"), ms_a_stLightKeys );
	m_poKeyboard->mfn_vSetObjectName ( CString ("Light Editor") );
}

Light_Interface::~Light_Interface(void)
{
	delete m_poKeyboard;
	m_poKeyboard=NULL;
}



void Light_Interface::fn_vJustAfterRegistered (void)
{
	//----------------------------------------- declare the type name
	CString apszName[] = { "Light", "LightCursor" };
	fn_vRegisterObjectsType(apszName,2);

	//----- static init of objects
	Light::fn_vInitObject ();

}


void Light_Interface::fn_vConstruct(void)
{
	//------------------------ .ini file
	int			iDim;
	char		szDimension[256];
	CString		csFileName = M_GetMainApp()->m_csEditorDataPath + "Objects\\" + C_szLightIniFile;


	//-------------------------------------------------------- splitters
	m_p_oSplitFrameLight = new CSplitFrame();
	m_p_oSplitFrameLight->CreateBase( "Edition", 1, 2, GetInterface()->GetMainWorld() );
	m_p_oSplitFrameLight->CreateSplitter( C_cVerticalSplitter, 2);

	HINSTANCE hOldInst = AfxGetResourceHandle();
    AfxSetResourceHandle( m_p_stDLLIdentity->hModule );


	GetPrivateProfileString ("Preference", "Light Edit Dimension", "0", szDimension, 256, (char*)(LPCSTR)csFileName);
	iDim = atoi(szDimension);

	m_p_oSplitFrameLight->CreateView(1, RUNTIME_CLASS(DiaLight), "no light to edit", iDim>0 ? iDim : 450 );
	m_p_oSplitFrameLight->mfn_vEnableCaption (FALSE);
	m_p_oSplitFrameLight->m_stWinTop.cLinkSame=FRM_C_MoveRight;

	GetPrivateProfileString ("Preference", "Light Left Frame Width", "0", szDimension, 256, (char*)(LPCSTR)csFileName);
	iDim = atoi(szDimension);
	m_p_oSplitFrameLight->m_iInitWidth = iDim>0 ? iDim : 185;

	// set the pointer dialog of the Light dialog
	Light::fn_vSetDialog ((DiaLight*) m_p_oSplitFrameLight->m_fn_p_oGetPane(1), this);

    AfxSetResourceHandle( hOldInst );

	//----------------------------------------------------- Lists
	m_p_oDialogList = new  CPA_DialogList();
	m_p_oDialogList->fn_vInitDialog ( this, m_p_oSplitFrameLight );
	m_p_oDialogList->SetPermanentHeaders (FALSE);
	TUT_M_vGetTutDll ();
	TUT_M_vRegisterDialogList (m_p_oDialogList, "OLG_List", "", "OLG_ComboSelect", "");

	GetPrivateProfileString ("Preference", "Light DialogList Dimension", "0", szDimension, 256, (char*)(LPCSTR)csFileName);
	iDim = atoi(szDimension);

	m_p_oSplitFrameLight->SetPaneView(0, m_p_oDialogList, "Lists", iDim>0 ? iDim : 160);


 	// icons for list
	m_oIconList.Create(20, 20, ILC_MASK, 0, 19);

	m_oIconList.Add(LoadIcon(GetDLLIdentity()->hModule, MAKEINTRESOURCE(IDI_SPHERICAL_LIGHT_ICON)));		/*0*/
	m_oIconList.Add(LoadIcon(GetDLLIdentity()->hModule, MAKEINTRESOURCE(IDI_SPOT_LIGHT_ICON)));				/*1*/
	m_oIconList.Add(LoadIcon(GetDLLIdentity()->hModule, MAKEINTRESOURCE(IDI_PARALLEL_LIGHT_ICON)));			/*2*/
	m_oIconList.Add(LoadIcon(GetDLLIdentity()->hModule, MAKEINTRESOURCE(IDI_AMBIENT_LIGHT_ICON)));			/*3*/
	m_oIconList.Add(LoadIcon(GetDLLIdentity()->hModule, MAKEINTRESOURCE(IDI_PARALLELBOX_LIGHT_ICON)));		/*4*/
	m_oIconList.Add(LoadIcon(GetDLLIdentity()->hModule, MAKEINTRESOURCE(IDI_Z_LIGHT_ICON)));				/*5*/	

	m_oIconList.Add(LoadIcon(GetDLLIdentity()->hModule, MAKEINTRESOURCE(IDI_SPHERICAL_LIGHT_BLUE_ICON)));	/*6*/
	m_oIconList.Add(LoadIcon(GetDLLIdentity()->hModule, MAKEINTRESOURCE(IDI_SPOT_LIGHT_BLUE_ICON)));		/*7*/
	m_oIconList.Add(LoadIcon(GetDLLIdentity()->hModule, MAKEINTRESOURCE(IDI_PARALLEL_LIGHT_BLUE_ICON)));	/*8*/
	m_oIconList.Add(LoadIcon(GetDLLIdentity()->hModule, MAKEINTRESOURCE(IDI_AMBIENT_LIGHT_BLUE_ICON)));		/*9*/
	m_oIconList.Add(LoadIcon(GetDLLIdentity()->hModule, MAKEINTRESOURCE(IDI_PARALLELBOX_LIGHT_BLUE_ICON)));	/*10*/
	m_oIconList.Add(LoadIcon(GetDLLIdentity()->hModule, MAKEINTRESOURCE(IDI_Z_LIGHT_BLUE_ICON)));			/*11*/	

	m_oIconList.Add(LoadIcon(GetDLLIdentity()->hModule, MAKEINTRESOURCE(IDI_SPHERICAL_IMPORT_LIGHT_ICON)));	/*12*/
	m_oIconList.Add(LoadIcon(GetDLLIdentity()->hModule, MAKEINTRESOURCE(IDI_SPOT_IMPORT_LIGHT_ICON)));		/*13*/
	m_oIconList.Add(LoadIcon(GetDLLIdentity()->hModule, MAKEINTRESOURCE(IDI_PARALLEL_IMPORT_LIGHT_ICON)));	/*14*/
	m_oIconList.Add(LoadIcon(GetDLLIdentity()->hModule, MAKEINTRESOURCE(IDI_AMBIENT_IMPORT_LIGHT_ICON)));	/*15*/
	m_oIconList.Add(LoadIcon(GetDLLIdentity()->hModule, MAKEINTRESOURCE(IDI_PARALLELBOX_IMPORT_LIGHT_ICON)));/*16*/
	m_oIconList.Add(LoadIcon(GetDLLIdentity()->hModule, MAKEINTRESOURCE(IDI_Z_IMPORT_LIGHT_ICON)));			/*17*/	

	m_oIconList.Add(LoadIcon(GetDLLIdentity()->hModule, MAKEINTRESOURCE(IDI_FOG_ICON)));					/*18*/
}


//--------------------------------------------------------------------
//					LISTS
//--------------------------------------------------------------------

// init the lists in the dialog
void Light_Interface::GetListsForDialog  ( CPA_DialogList * pDialog )
{
//	CPA_List<CPA_SuperObject>* pList = new CPA_List<CPA_SuperObject>;
//	pList->RemoveAll ();

	// construct the lists
	pDialog->fn_vAddANewTree ( csHierarchyList, ((DEV_MultiDevice3D*)(GetInterface()->GetMultiDevice3D()))->GetWorld()->GetRoot());
//	pDialog->fn_vAddANewList ( csCurrentList, GetInterface()->GetSortedListByType("All Types"));
	pDialog->fn_vAddANewList ( csLightList,  GetInterface()->GetSortedListByType ("Light"), NULL, &m_oIconList,E_lo_Alpha, TRUE, C_lDrawState | C_lDrawName, TRUE );

// Begin Silviu Simen List by Sector and type
	CPA_List<CPA_SuperObject>* poList = GetInterface()->GetObjectListByType	(C_szSectorTypeName);
	CPA_SuperObject * p_sector;
	POSITION pos;

	ASSERT (poList);
	for (p_sector = poList -> GetHeadElement(pos); p_sector; 
		 p_sector = poList -> GetNextElement(pos) ) 
	{
		m_p_oDialogList->fn_vAddANewList(p_sector -> GetName() + "(Position)", M_GetMainWorld()->m_stListObjectsInSectors.GetListOfSectorByType(p_sector,HIE_C_ulEDT_Light), NULL, &m_oIconList,E_lo_Alpha, TRUE, C_lDrawState | C_lDrawName, TRUE );
		m_p_oDialogList->fn_vAddANewList(p_sector -> GetName() + "(Effect)", fn_pGetListBySector(p_sector), NULL, &m_oIconList,E_lo_Alpha, TRUE, C_lDrawState | C_lDrawName, TRUE );
	};
// End Silviu Simen List by Sector and type
}

// get the list of lights affecting the sector
CPA_BaseObjectList * Light_Interface::fn_pGetListBySector (CPA_SuperObject *pSector)
{
	Light_ListBySector	*pList;
	POSITION			pos;

	for (pList = m_stListBySector.GetHeadElement(pos); pList; pList = m_stListBySector.GetNextElement(pos))
	{
		if (pList->GetSector() == pSector)
			return pList->GetList();
	}
	return NULL;
}


BOOL Light_Interface::fn_bTestFunction (CString csCurrentType, CString csTestName, CPA_BaseObject *pElem)
{
	CPA_SuperObject *pEdObj;
	if (csCurrentType==csCurrentList)
	{
		pEdObj = (CPA_SuperObject *) pElem;
		if ((GetInterface()->GetCurrentModel())&&(pEdObj->GetModelName()==GetInterface()->GetCurrentModel()->m_csName))
			return TRUE;
		else
			return FALSE;
	}
	return TRUE;
}


BOOL Light_Interface::fn_bOnSelChangeHierarchyTree	(CPA_DialogList *pDialog, CString csTypeName, CPA_BaseObject *pSelectedObject, CPA_BaseObject *pSelectedParent)
{
	if (!pSelectedObject) return FALSE;
	CPA_SuperObject* pSuperObject = (CPA_SuperObject*)pSelectedObject;

	switch (pSuperObject->GetObjectType())
	{
		case HIE_C_ulEDT_Light :
			if (m_o_ModifRadiusLight!=(Light*)pSuperObject->GetObject())
			{
				if (m_o_ModifRadiusLight) m_o_ModifRadiusLight->fn_vUnSelect ();
				m_o_ModifRadiusLight = NULL;
			}
			GetInterface()->fn_vCancelCurrentSelection (FALSE);
			fn_vEdit ((Light*)pSuperObject->GetObject());
			break;
	}
	return FALSE;
}


BOOL Light_Interface::fn_bOnDblClkHierarchyTree	(CPA_DialogList *pDialog, CString csTypeName, CPA_BaseObject *pSelectedObject, CPA_BaseObject *pSelectedParent)
{
	if (!pSelectedObject) return FALSE;
	// ?
	CPA_SuperObject* pSuperObject = (CPA_SuperObject*)pSelectedObject;
	if (pSuperObject) GetInterface()->fn_bSelectObject (pSuperObject, TRUE);
	return FALSE;
}

// we select something in the list
BOOL Light_Interface::fn_bOnSelChangeListObjects (CPA_DialogList *pDialog, CString csTypeName, CPA_BaseObject *pSelectedObject, BOOL bUnselect)
{
	if (!pSelectedObject) return FALSE;
	CPA_SuperObject* pSuperObject = (CPA_SuperObject*)pSelectedObject;

	switch (pSuperObject->GetObjectType())
	{
		case HIE_C_ulEDT_Light :
			if (m_o_ModifRadiusLight!=(Light*)pSuperObject->GetObject())
			{
				if (m_o_ModifRadiusLight) m_o_ModifRadiusLight->fn_vUnSelect ();
				m_o_ModifRadiusLight = NULL;
			}
			GetInterface()->fn_vCancelCurrentSelection (FALSE);
			if( bUnselect )
				fn_vEdit (NULL,FALSE);
			else
				fn_vEdit ((Light*)pSuperObject->GetObject(),FALSE);
			break;
	}
	return FALSE;
}

BOOL Light_Interface::fn_bOnDblClkListObjects (CPA_DialogList *pDialog, CString csTypeName, CPA_BaseObject *pSelectedObject)
{
	if (!pSelectedObject) return FALSE;
	CPA_SuperObject* pSuperObject = (CPA_SuperObject*)pSelectedObject;
	if (pSuperObject) GetInterface()->fn_bSelectObject (pSuperObject, TRUE);
	return FALSE;
}

tdeTypeAnswer Light_Interface::fn_bAcceptSelect	(CPA_SuperObject *pEdObj, ACP_tdxIndex xIndex, HIE_tdstPickInfo *pPicking, tdeStatus eStatus)
{
	if (eStatus!=C_AsConcernedDLL) return CPA_ObjectDLLBase::fn_bAcceptSelect (pEdObj, xIndex, pPicking, eStatus);
	if (pEdObj->GetObjectType()==HIE_C_ulEDT_Light) return C_Accept;
	return C_Refuse;
}


CPA_BaseObject* Light_Interface::GetDialogSelection (CPA_DialogList *pDialog, CString csTypeName, tdeListDrawMode eDrawMode)
{
	if (csTypeName!=csHierarchyList)
	{
		Light* poLight = Light::fn_pGetDialog()->fn_pGetEditLight();
		if (!poLight) return NULL;
		return poLight->GetSuperObject();
	}
	return CPA_ObjectDLLBase::GetDialogSelection ( pDialog, csTypeName, eDrawMode );
}


//---- icon management
int	Light_Interface::GetStateForListItem (CPA_DialogList *pDialog, CString csListName, CPA_BaseObject *pObject)
{
	if (csListName!=csHierarchyList )
	{
		Light* poLight = (Light*) ((CPA_SuperObject*)pObject)->GetObject();

		if (poLight->fn_bIs3DsMaxLight())
		{
			switch (poLight->fn_lGetType())
			{
				case GLI_C_lSphericalLight:				return 12;
				case GLI_C_lHotSpotLight :				return 13;
				case GLI_C_lParallelLight :				return 14;
				case GLI_C_lAmbientLight :				return 15;
				case GLI_C_lParallelLight_With_Limit :	return 16;
				default /*case GLI_C_lZ_Light*/: 		return 17;
				case GLI_C_lFogLight :					return 18;
			}
		}
		else if (poLight->fn_bGetOnOff())
		{
			switch (poLight->fn_lGetType())
			{
				case GLI_C_lSphericalLight:				return 0;
				case GLI_C_lHotSpotLight :				return 1;
				case GLI_C_lParallelLight :				return 2;
				case GLI_C_lAmbientLight :				return 3;
				case GLI_C_lParallelLight_With_Limit :	return 4;
				default /*case GLI_C_lZ_Light*/: 		return 5;
				case GLI_C_lFogLight :					return 18;
			}
		}
		else
		{
			switch (poLight->fn_lGetType())
			{
				case GLI_C_lSphericalLight:				return 6;
				case GLI_C_lHotSpotLight :				return 7;
				case GLI_C_lParallelLight :				return 8;
				case GLI_C_lAmbientLight :				return 9;
				case GLI_C_lParallelLight_With_Limit :	return 10;
				default /*case GLI_C_lZ_Light*/: 		return 11;
				case GLI_C_lFogLight :					return 18;
			}
		}

	}
	return CPA_ObjectDLLBase::GetStateForListItem (pDialog, csListName, pObject);
}


//----------------------------------------------------------------------
// CURRENT DLL
//----------------------------------------------------------------------
tdePermission Light_Interface::fn_eAcceptNewEditor (CPA_EditorBase *pNewDll)
{
	if ( pNewDll->fn_bIsCurrentEditor () ) return C_Allow;
	else
	{
		// Dialog will be delete by the hierarchy editor, so we unset the flag before
		m_bDialogOnScreen = FALSE;
		return C_CloseBefore;
	}
}


void Light_Interface::fn_vOnActivateEditor (CPA_List<CPA_BaseObject> *pParams, BOOL bBackActivated)
{
	if (!m_bDialogOnScreen)
	{	// Set the Dialog on the screen
		// call the init lists functions
		m_p_oDialogList->fn_vInitAllLists ();
		m_p_oDialogList->fn_vReinitDialog ();

		// activate the frames of the editor
		HWND WindowWithFocus = GetFocus ();
		g_oFrameGest.mfn_vSetRefresh(FALSE);
		g_oFrameGest.mfn_vActivateWindow (m_p_oSplitFrameLight);
		g_oFrameGest.mfn_vActivateWindow ( GetInterface()->GetModelFrame() );

		SetFocus (WindowWithFocus);
		g_oFrameGest.mfn_vSetRefresh(TRUE);
		m_p_oDialogList->SetCurrentType  ( csLightList );
		m_p_oDialogList->SetDefaultButtonState ( FALSE );
//ROMTEAM SelectMode (Ionut Grozea 25/02/98)
		m_bPreviousLinkMode = GetInterface()->GetLinkMode();
		GetInterface()->SetLinkMode(FALSE);
		m_csLastSelectionType = GetInterface()->GetSelectMode();
		GetInterface()->SetSelectMode("Light");
		m_bSelectModeIsLight = 1;
//ENDROMTEAM SelectMode (Ionut Grozea)
//ANNECY Shaitan Correction 03/02/98 {
		g_csPreviousList = GetInterface()->GetDialogInsert()->fn_csGetCurrentListModel();
		GetInterface()->GetDialogInsert()->fn_vSetCurrentListModel("Light");
//ENDANNECY Shaitan Correction }

		// set the enter editor ( WP or way )
		m_bDialogOnScreen=TRUE;
	}

	// edit pParam
	if (pParams)
	{
		CPA_BaseObject* p_oEditSuperLight = fn_pSelectLightParam ( pParams );
		if (p_oEditSuperLight) fn_vEdit ( (Light*) ((CPA_SuperObject*)p_oEditSuperLight)->GetObject() );
	}
	else
	{
		 CPA_SuperObject *pSelectedObject = M_GetWorld()->GetSingleSelection();
		 if (pSelectedObject && (pSelectedObject->GetObject()->GetDataType()==HIE_C_ulEDT_Light))
			 fn_vEdit ( (Light*) ((CPA_SuperObject*)pSelectedObject)->GetObject() );
	}

	// display Tip of the Day
	GetInterface()->fn_vDisplayTipOfDay("Lights", "OLG", g_bTipFirstTime);
	g_bTipFirstTime = FALSE;
}

void Light_Interface::fn_vOnCloseEditor (void)
{
	// desactivate the frames
	g_oFrameGest.mfn_vSetRefresh(FALSE);

	g_oFrameGest.mfn_vDisactivateWindow (m_p_oSplitFrameLight);
	g_oFrameGest.mfn_vSetRefresh(TRUE);
	m_bDialogOnScreen=FALSE;
//ROMTEAM SelectMode (Ionut Grozea 25/02/98)
	GetInterface()->SetSelectMode(m_csLastSelectionType);
	GetInterface()->SetLinkMode(m_bPreviousLinkMode );
	m_bSelectModeIsLight = 0;
//ENDROMTEAM SelectMode (Ionut Grozea)
	GetInterface()->GetDialogInsert()->fn_vSetCurrentListModel(g_csPreviousList);

	// unselect lights
	if (m_o_ModifRadiusLight)
	{
		m_o_ModifRadiusLight->fn_vUnSelect ();
		m_o_ModifRadiusLight=NULL;
	}
}


CString Light_Interface::fn_csGetSaveFileName (void)
{
	char szLevelName [256];
	fn_zsGetActualLevelFilename (szLevelName, "lgt");
	CString csLevelName = szLevelName;
	return csLevelName;
}

void Light_Interface::fn_vLevelHasChanged (void)
{
	fn_vExistSaveFile ();
}


void Light_Interface::fn_vBeforeSaveAll  (void)
{
	if (m_bSaveRLI)
	{
		// notification to save RLI file
		 fn_vSaveRLIModifyIPO ();

		if (m_bNotifyIPO)
		{
			CPA_BaseObjectList* poListOfIPO = GetInterface()->GetMainWorld()->fn_p_oGetOriginalObjectList (C_szInstanciatedPhysicalObjectTypeName);
			Position xPos;
			CPA_BaseObject* poBaseObject;
			for (poBaseObject = poListOfIPO->GetHeadElement(xPos); poBaseObject; poBaseObject = poListOfIPO->GetNextElement(xPos) )
//ANNECY Shaitan Correction (31/03/98) {
			{
				if (((CPA_SaveObject*)poBaseObject)->GetCurrentNotification() != SCR_EA_Ntfy_DeleteSection)
					((CPA_SaveObject*)poBaseObject)->fn_vNotifySave ();
			}
//ENDANNECY Shaitan Correction (31/03/98) }
			m_bNotifyIPO=FALSE;
		}

		m_bSaveRLI=FALSE;
	}
}

void Light_Interface::fn_vAfterSaveAll  (void)
{
	fn_vExistSaveFile ();
	Light::fn_vSetNotifyHeader (FALSE);
	Light::fn_vUpdateSectorSection ();
}

void Light_Interface::fn_vBeforeEngine (void)
{
	// validate modifs of the dialogs
	m_bRunEngine = TRUE;
	
	// delete all lights super - object in hierarchy
	m_ListDeleteLightBeforeEngine.RemoveAll ();
	m_ListOfParentDeleteLightBeforeEngine.RemoveAll ();


	if (m_o_ModifRadiusLight)
	{
		m_o_ModifRadiusLight->fn_vUnSelect ();
		m_o_ModifRadiusLight=NULL;
	}

	CPA_BaseObjectList* poList = m_poLight->GetInterface()->GetMainWorld()->fn_p_oGetOriginalObjectList (C_szLightTypeName);
	Position xPos;
	CPA_BaseObject* poBaseObject;

	for (poBaseObject = poList->GetHeadElement(xPos); poBaseObject; poBaseObject = poList->GetNextElement(xPos) )
	{
		CPA_SuperObject* poSuperObjectParent = ((Light*)poBaseObject)->GetSuperObject();
		CPA_SuperObject* poSuperObject = (CPA_SuperObject*) poSuperObjectParent->GetHeadElement ();

		if( poSuperObject )
		{
			m_ListDeleteLightBeforeEngine.AddTail ( poSuperObject );
			m_ListOfParentDeleteLightBeforeEngine.AddTail ( poSuperObjectParent );
			GetInterface()->fn_bDeleteObjectInHierarchy ( poSuperObject, FALSE, FALSE, FALSE, FALSE );
		}
	}

	GetInterface()->fn_vUpdateAll (E_mc_JustDraw);
	if (!fn_bIsCurrentEditor()) return;

	g_oFrameGest.mfn_vDisactivateWindow (m_p_oSplitFrameLight);
	m_bDialogOnScreen=FALSE;

}


void Light_Interface::fn_vBeforeEditor (void)
{
	m_bRunEngine = FALSE;

	if (m_bFirstBeforeEditor)
	{
		fn_vGiveProgressInfo ("Loading static lights ...", -1);
		m_bStopDraw=FALSE;
		fn_vExistSaveFile ();
		fn_vLoadStaticLight ();

		m_bFirstBeforeEditor=FALSE;
		fn_vGiveProgressInfo ("Loading static lights", 100);

		// init list of section sector in light objects
		Light::fn_vInitListOfSectionObject ();
		fn_vInitListOfLightSectionSector ();

		fn_vCreate3DSMaxLights ();

		fn_vDeleteInvalideLight ();

		// create list by sector
		CPA_List<CPA_SuperObject>* poList = GetInterface()->GetObjectListByType	(C_szSectorTypeName);
		CPA_SuperObject * p_sector;
		POSITION pos;

		ASSERT (poList);
		for (p_sector = poList -> GetHeadElement(pos); p_sector; 
			 p_sector = poList -> GetNextElement(pos) ) 
		{
			m_stListBySector.AddTail(new Light_ListBySector(p_sector));
		}
		
		// update list by sector
		fn_vUpdateListsBySector();

//ANNECY Shaitan Correction 03/03/98 {
//		m_bNotifyIPO=TRUE;
		m_bNotifyIPO=FALSE;


		CPA_BaseObjectList* poListOfIPO = GetInterface()->GetMainWorld()->fn_p_oGetOriginalObjectList (C_szInstanciatedPhysicalObjectTypeName);
		if (poListOfIPO)
		{
			if (poListOfIPO->GetCount()>0)
			{
//				CPA_BaseObject* poBaseObject = poListOfIPO->GetHead();
//				if (poBaseObject)
				CPA_BaseObject* poBaseObject;
				Position pos = poListOfIPO->GetHeadPosition();
				while (pos)
				{
					poBaseObject = poListOfIPO->GetNext(pos);
					IPO_tdxHandleToInstanciatedPhysicalObject hIPO = (IPO_tdxHandleToInstanciatedPhysicalObject)(poBaseObject->GetData());
//					if (IPO_fn_hGetRadiosity(hIPO)) m_bNotifyIPO=FALSE;
					if (!IPO_fn_hGetRadiosity(hIPO)) m_bNotifyIPO=TRUE;
				}
			}
		}
//ENDANNECY Shaitan Correction }

/*
		CPA_List<CPA_SuperObject>* poListOfSuperIPO = GetInterface()->GetObjectListByType (C_szInstanciatedPhysicalObjectTypeName);
		if (poListOfSuperIPO)
		{
			if (poListOfSuperIPO->GetCount()>0)
			{
				CPA_SuperObject* poSuperObject = poListOfSuperIPO->GetHead();
				if (poSuperObject)
				{
					IPO_tdxHandleToInstanciatedPhysicalObject hIPO = (IPO_tdxHandleToInstanciatedPhysicalObject)(poSuperObject->GetObject()->GetData());
						if (IPO_fn_hGetRadiosity(hIPO)) m_bNotifyIPO=FALSE;
				}
			}
		}
*/
		if (m_bNotifyIPO)
		{
			m_bModifyAll=TRUE;		// compute the whole rli file
			fn_vComputeRLI ();		// m_bNotifyIPO is used here as a flag
		}
	}

	// add lights super objects in hierarchy
	POSITION xPosLight, xPosParent;
	CPA_SuperObject* poSuperObject;
	CPA_SuperObject* poParent;

	for (
		  poSuperObject=m_ListDeleteLightBeforeEngine.GetHeadElement(xPosLight),
		  poParent=m_ListOfParentDeleteLightBeforeEngine.GetHeadElement(xPosParent);
		  poSuperObject;
		  poSuperObject=m_ListDeleteLightBeforeEngine.GetNextElement(xPosLight) ,
		  poParent=m_ListOfParentDeleteLightBeforeEngine.GetNextElement(xPosParent)
		)
		GetInterface()->fn_bInsertObjectInHierarchy (poSuperObject, poParent, FALSE, FALSE, FALSE );

	if (m_ListDeleteLightBeforeEngine.GetCount()||m_bNotifyIPO) GetInterface()->fn_vUpdateAll (E_mc_JustDraw);

	if (!fn_bIsCurrentEditor()) 
		return;

	m_p_oDialogList->fn_vInitAllLists ();
	m_p_oDialogList->fn_vReinitDialog ();

	// activate the frames of the editor
	HWND WindowWithFocus = GetFocus ();
	g_oFrameGest.mfn_vSetRefresh(FALSE);
	g_oFrameGest.mfn_vActivateWindow (m_p_oSplitFrameLight);
	g_oFrameGest.mfn_vActivateWindow ( GetInterface()->GetModelFrame() );
	SetFocus (WindowWithFocus);
	g_oFrameGest.mfn_vSetRefresh(TRUE);
	m_p_oDialogList->SetCurrentType  ( csLightList );
	m_p_oDialogList->SetDefaultButtonState ( FALSE );

	g_csPreviousList = GetInterface()->GetDialogInsert()->fn_csGetCurrentListModel();
	GetInterface()->GetDialogInsert()->fn_vSetCurrentListModel("Light");

	// set the enter editor ( WP or way )
	m_bDialogOnScreen=TRUE;
	m_bRunEngine=FALSE;



}

void Light_Interface::fn_vLoadStaticLight (void)
{
	// we are going to build all the editor objects
	CPA_List <CPA_BaseObject> oList;
	m_ListOfInvalideLight.RemoveAll ();

	// stop prefix
	BOOL bLoadingWorld = GetInterface()->fn_bIsLoadingWorld();
	GetInterface ()->SetLoadingWorld (TRUE);

	// load .lgt
	char szCompleteLevelsFileName[SCR_CV_ui_Cfg_MaxLenName];
	char* pszLevelsFileName;
	fn_zsGetActualLevelFilename ( szCompleteLevelsFileName, c_Light_File_extension );
	pszLevelsFileName = szCompleteLevelsFileName + strlen(fn_szGetLevelsDataPath()) + 1;

	// engine load
	if (SCR_fn_c_RdL0_IsSectionExists (szCompleteLevelsFileName))
		SCR_fnp_st_RdL0_AnalyseSection (pszLevelsFileName,SCR_CDF_uw_Anl_Normal);

	// create all editor objects
	SCR_tdst_Link_Table* pLinkTable = LGT_fn_p_stGetLightLinkTable ();
	unsigned int uiPos;
	SCR_tdst_Link_Value	*pLinkValue;

	uiPos = 0;
	SCR_M_DyAr_GetNextElement
	(
		SCR_tdst_Link_Value,
		uiPos,
		pLinkValue,
		SCR_M_st_Link_GetDynamicArray(pLinkTable)
	)
	while (pLinkValue)
	{
		if (SCR_M_e_Link_GetState(pLinkValue) != SCR_ELS_Link_NotInitialized)
		{
			GLI_tdxHandleToLight hStaticLight = (GLI_tdxHandleToLight) SCR_M_ul_Link_GetValue (pLinkValue);
			CPA_SuperObject* poSuperLight = fn_pCreateNewLightFromEngineHandle ( hStaticLight );
			if (poSuperLight)
			{
				// search position of superobject
				MTH3D_tdstVector stVertex;
				( (Light*)(poSuperLight->GetObject()) )->fn_vSetEngineMatrix(FALSE);
				GEO_tdxHandleToMatrix hAbsoluteObjectMatrix = HIE_fn_hGetSuperObjectGlobalMatrix (poSuperLight->GetStruct());
				POS_fn_vGetTranslationVector( hAbsoluteObjectMatrix , &stVertex ) ;
				CPA_SuperObject* poSector = GetInterface()->GetSpecificInterface()->GetCurrentSectorFromPos (&stVertex);

				if (poSector)
				{
					// insert in hierarchy
					m_bLoadLight=TRUE;
//ANNECY Shaitan EmptySectors 25/02/98
//					if (poSector->GetHeadElement()) GetInterface()->fn_bInsertObjectInHierarchy (poSuperLight, (CPA_SuperObject*)(poSector->GetHeadElement()), FALSE, FALSE, FALSE );
//					else m_ListOfInvalideLight.AddTail ( (Light*)(poSuperLight->GetObject()) );
					GetInterface()->fn_bInsertObjectInHierarchy (poSuperLight, poSector, FALSE, FALSE, FALSE );
//ENDANNECY Shaitan EmptySectors
					m_bLoadLight=FALSE;
				}
				else 
					m_ListOfInvalideLight.AddTail ( (Light*)(poSuperLight->GetObject()) );
			}
		}
		uiPos++;
		SCR_M_DyAr_GetNextElement
		(
			SCR_tdst_Link_Value,
			uiPos,
			pLinkValue,
			SCR_M_st_Link_GetDynamicArray(pLinkTable)
		)
	}



	CPA_List<CPA_SuperObject>* poList = GetInterface()->GetObjectListByType	(C_szSectorTypeName);
	if (poList->IsEmpty()) return;

	POSITION xSuperObjectPos;
	CPA_SuperObject* poSuperObject;

	// loop on the sectors super object
	for ( poSuperObject=poList->GetHeadElement(xSuperObjectPos); poSuperObject; poSuperObject=poList->GetNextElement(xSuperObjectPos) )
	{
		HIE_tdxHandleToSuperObject hSector;
		hSector = (HIE_tdxHandleToSuperObject)(poSuperObject->GetStruct());

		// loop on the engine lights of each sector
		SECT_tdxHandleOfElementLstStaticLights hStaticLightsElement;

		long i;
		SECT_M_ForEachStaticLightsListInSector (hSector,hStaticLightsElement,i)
		{
			GLI_tdxHandleToLight			hStaticLight;
			CString							csSectionName;

			hStaticLight = SECT_GetStaticLightsInList ( hStaticLightsElement );
			// The editor object exist or not ?
			CPA_BaseObject * pEdObj  = GetInterface()->GetMainWorld()->fn_p_oFindObjectWithEngine (hStaticLight, C_szLightTypeName);

			ASSERT (pEdObj);

			Light* poLight = (Light*)pEdObj;
			poLight->fn_vAddSector (poSuperObject);
		}
	}

	Light::fn_pGetDialog()->fn_vEdit (NULL);

	// delete unused light sections
	CPA_BaseObjectList* poListOfLight = GetInterface()->GetMainWorld()->fn_p_oGetOriginalObjectList (C_szLightTypeName);
	Position xPosDeleteLight;
	CPA_BaseObject* poBaseObject;
	BOOL bNotReferenced=FALSE;
	CString csMessage = "Some lights don't affect any sector : ";

	for ( poBaseObject = poListOfLight->GetHeadElement(xPosDeleteLight); poBaseObject; poBaseObject = poListOfLight->GetNextElement(xPosDeleteLight) )
	{
		if ( !((Light*)poBaseObject)->fn_bReferenced() ) 
		{
			bNotReferenced=TRUE;
			csMessage += "\n ";
			csMessage += poBaseObject->GetName();
		}
	}

	if (bNotReferenced)
		MessageBox ( AfxGetMainWnd()->m_hWnd, csMessage, "Light editor Warning", MB_OK|MB_ICONWARNING  );


	// can prefix
	GetInterface ()->SetLoadingWorld (bLoadingWorld);

	// That's all Folks
}


// create lights from 3DSMax file -> .lg2
void Light_Interface::fn_vCreate3DSMaxLights (void)
{
	char szCompleteLevelsFileName[SCR_CV_ui_Cfg_MaxLenName];
	char* pszLevelsFileName;
	BOOL bLoadingWorld = GetInterface()->fn_bIsLoadingWorld();
	GetInterface ()->SetLoadingWorld (TRUE);

	fn_zsGetActualLevelFilename ( szCompleteLevelsFileName, c_Light_3DsMax_File_extension );
	pszLevelsFileName = szCompleteLevelsFileName + strlen(fn_szGetLevelsDataPath()) + 1;


	if (SCR_fn_c_RdL0_IsSectionExists (szCompleteLevelsFileName))
		SCR_fnp_st_RdL0_AnalyseSection (pszLevelsFileName,SCR_CDF_uw_Anl_ForceAnalyse);

	SCR_tdst_Link_Table* pLinkTable = LGT_fn_p_stGetLightLinkTable ();

	unsigned int uiPos;
	SCR_tdst_Link_Value	*pLinkValue;

	// Get first element of array
	uiPos = 0;
	SCR_M_DyAr_GetNextElement
	(
		SCR_tdst_Link_Value,
		uiPos,
		pLinkValue,
		SCR_M_st_Link_GetDynamicArray(pLinkTable)
	)
	while (pLinkValue)
	{
		if (SCR_M_e_Link_GetState(pLinkValue) != SCR_ELS_Link_NotInitialized)
		{
			CString csSectionName = SCR_M_p_sz_Link_GetKey(pLinkValue);
			GLI_tdxHandleToLight hStaticLight = (GLI_tdxHandleToLight) SCR_M_ul_Link_GetValue (pLinkValue);

			char szFileName [SCR_CV_ui_Cfg_MaxLenName];
			char szActionName [SCR_CV_ui_Cfg_MaxLenName];
			char szName [SCR_CV_ui_Cfg_MaxLenName];
			char szSectionName [SCR_CV_ui_Cfg_MaxLenName];
			long lLenghtFileName;
//ROMTEAM BlendRLI (Ionut Grozea 24/02/98)
			long lightIsPaint = 0;
			long lightIsAlpha = 0;
//ENDROMTEAM BlendRLI (Ionut Grozea)

			char* pExtFile = NULL;
			SCR_fn_v_RdL0_SplitSectionName((char*)(LPCSTR) csSectionName, szFileName, szActionName, szName);

			// file extension
			lLenghtFileName = strlen(szFileName);
			pExtFile = szFileName + lLenghtFileName - 3;

			// 3DSMax extension ?
			if (!strcmp (pExtFile,c_Light_3DsMax_File_extension))
			{
//ROMTEAM BlendRLI (Ionut Grozea 24/02/98)
				long lLenghtLightName = strlen(szName);
				char *p_szPaint, *p_szAlpha;

				p_szPaint = strstr(szName, "_paint");
				p_szAlpha = strstr(szName, "_alpha");
				
				if (p_szPaint)
				{
					lightIsPaint = 1;
					strcpy(p_szPaint, "\0");
				}
				if (p_szAlpha)
				{
					lightIsAlpha = 1;
					strcpy(p_szAlpha, "\0");
				}
/*
				char szExtensionName [SCR_CV_ui_Cfg_MaxLenName];

				strcpy(szExtensionName , szName+lLenghtLightName-5);

				if (!strncmp(szExtensionName , "Paint" , 5))
				{
					strcpy(szName+lLenghtLightName-6,"\0");
					lightIsPaint = 1;
					if (!strncmp(szExtensionName , "Alpha" , 5))
					{
						strcpy(szName+lLenghtLightName-6,"\0");
						lightIsAlpha = 1;
					}

				}
				if (!strncmp(szExtensionName , "Alpha" , 5))
				{
					strcpy(szName+lLenghtLightName-6,"\0");
					lightIsAlpha = 1;

					if (!strncmp(szExtensionName , "Paint" , 5))
					{
						strcpy(szName+lLenghtLightName-6,"\0");
						lightIsPaint = 1;
					}

				}
*/
//ENDROMTEAM BlendRLI (Ionut Grozea)
				strcpy ( szFileName + lLenghtFileName - 3, c_Light_File_extension );
				SCR_fn_v_RdL0_ComputeSectionName ( szSectionName, szFileName, szActionName, szName);

				// engine light already in .lgt ?
				strcpy ( ((char*)(LPCSTR) csSectionName) + csSectionName.GetLength() - 3, c_Light_File_extension );
				SCR_tdst_Link_Value* pValue = SCR_fnp_st_Link_SearchKey (pLinkTable, szSectionName);

				if (!pValue)
				{
					// light was not found in .lgt

					// search position of superobject
					MTH3D_tdstVector stVertex;
					POS_tdstCompletePosition stAbsoluteMatrix;

					POS_fn_vSetIdentityMatrix(&stAbsoluteMatrix);

					if ( GLI_lGetLightType (hStaticLight) == GLI_C_lAmbientLight )
					{
						CPA_List<CPA_SuperObject>* poList = m_poLight->GetInterface()->GetInterface()->GetObjectListByType	(/*C_szSectorTypeName*/C_szInstanciatedPhysicalObjectTypeName);
						if (poList)
						{
							CPA_SuperObject* poSuperSector = (CPA_SuperObject*)(poList->GetHead()->GetHead());
							if (poSuperSector)
							{
								GEO_tdxHandleToMatrix hAbsoluteMatrix =  HIE_fn_hGetSuperObjectGlobalMatrix ( poSuperSector->GetStruct() );
								POS_fn_vGetTranslationVector( hAbsoluteMatrix , &stVertex );
								POS_fn_vSetTranslationVector( &stAbsoluteMatrix , &stVertex );
								GLI_xSetLightMatrix ( hStaticLight , &stAbsoluteMatrix );
							}
						}
					}

					GLI_xGetLightMatrix ( hStaticLight , &stAbsoluteMatrix );
					POS_fn_vGetTranslationVector( &stAbsoluteMatrix , &stVertex ) ;
					CPA_SuperObject* poSector = GetInterface()->GetSpecificInterface()->GetCurrentSectorFromPos (&stVertex);

					if (poSector)
					{
						// change link table
						strcpy ( SCR_M_p_sz_Link_GetKey (pLinkValue), szSectionName);

						CPA_SuperObject* poSuperLight = fn_pCreateNewLightFromEngineHandle ( hStaticLight );
						Light* poLight = (Light*)(poSuperLight->GetObject());

//ROMTEAM BlendRLI (Ionut Grozea 24/02/98)
						if (lightIsPaint)
							poLight->fn_vSetTypePaint();
//ENDROMTEAM BlendRLI (Ionut Grozea)

						// set sector to the light
						poLight->fn_vAddSector (poSector);
						poLight->fn_vSetEngineMatrix(FALSE);
						poLight->Set3DsMaxLight (TRUE);

						// force saving section in .lgt
						poLight->SetExistingSection (FALSE);
						poLight->GetMatrixSection()->SetExistingSection (FALSE);
						poLight->fn_vNotifySave();
//ROMTEAM BlendRLI (Ionut Grozea 24/02/98)
						if (lightIsAlpha)
							poLight->fn_vSetLightForAlpha();
//ENDROMTEAM BlendRLI (Ionut Grozea)

						// insert in hierarchy
						m_bLoadLight=TRUE;
//ANNECY Shaitan EmptySectors 25/02/98
//						GetInterface()->fn_bInsertObjectInHierarchy (poSuperLight, (CPA_SuperObject*)(poSector->GetHeadElement()), FALSE, FALSE, FALSE);
						GetInterface()->fn_bInsertObjectInHierarchy (poSuperLight, poSector, FALSE, FALSE, FALSE);
//ENDANNECY Shaitan EmptySectors
						m_bLoadLight=FALSE;
					}
				}
				else
				{
					// set flag icon
					GLI_tdxHandleToLight hEngineLight = (GLI_tdxHandleToLight) SCR_M_ul_Link_GetValue (pValue);
					CPA_BaseObject* poBaseObject  = GetInterface()->GetMainWorld()->fn_p_oFindObjectWithEngine (hEngineLight, C_szLightTypeName);
					( (Light*)poBaseObject )->Set3DsMaxLight (TRUE);
				}
			}
		}
		// Get next element
		uiPos++;
		SCR_M_DyAr_GetNextElement
		(
			SCR_tdst_Link_Value,
			uiPos,
			pLinkValue,
			SCR_M_st_Link_GetDynamicArray(pLinkTable)
		)
	}

	GetInterface ()->SetLoadingWorld (bLoadingWorld);

}

// init the list of section sector used by each light
void Light_Interface::fn_vInitListOfLightSectionSector (void)
{
	Position xPos;
	CPA_BaseObject* poBaseObject;
	CPA_BaseObjectList* poListOfLight = GetInterface()->GetMainWorld()->fn_p_oGetOriginalObjectList (C_szLightTypeName);

	for (poBaseObject=poListOfLight->GetHeadElement(xPos); poBaseObject; poBaseObject=poListOfLight->GetNextElement(xPos) )
	{
		Light* poLight = (Light*) poBaseObject;
		poLight->fn_vUpDateSectorSection ();
	}
}

// delete inavalide light sections
void Light_Interface::fn_vDeleteInvalideLight (void)
{
	POSITION xPos;
	Light* poLight;

	for (poLight = m_ListOfInvalideLight.GetHeadElement(xPos); xPos; m_ListOfInvalideLight.GetNextElement(xPos) )
		poLight->fn_vNotifyUnSave ();
}


//----------------------------------------------------------------------
// Pop-up menu
//----------------------------------------------------------------------
BOOL Light_Interface::fn_bDefinePopupMenu(EDT_PopUpMenu *pPopup, CPA_List<CPA_SuperObject> *pSelection, BOOL bIsAlone)
{
	BOOL bEntry=FALSE;


	if (m_bMainDll)
	{
		m_bMainDll=FALSE;
		return FALSE;
	}
	m_bMainDll=bIsAlone;


	CPA_List<CPA_SuperObject>* poList = GetInterface()->GetSelectedObjects (this);

	if (!poList->GetCount()) m_poRClicLight=NULL;
	else m_poRClicLight = (Light*)(poList->GetHead()->GetObject());

	if (m_poRClicLight)
	{
		if (m_poRClicLight->fn_bGetOnOff())
		{
			char szMes [100];
			sprintf ( szMes, "Realtime light %s off", m_poRClicLight->GetName().GetBuffer(100) );
//CPA2 Corneliu Babiuc 21-05-98
			strcat( szMes, "\t");
			strcat( szMes, (char *)(LPCSTR)m_poKeyboard->mfn_oConvertIniStringToKeyString((const CString*)&CString("Real Time")));
//END CPA2 Corneliu Babiuc 21-05-98
			pPopup->AddAnEntry(this, szMes, c_Light_Popup_Off);
		}
		else
		{
			char szMes [100];
			sprintf ( szMes, "Realtime light %s on", m_poRClicLight->GetName().GetBuffer(100) );
//CPA2 Corneliu Babiuc 21-05-98
			strcat( szMes, "\t");
			strcat( szMes, (char *)(LPCSTR)m_poKeyboard->mfn_oConvertIniStringToKeyString((const CString*)&CString("Real Time")));
//END CPA2 Corneliu Babiuc 21-05-98
			pPopup->AddAnEntry(this, szMes, c_Light_Popup_On);
		}
		bEntry=TRUE;


		if (m_poRClicLight->fn_bIsLightOn())
		{
			char szMes [100];
			sprintf ( szMes, "Switch off light %s", m_poRClicLight->GetName().GetBuffer(100) );
//CPA2 Corneliu Babiuc 21-05-98
			strcat( szMes, "\t");
			strcat( szMes, (char *)(LPCSTR)m_poKeyboard->mfn_oConvertIniStringToKeyString((const CString*)&CString("Light Switch")));
//END CPA2 Corneliu Babiuc 21-05-98
			pPopup->AddAnEntry(this, szMes, c_light_Popup_RealTime_Off);
		}
		else
		{
			char szMes [100];
			sprintf ( szMes, "Switch on light %s", m_poRClicLight->GetName().GetBuffer(100) );
//CPA2 Corneliu Babiuc 21-05-98
			strcat( szMes, "\t");
			strcat( szMes, (char *)(LPCSTR)m_poKeyboard->mfn_oConvertIniStringToKeyString((const CString*)&CString("Light Switch")));
//END CPA2 Corneliu Babiuc 21-05-98
			pPopup->AddAnEntry(this, szMes, c_light_Popup_RealTime_On);
		}
		bEntry=TRUE;


		if (fn_bIsCurrentEditor() & m_poRClicLight->fn_bIs3DsMaxLight())
		{
			char szMes [100];
			sprintf ( szMes, "Update light %s", m_poRClicLight->GetName().GetBuffer(100) );
			pPopup->AddAnEntry(this, szMes, c_light_Popup_Update);
			bEntry=TRUE;
		}
	}

	if (fn_bIsCurrentEditor() & bIsAlone)
	{
		pPopup->AddAnEntry(this, "Exit Light editor", c_Light_Popup_Exit);
		bEntry=TRUE;
	}



	return bEntry;
}

void Light_Interface::_OnPopUpMenuCommand(UINT m_IDCmdMsg)
{
	switch (m_IDCmdMsg)
	{
	case c_Light_Popup_Off:
		m_poRClicLight->fn_vSetOnOff (FALSE);
		Light::fn_pGetDialog()->fn_vSetOnOff (m_poRClicLight);

		break;
	case c_Light_Popup_On:
		m_poRClicLight->fn_vSetOnOff (TRUE);
		Light::fn_pGetDialog()->fn_vSetOnOff (m_poRClicLight);
		break;

	case c_Light_Popup_Exit:
		GetMainWorld ( ) -> fn_bCloseEditor ( this );
		break;

	case c_light_Popup_Update:
		m_poRClicLight->fn_vUpdateLight();
		break;

	case c_light_Popup_RealTime_Off:
		fn_vSwitchOnLight ( m_poRClicLight, FALSE );
		break;

	case c_light_Popup_RealTime_On:
		fn_vSwitchOnLight ( m_poRClicLight, TRUE );
		break;

	}


	m_poRClicLight=NULL;
	m_bMainDll=FALSE;
}


ACP_tdxHandleOfObject Light_Interface::fn_hGetBoundingVolume (CPA_BaseObject *_pObj)
{
	CPA_ObjectDLLBase * pGeomDll = GetInterface()->GetMainWorld()->GetObjectDLLWithName (C_szDLLGeometryName);
	CPA_SuperObject* poGeomSuperObject = (CPA_SuperObject*) ((Light*) _pObj)->GetSuperObject()->GetHeadElement();
	return pGeomDll->fn_hGetBoundingVolume (poGeomSuperObject->GetObject());
}


//----------------------------------------------------------------------
// Keyboard events
//----------------------------------------------------------------------
BOOL Light_Interface::fn_bOnKeyDownInDialog	(CPA_DialogList *pDialog, CString csTypeName, tdeListDrawMode eDraw, CPA_BaseObject *pSelectedObject, UINT nChar, UINT nRepCnt, UINT nFlags)
{
	if (nChar==VK_DELETE)
	{
		// delete only SUPER OBJECT
		if (pSelectedObject->GetType()!=C_szSuperObjectTypeName) return FALSE;

		CPA_SuperObject* poSuperObject = (CPA_SuperObject*) pSelectedObject;

		// only waypoint & way
		if ( poSuperObject->GetObjectType()==HIE_C_ulEDT_Light )
		{
			GetInterface()->fn_bDeleteObjectInHierarchy ( poSuperObject );
			return TRUE;
		}

	}
	return FALSE;
}




//----------------------------------------------------------------------
// Mouse events
//----------------------------------------------------------------------
BOOL Light_Interface::_OnLButtonDown (UINT i, tdstMousePos *pMouse, ACP_tdxIndex xIndex, HIE_tdstPickInfo *pInfo)
{
	CPA_SuperObject		*psoSuperObject, *psoClicked;
	ACP_tdxIndex		xFndIndex;

	fn_vClearStatus ();

	if (m_bOrientLight) return FALSE;


	if (!xIndex)
	{
		m_poLight=NULL;
		return TRUE;
	}

	// light ?
	psoSuperObject = fn_pExplorePicking (xIndex, pInfo, HIE_C_ulEDT_Light, &xFndIndex);
	// to avoid near / far
	if (m_o_ModifRadiusLight && m_o_ModifRadiusLight->GetSuperObject() == psoSuperObject)
	{
		psoClicked = GetInterface()->GetEditorObject(pInfo[xFndIndex].hSprObject);
		if (psoClicked != m_o_ModifRadiusLight->GetSuperObject()->GetSuperObjectFirstChild())
		{
			psoSuperObject = fn_pExplorePicking (xIndex - xFndIndex - 1, &pInfo[xFndIndex+1], HIE_C_ulEDT_Light);
			if (!psoSuperObject)
				psoSuperObject = m_o_ModifRadiusLight->GetSuperObject();
		}
	}


	if (psoSuperObject)
	{
		fn_vEdit ((Light*)(psoSuperObject->GetObject()));
		return FALSE;
	}

	if (i==(MK_CONTROL|MK_LBUTTON) && !g_bKeyUsed)
	{
		psoSuperObject=fn_pExplorePicking (xIndex, pInfo, HIE_C_ulSector);
		if (psoSuperObject)
		{
			if (Light::fn_pGetDialog()->fn_pGetEditLight()) Light::fn_pGetDialog()->fn_vClicSector ( psoSuperObject->GetObject() );
			return TRUE;
		}
	}

	// we don't clic on a light
	if (m_o_ModifRadiusLight)
	{
		m_o_ModifRadiusLight->fn_vUnSelect ();
		m_o_ModifRadiusLight=NULL;
	}
	return FALSE;
}

BOOL Light_Interface::_OnRButtonDown (UINT i, tdstMousePos *, ACP_tdxIndex xIndex, HIE_tdstPickInfo *pInfo)
{
	CPA_SuperObject* psoSuperObject=NULL;

	psoSuperObject=fn_pExplorePicking (xIndex, pInfo, HIE_C_ulEDT_Light);
	// light ?
	if (psoSuperObject)
	{
		m_poRClicLight = (Light*)(psoSuperObject->GetObject());
		return FALSE;
	}

	return FALSE;
}


BOOL Light_Interface::_OnLButtonUp (UINT, tdstMousePos *p_stPos)
{
	if (m_poLight)
	{
		m_poLight=NULL;
		fn_vSetCursor (IDC_POINTER);
		return TRUE;
	}

	return FALSE;
}

//----------------------------------------------------------------------
//         MODELS
//----------------------------------------------------------------------
void Light_Interface::fn_vInitListByType(CPA_World *pWorld)
{
	pWorld->fn_vAddANewListByType ("Light", this);
}


void Light_Interface::fn_vInitListsOfModels (void)
{
	//---- Light model
	GetInterface()->fn_bAddANewModelList("Light", this);

	EDT_Model* pNewModelSpot = new EDT_Model ( this, "Light", csSpotModelName, "objects\\light\\spot.bmp", GetInterface() );
	GetInterface()-> fn_bAddANewModel (pNewModelSpot, "Light", this);

	EDT_Model* pNewModelSpherical = new EDT_Model ( this, "Light", csSphericalModelName, "objects\\light\\sphere.bmp", GetInterface() );
	GetInterface()-> fn_bAddANewModel (pNewModelSpherical, "Light", this);

	EDT_Model* pNewModelParallel = new EDT_Model ( this, "Light", csParallelModelName, "objects\\light\\parallel.bmp", GetInterface() );
	GetInterface()-> fn_bAddANewModel (pNewModelParallel, "Light", this);

	EDT_Model* pNewModelAmbient = new EDT_Model ( this, "Light", csAmbientModelName, "objects\\light\\ambient.bmp", GetInterface() );
	GetInterface()-> fn_bAddANewModel (pNewModelAmbient, "Light", this);
//CHINA WFQ (MT) 16/02/98 {
    EDT_Model* pNewModelParallelBox = new EDT_Model ( this, "Light", csParallelBoxModelName, "objects\\light\\parabox.bmp", GetInterface() );
	GetInterface()-> fn_bAddANewModel (pNewModelParallelBox, "Light", this);
//ENDCHINA WFQ }
//ROMTEAM Z_Light Ionut Grozea 01-05-1998
    EDT_Model* pNewModelZ_Light = new EDT_Model ( this, "Light", csZModelName, "objects\\light\\z_light.bmp", GetInterface() );
	GetInterface()-> fn_bAddANewModel (pNewModelZ_Light, "Light", this);
//ENDROMTEAM Z_Light Ionut Grozea 01-05-1998


//ANNECY jt {
    EDT_Model* pNewModelFog = new EDT_Model ( this, "Light", csFogModelName, "objects\\light\\fog.bmp", GetInterface() );
	GetInterface()-> fn_bAddANewModel (pNewModelFog, "Light", this);
//ENDANNECY jt }
}


void Light_Interface::fn_vBuildNewEditorInstance (CPA_SuperObject *pEditorInstance, HIE_tdxHandleToSuperObject hEngineInstance)
{
	SCR_tdst_Link_Value				*pLinkValue;
	Light							*poEdLight;
	CString							csSectionName;
	char							szFileName[SCR_CV_ui_Cfg_MaxLenName];
	char							szActionName[SCR_CV_ui_Cfg_MaxLenName];
	char							szName[SCR_CV_ui_Cfg_MaxLenName];

	GLI_tdxHandleToLight hEngine = (GLI_tdxHandleToLight) HIE_fn_hGetSuperObjectObject(hEngineInstance);

	// Link table
	SCR_tdst_Link_Table *  pLinkTable = LGT_fn_p_stGetLightLinkTable();

	// Link value
	pLinkValue = SCR_fnp_st_Link_SearchValue(pLinkTable, (unsigned long) hEngine);

	if ((pLinkValue)&&(SCR_M_e_Link_GetState(pLinkValue) == SCR_ELS_Link_Initialized))
		csSectionName = SCR_M_p_sz_Link_GetKey(pLinkValue);

	// get parameters and create object
	SCR_fn_v_RdL0_SplitSectionName((char*)(LPCSTR) csSectionName, szFileName, szActionName, szName);
	poEdLight = new Light( GetMainWorld(), this, hEngine, szName, szFileName, szActionName );
	pEditorInstance->SetObject(poEdLight);
}


CPA_SuperObject* Light_Interface::GetNewInstance (CString csTypeName, CString csModelName, CPA_SuperObject *pParent)
{
	char szLevelFileName [256];
	fn_zsGetActualLevelFilename (szLevelFileName,"lgt");
	long lSizePath = strlen ( fn_szGetLevelsDataPath() );
	CString csLevelName = szLevelFileName+lSizePath+1;

	if (csTypeName==C_szLightTypeName )
	{

		if (csModelName==csSpotModelName)
		{
			//---------------------- Spot
			fn_vSetTypeLight (GLI_C_lHotSpotLight);

			CPA_SuperObject* psoSpot = GetInterface()->GetNewSuperObject ( E_ss_NoSave, C_NoType );

			Light* poSpot = new Light (GetInterface()->GetMainWorld(),this, csLevelName);

			// init objet
			poSpot->SetSuperObject (psoSpot);
			psoSpot->SetObject(poSpot);
			psoSpot->SetModelName (csSpotModelName);
			psoSpot->SetTypeSO (C_Static);


			//---------------------------------- Spot
			CPA_SuperObject* spoGraphicSpot = fn_pGetNewSpotGraphicObject ();

			spoGraphicSpot->SetEditProtected (TRUE);
			spoGraphicSpot->SetSuperObjectOwner (psoSpot);
			psoSpot->AddTail (spoGraphicSpot);

			HIE_fn_vSetSuperObjectDrawMask(psoSpot->GetStruct(), GLI_C_lAllIsEnable);

			// inversion Z -> -Z
			GEO_tdxHandleToMatrix hLocalMatrix = HIE_fn_hGetSuperObjectMatrix ( psoSpot->GetStruct() );
//			MTH3D_tdstVector stI, stY, stK;
			/*
			POS_fn_vGetRotationMatrix( hLocalMatrix ,
				&stI, &stY, &stK );

			MTH3D_M_vMulScalarVector(&stK,-1,&stK);
			MTH3D_M_vMulScalarVector(&stY,-1,&stY);

			POS_fn_vSetRotationMatrix( hLocalMatrix ,
				&stI, &stY, &stK );
			*/

			// update for alpha
			GLI_vSetAlphaLightFlag((GLI_tdxHandleToLight)poSpot->GetEngineStruct(),2);
			GLI_vSetLightPerso((GLI_tdxHandleToLight)poSpot->GetEngineStruct(), FALSE);

			return psoSpot;
		}

		else if (csModelName==csSphericalModelName)
		{
			//---------------------- Spherical
			fn_vSetTypeLight (GLI_C_lSphericalLight);

			CPA_SuperObject* psoSpherical = GetInterface()->GetNewSuperObject ( E_ss_NoSave, C_NoType);
			Light* poSpherical = new Light (GetInterface()->GetMainWorld(),this,csLevelName);

			// init objet
			poSpherical->SetSuperObject (psoSpherical);
			psoSpherical->SetObject(poSpherical);
			psoSpherical->SetModelName (csSphericalModelName);
			psoSpherical->SetTypeSO (C_Static);

			//---------------------------------- Spherical
			CPA_SuperObject* spoGraphicSpherical = fn_pGetNewSphericalGraphicObject ();
			spoGraphicSpherical->SetEditProtected (TRUE);
			spoGraphicSpherical->SetSuperObjectOwner (psoSpherical);
			psoSpherical->AddTail (spoGraphicSpherical);

			HIE_fn_vSetSuperObjectDrawMask(psoSpherical->GetStruct(), GLI_C_lAllIsEnable);

			// update for alpha
			GLI_vSetAlphaLightFlag((GLI_tdxHandleToLight)poSpherical->GetEngineStruct(),2);
			GLI_vSetLightPerso((GLI_tdxHandleToLight)poSpherical->GetEngineStruct(), FALSE);

			return psoSpherical;
		}

		else if (csModelName==csParallelModelName)
		{
			//---------------------- Parallel
			fn_vSetTypeLight (GLI_C_lParallelLight);

			CPA_SuperObject* psoParallel = GetInterface()->GetNewSuperObject ( E_ss_NoSave, C_NoType);
			Light* poParallel = new Light (GetInterface()->GetMainWorld(),this,csLevelName);

			// init objet
			poParallel->SetSuperObject (psoParallel);
			psoParallel->SetObject(poParallel);
			psoParallel->SetModelName (csParallelModelName);
			psoParallel->SetTypeSO (C_Static);

			//---------------------------------- Parallel
			CPA_SuperObject* spoGraphicParallel = fn_pGetNewParallelGraphicObject ();
			spoGraphicParallel->SetEditProtected (TRUE);
			spoGraphicParallel->SetSuperObjectOwner (psoParallel);
			psoParallel->AddTail (spoGraphicParallel);

			// inversion Z -> -Z
			GEO_tdxHandleToMatrix hLocalMatrix = HIE_fn_hGetSuperObjectMatrix ( psoParallel->GetStruct() );
			MTH3D_tdstVector stI, stY, stK;

			POS_fn_vGetRotationMatrix( hLocalMatrix ,
				&stI, &stY, &stK );

			MTH3D_M_vMulScalarVector(&stK,MTH_C_MinusONE,&stK);
			MTH3D_M_vMulScalarVector(&stY,MTH_C_MinusONE,&stY);

			POS_fn_vSetRotationMatrix( hLocalMatrix ,
				&stI, &stY, &stK );

			// update for alpha
			GLI_vSetAlphaLightFlag((GLI_tdxHandleToLight)poParallel->GetEngineStruct(),2);
			GLI_vSetLightPerso((GLI_tdxHandleToLight)poParallel->GetEngineStruct(), FALSE);

			return psoParallel;
		}

		else if (csModelName==csAmbientModelName)
		{
			//---------------------- Ambient
			fn_vSetTypeLight (GLI_C_lAmbientLight);

			CPA_SuperObject* psoAmbient = GetInterface()->GetNewSuperObject ( E_ss_NoSave, C_NoType);
			Light* poAmbient = new Light (GetInterface()->GetMainWorld(),this,csLevelName);

			// init objet
			poAmbient->SetSuperObject (psoAmbient);
			psoAmbient->SetObject(poAmbient);
			psoAmbient->SetModelName (csAmbientModelName);
			psoAmbient->SetTypeSO (C_Static);

			CPA_SuperObject* spoGraphicAmbient = fn_pGetNewAmbientGraphicObject ();
			spoGraphicAmbient->SetEditProtected (TRUE);
			spoGraphicAmbient->SetSuperObjectOwner (psoAmbient);
			psoAmbient->AddTail (spoGraphicAmbient);

			// update for alpha
			GLI_vSetAlphaLightFlag((GLI_tdxHandleToLight)poAmbient->GetEngineStruct(),2);
			GLI_vSetLightPerso((GLI_tdxHandleToLight)poAmbient->GetEngineStruct(), FALSE);

			return psoAmbient;

		}
//CHINA WFQ (MT) 16/02/98 {
		else if (csModelName==csParallelBoxModelName)
		{

			//---------------------- ParallelBox
			fn_vSetTypeLight (GLI_C_lParallelLight_With_Limit);

			CPA_SuperObject* psoParallelBox = GetInterface()->GetNewSuperObject ( E_ss_NoSave, C_NoType);
			Light* poParallelBox = new Light (GetInterface()->GetMainWorld(),this,csLevelName);

			// init objet
			poParallelBox->SetSuperObject (psoParallelBox);
			psoParallelBox->SetObject(poParallelBox);
			psoParallelBox->SetModelName (csParallelBoxModelName);
			psoParallelBox->SetTypeSO (C_Static);

			//---------------------------------- ParallelBox
			CPA_SuperObject* spoGraphicParallelBox = fn_pGetNewParallelBoxGraphicObject ();
			spoGraphicParallelBox->SetEditProtected (TRUE);
			spoGraphicParallelBox->SetSuperObjectOwner (psoParallelBox);
			psoParallelBox->AddTail (spoGraphicParallelBox);

			// update for alpha
			GLI_vSetAlphaLightFlag((GLI_tdxHandleToLight)poParallelBox->GetEngineStruct(),2);
			GLI_vSetLightPerso((GLI_tdxHandleToLight)poParallelBox->GetEngineStruct(), FALSE);

			return psoParallelBox;
		}
//ENDCHINA WFQ }
//ROMTEAM Z_Light Ionut Grozea 01-05-1998
		else if (csModelName==csZModelName)
		{

			//---------------------- ZModel
//			fn_vSetTypeLight (GLI_C_lZ_Light);

			CPA_SuperObject* psoZModel = GetInterface()->GetNewSuperObject ( E_ss_NoSave, C_NoType);
			Light* poZModel = new Light (GetInterface()->GetMainWorld(),this,csLevelName);

			// init objet
			poZModel->SetSuperObject (psoZModel);
			psoZModel->SetObject(poZModel);
			psoZModel->SetModelName (csZModelName);
			psoZModel->SetTypeSO (C_Static);

			//---------------------------------- ZModel
			CPA_SuperObject* spoGraphicZModel = fn_pGetNewZGraphicObject ();
			spoGraphicZModel->SetEditProtected (TRUE);
			spoGraphicZModel->SetSuperObjectOwner (psoZModel);
			psoZModel->AddTail (spoGraphicZModel);

			// update for alpha
			GLI_vSetAlphaLightFlag((GLI_tdxHandleToLight)poZModel->GetEngineStruct(),2);
			GLI_vSetLightPerso((GLI_tdxHandleToLight)poZModel->GetEngineStruct(), FALSE);

			return psoZModel;
		}
		
//ENDROMTEAM Z_Light Ionut Grozea 01-05-1998


//ANNECY jt {
		else if (csModelName==csFogModelName)
		{
			GLI_tdxHandleToLight hLight;
			//---------------------- Fog
			fn_vSetTypeLight (GLI_C_lFogLight);

			CPA_SuperObject* psoFog = GetInterface()->GetNewSuperObject ( E_ss_NoSave, C_NoType);
			Light* poFog = new Light (GetInterface()->GetMainWorld(),this,csLevelName);

			// init objet
			poFog->SetSuperObject (psoFog);
			psoFog->SetObject(poFog);
			psoFog->SetModelName (csFogModelName);
			psoFog->SetTypeSO (C_Static);

			CPA_SuperObject* spoGraphicFog = fn_pGetNewFogGraphicObject ();
			spoGraphicFog->SetEditProtected (TRUE);
			spoGraphicFog->SetSuperObjectOwner (psoFog);
			psoFog->AddTail (spoGraphicFog);

			HIE_fn_vSetSuperObjectDrawMask(psoFog->GetStruct(), GLI_C_lAllIsEnable);
			
			hLight = (GLI_tdxHandleToLight) (psoFog->GetObject()->GetData());
			GLI_fn_vFogSetNear(hLight, MTH_C_ZERO);
			GLI_fn_vFogSetFar(hLight, 15.f);
			GLI_fn_vFogSetInfinite(hLight, 50000.f);
			GLI_fn_vFogSetBlendNear(hLight, MTH_C_ZERO);
			GLI_fn_vFogSetBlendFar(hLight, 150.f);

			GLI_vSetLightPerso((GLI_tdxHandleToLight)poFog->GetEngineStruct(), FALSE);

			return psoFog;
		}
//ENDANNECY jt }

        else return NULL;
	}

	else return NULL;
}



CPA_SuperObject* Light_Interface::fn_pCreateNewLightFromEngineHandle ( GLI_tdxHandleToLight hStaticLight )
{
	CString					csSectionName;
	char*					pszShortFileName;
	char					szFileName[SCR_CV_ui_Cfg_MaxLenName];
	char					szActionName[SCR_CV_ui_Cfg_MaxLenName];
	char					szName[SCR_CV_ui_Cfg_MaxLenName];
	CPA_SuperObject*		poSuperObject;
	CPA_SuperObject*		poGraphic;
	Light*					poLight;
	long lType = GLI_lGetLightType (hStaticLight);



	// Link table
	SCR_tdst_Link_Table* pLinkTable = LGT_fn_p_stGetLightLinkTable();

	// Link value
	SCR_tdst_Link_Value* pLinkValue = SCR_fnp_st_Link_SearchValue(pLinkTable, (unsigned long) hStaticLight);

	if ((pLinkValue)&&(SCR_M_e_Link_GetState(pLinkValue) == SCR_ELS_Link_Initialized))
		csSectionName = SCR_M_p_sz_Link_GetKey(pLinkValue);

	// get parameters and create object
	SCR_fn_v_RdL0_SplitSectionName((char*)(LPCSTR) csSectionName, szFileName, szActionName, szName);


	long lSizePath = strlen ( fn_szGetLevelsDataPath() );
	pszShortFileName = szFileName + lSizePath + 1;

	poSuperObject = GetInterface()->GetNewSuperObject (E_ss_NoSave, C_NoType);

	// object construction
	switch (lType)
	{
		case GLI_C_lParallelLight :
		{
			fn_vSetTypeLight (GLI_C_lParallelLight);
			poSuperObject->SetModelName (csParallelModelName);
			poLight = new Light( GetMainWorld(), this, hStaticLight, szName, pszShortFileName, szActionName);
			poGraphic = fn_pGetNewParallelGraphicObject (hStaticLight);
		} break;

		case GLI_C_lSphericalLight :
		{
			fn_vSetTypeLight (GLI_C_lSphericalLight);
			poSuperObject->SetModelName (csSphericalModelName);
			poLight = new Light( GetMainWorld(), this, hStaticLight, szName, pszShortFileName, szActionName);
			poGraphic = fn_pGetNewSphericalGraphicObject (hStaticLight);
		} break;

		case GLI_C_lHotSpotLight :
		{
			fn_vSetTypeLight (GLI_C_lHotSpotLight);
			poSuperObject->SetModelName (csSpotModelName);
			poLight = new Light( GetMainWorld(), this, hStaticLight, szName, pszShortFileName, szActionName);
			poGraphic = fn_pGetNewSpotGraphicObject (hStaticLight);
		} break;
//CHINA WFQ (MT) 16/02/98 {
		case GLI_C_lParallelLight_With_Limit :
		{
			fn_vSetTypeLight (GLI_C_lParallelLight_With_Limit);
			poSuperObject->SetModelName (csParallelBoxModelName);
			poLight = new Light( GetMainWorld(), this, hStaticLight, szName, pszShortFileName, szActionName);
			poGraphic = fn_pGetNewParallelBoxGraphicObject ();
		} break;
//ENDCHINA WFQ }
//ROMTEAM Z_Light Ionut Grozea 01-05-1998
/*
		case GLI_C_lZ_Light :
		{
			fn_vSetTypeLight (GLI_C_lZ_Light);
			poSuperObject->SetModelName (csZModelName);
			poLight = new Light( GetMainWorld(), this, hStaticLight, szName, pszShortFileName, szActionName);
 			poGraphic = fn_pGetNewZGraphicObject();
		} break;
*/
//ENDROMTEAM Z_Light Ionut Grozea 01-05-1998

		case GLI_C_lAmbientLight :
		{
			fn_vSetTypeLight (GLI_C_lAmbientLight);
			poSuperObject->SetModelName (csAmbientModelName);
			poLight = new Light( GetMainWorld(), this, hStaticLight, szName, pszShortFileName, szActionName);
			poGraphic = fn_pGetNewAmbientGraphicObject (hStaticLight);
		} break;
//ANNECY jt {
		case GLI_C_lFogLight :
		{
			fn_vSetTypeLight (GLI_C_lFogLight);
			poSuperObject->SetModelName (csFogModelName);
			poLight = new Light( GetMainWorld(), this, hStaticLight, szName, pszShortFileName, szActionName);
			poGraphic = fn_pGetNewFogGraphicObject (hStaticLight);
		} break;
//ENDANNECY jt }	
	
	}

	// common assignation
		// init objet
		poLight->SetSuperObject (poSuperObject);
		poSuperObject->SetObject(poLight);
		poSuperObject->SetTypeSO (C_Static);

		// init graphic object
		poGraphic->SetEditProtected (TRUE);
		poGraphic->SetSuperObjectOwner (poSuperObject);
		poSuperObject->AddTail (poGraphic);
		HIE_fn_vSetSuperObjectDrawMask(poSuperObject->GetStruct(), GLI_C_lAllIsEnable);


		// set matrix to super object
		GLI_tdxHandleToLight hLight = (GLI_tdxHandleToLight)(poLight->GetEngineStruct ());
		GEO_tdxHandleToMatrix hMatrix = HIE_fn_hGetSuperObjectMatrix ( poLight->GetSuperObject()->GetStruct() );
		GLI_xGetLightMatrix ( hLight, hMatrix ) ;

	return poSuperObject;
}


//------ Copy-paste
CPA_BaseObject * Light_Interface::Duplicate	  (CPA_BaseObject *pObject, CPA_SuperObject *pNewSuperObject)
{
	Light* poLight = new Light (*((Light*)pObject));
	poLight->fn_vNotifySave ();

	// init objet
	poLight->SetSuperObject (pNewSuperObject);
	pNewSuperObject->SetObject(poLight);
	pNewSuperObject->SetTypeSO (C_Static);

	return poLight;
}

CPA_SuperObject* Light_Interface::GetCopyOfProtectedChild (CPA_SuperObject *pInitialChild, CPA_SuperObject *pNewOwner)
{
	// construct new child
	CPA_SuperObject* poNewChild = GetInterface ()->GetCopyOfSuperObject (pInitialChild);
	CPA_BaseObject * poNewObject = pInitialChild->GetObjectDLL()->Duplicate(pInitialChild->GetObject(), poNewChild);
	pInitialChild->SetObject(poNewObject);

	// update parameters
	CPA_SuperObject* poInitialOwner = pInitialChild->GetSuperObjectOwner();
	Light * poInitialLight = (Light *) poInitialOwner->GetObject();
	Light * poNewLight =  (Light *) pNewOwner->GetObject();

	if (pInitialChild == poInitialLight->m_poNearSuperObject)
	{
		poNewLight->m_poNearSuperObject = poNewChild;
		poNewLight->m_bSelect = TRUE;
	}
	if (pInitialChild == poInitialLight->m_poFarSuperObject)
	{
		poNewLight->m_poFarSuperObject = poNewChild;
		poNewLight->m_bSelect = TRUE;
	}
	if (pInitialChild == poInitialLight->m_poInterSuperObject)
	{
		poNewLight->m_poInterSuperObject = poNewChild;
		poNewLight->m_bSelect = TRUE;
	}
	if (pInitialChild == poInitialLight->m_poExterSuperObject)
	{
		poNewLight->m_poExterSuperObject = poNewChild;
		poNewLight->m_bSelect = TRUE;
	}

	return poNewChild;
}

CPA_SuperObject* Light_Interface::GetParentForInsertion	 (CString csTypeName, CString csModelName, tdstPosition *p_stPosition)
{
//ANNECY Shaitan Correction 03/03/98 {
	if (!p_stPosition->xIndex)
		return NULL;
//ENDANNECY Shaitan Correction }

	if ( (csModelName=="Spherical")||(csModelName=="Spot")||(csModelName=="Parallel") )
	{
		CPA_SuperObject* poSuperObject;
		poSuperObject = GetInterface()->GetSpecificInterface()->GetCurrentSectorFromPos (&(p_stPosition->stPos.stPos3D));
//ANNECY Shaitan EmptySectors 25/02/98
//		if (!poSuperObject) return NULL;
//		return (CPA_SuperObject*)(poSuperObject->GetHeadElement ());
		return poSuperObject;
//ENDANNECY Shaitan EmptySectors
	}
	return NULL;
}


tdeTypeSO Light_Interface::GetTypeInstance (CString csTypeName, CString csModelName)
{
	return C_Static;
}

//ANNECY Shaitan EmptySectors 25/02/98
tdeSaveStatus Light_Interface::GetStatusInstance (CString csTypeName, CString csModelName)
{
	return E_ss_NoSave;
}
//ENDANNECY Shaitan EmptySectors

EDT_Model* Light_Interface::fn_pstLoadNewDescriptor (void)
{
	return NULL;
}


CPA_BaseObject* Light_Interface::GetNewObject (CString csObjectFile, CString csObjectName, FILE *p_fFile, CPA_MainWorld *p_oMainWorld)
{
	return NULL;
}

//-------------------------------------------------------------------
//					Orientation
//-------------------------------------------------------------------
BOOL Light_Interface::fn_bAcceptOrientInstance (CPA_SuperObject *pEdObj)
{
	if (pEdObj->GetObjectType()==HIE_C_ulEDT_Light)
	{
		Light* poLight = (Light*) (pEdObj->GetObject());
		if( poLight->fn_lGetType()==GLI_C_lHotSpotLight || poLight->fn_lGetType()==GLI_C_lParallelLight )
		{
			return TRUE;
		}
	}
	return FALSE;
}

BOOL Light_Interface::fn_bOnClickOrientPosition (CPA_SuperObject *pEdObj, tdstPosition *pOrientPosition)
{
	unsigned long ulFlags;

	ASSERT(pEdObj->GetObjectType()==HIE_C_ulEDT_Light);

	Light* poLight = (Light*) (pEdObj->GetObject());

	ASSERT( poLight->fn_lGetType()==GLI_C_lHotSpotLight || poLight->fn_lGetType()==GLI_C_lParallelLight );

	if( fn_bIsCurrentEditor() ) fn_vEdit( poLight );
	ulFlags = HIE_fn_SO_ulGetFlags(pEdObj->GetStruct());
	ulFlags |= HIE_C_Flag_ulNotPickable;
	HIE_fn_SO_vSetFlags(pEdObj->GetStruct(), ulFlags);
	m_bOrientLight=TRUE;
	return TRUE;
}

BOOL Light_Interface::fn_bOnOrientingObject (CPA_SuperObject *pEdObj, tdstPosition *pOrientPosition)
{
	if (!m_bOrientLight) return FALSE;
	Light* poLight = (Light*) (pEdObj->GetObject());
	MTH3D_tdstVector v = pOrientPosition->stPos.stPos3D;
	poLight->fn_vOrientLight ( &v );
	fn_vComputeRLI ();
	poLight->fn_vSetModify (TRUE);
	return TRUE;
}

BOOL Light_Interface::fn_bOnEndOrientObject (CPA_SuperObject *pEdObj, tdstPosition *pOrientPosition)
{
	unsigned long ulFlags;

	if (!m_bOrientLight) return FALSE;
	GetInterface()->fn_vAddSelectedObject (pEdObj);
	m_bOrientLight=FALSE;
	ulFlags = HIE_fn_SO_ulGetFlags(pEdObj->GetStruct());
	ulFlags &= ~HIE_C_Flag_ulNotPickable;
	HIE_fn_SO_vSetFlags(pEdObj->GetStruct(), ulFlags);
	return TRUE;
}




//-------------------------------------------------------------------
//									MENU
//-------------------------------------------------------------------

//**************************************************************************************
//Begin Mircea Dunka 31 Aug 1998 - DialogBar interface
void Light_Interface::fn_vDefineDlgBarBtnIcon (tde_DlgBarCategory wCategory, tds_DlgBarBtn *_pDlgBarBtn)
{
	if(wCategory == C_DlgBarCategoryEditor)
	{
		_pDlgBarBtn->hIcon = ::LoadIcon((HINSTANCE)(GetDLLIdentity()->hModule), MAKEINTRESOURCE(IDI_OLG_DLGBAR_ICON));

        CString oCst;
        oCst = "Light";
        if( (M_GetMainApp()) && (M_GetMainApp()->mp_oAppKeyboard) )
        {
            oCst += "  (";
            oCst += M_GetMainApp()->mp_oAppKeyboard->mfn_oConvertIniStringToKeyString((const CString*)&CString("Activate Light Editor"));
			oCst += ")";
        }
		strcpy(_pDlgBarBtn->szToolTip, (char*)(LPCTSTR)oCst);
		_pDlgBarBtn->uID = (UINT)this;
	}
}
//end Mircea Dunka 31 Aug 1998


//----------------------- SubMenu
BOOL Light_Interface::fn_bDefineSubMenu(EDT_SubMenu *_p_oEDTSubMenu)
{

	if (_p_oEDTSubMenu->GetSubMenuType() == C_SubMenuEditor)
	{
		CString csEntry = "Light";
		csEntry += "\t";
		csEntry += M_GetMainApp()->mp_oAppKeyboard->mfn_oConvertIniStringToKeyString((const CString*)&CString("Activate Light Editor"));

		_p_oEDTSubMenu->AddAnEntry(this, (char*)(LPCTSTR)csEntry, c_Light_Submenu_Activate, fn_bIsCurrentEditor());
		return TRUE;
	}

	else if (_p_oEDTSubMenu->GetSubMenuType() == C_SubMenuSpecific && fn_bIsCurrentEditor())
	{
		// RLI
		_p_oEDTSubMenu->AddAnEntry(this, "Compute RLI", c_Light_SubMenu_Compute_RLI);

		if (fn_bIs3DsMaxLight()) _p_oEDTSubMenu->AddAnEntry(this, "Update 3DsMax light", c_Light_SubMenu_UpDate_Light);
		_p_oEDTSubMenu->AddASeparator();
		_p_oEDTSubMenu->AddAnEntry(this, "Save Dialogs Dimensions", c_Light_SubMenu_Save_Preference, FALSE, TRUE);
		return TRUE;
	}

	return FALSE;
}


void Light_Interface::_OnSubMenuCommand(EDT_SubMenu *_p_oEDTSubMenu,UINT uiMsgID)
{
	if (_p_oEDTSubMenu->GetSubMenuType()==C_SubMenuEditor)
	{

		switch ( uiMsgID )
		{
			case c_Light_Submenu_Activate:
			if  (fn_bIsCurrentEditor())
		        GetMainWorld ( ) -> fn_bCloseEditor ( this );
			else
		        GetMainWorld ( ) -> fn_bActivateEditor (this, NULL );
			break;
		}
	}

	else if (_p_oEDTSubMenu->GetSubMenuType()==C_SubMenuSpecific)
	{
		switch (uiMsgID)
		{
			case c_Light_SubMenu_Compute_RLI :
				m_bModifyAll=TRUE;
				fn_vComputeRLI ();
				GetInterface()->fn_vUpdateAll (E_mc_JustDraw);
				m_bNotifyIPO=TRUE;
				break;
			case c_Light_SubMenu_UpDate_Light :
				fn_vUpDateAllLight ();
				break;
			case c_Light_SubMenu_Save_Preference:
				fn_vSaveDialogsPreferences ();
				break;
		}
	}
}

//-------------------------------------------------------------------
// MOVES
//-------------------------------------------------------------------
void Light_Interface::fn_vOnBeginMove (CPA_List<CPA_SuperObject> *pListObjects, CPA_List<CPA_SuperObject> *pListConcerned, tdeStatus eStatus)
{
	CPA_SuperObject* poSuperObject;
	POSITION xPos;

	if (eStatus!=C_AsConcernedDLL) return;
	m_ListMovingLight.RemoveAll ();

	for
	(
		poSuperObject=pListConcerned->GetHeadElement(xPos);
		poSuperObject;
		poSuperObject=pListConcerned->GetNextElement(xPos)
	)
	if (poSuperObject->GetObjectType()==HIE_C_ulEDT_Light) 
		m_ListMovingLight.AddTail ((Light*)(poSuperObject->GetObject()));
}


void Light_Interface::fn_vOnMoving (CPA_List<CPA_SuperObject> *pListObjects, CPA_List<CPA_SuperObject> *pListConcerned, tdeStatus eStatus)
{
	Light* poLight;
	POSITION xPos;

	for
	(
		poLight=m_ListMovingLight.GetHeadElement(xPos);
		poLight;
		poLight=m_ListMovingLight.GetNextElement(xPos)
	)
	poLight->fn_vSetEngineMatrix (FALSE);
	fn_vComputeRLI ();
}


void Light_Interface::fn_vOnModifMove (CPA_List<EDT_SavePos> *pListObjects, CPA_List<EDT_SaveGlobalPos> *pListConcerned, tdeTypeModif eType, tdeStatus eStatus)
{
	POSITION xPos;
	EDT_SavePos* pstSavePos;

	// if move is cancel, no need to recompute affected sectors
	if (eType==C_EDTCancel) return;

	for
	(
		pstSavePos = pListObjects->GetHeadElement(xPos);
		pstSavePos;
		pstSavePos = pListObjects->GetNextElement(xPos)
	)
	if (pstSavePos->m_pObject->GetObjectType()==HIE_C_ulEDT_Light)
	{

		fn_vComputeRLI ();
		((Light*)(pstSavePos->m_pObject->GetObject()))->fn_vSetModify (TRUE);
		((Light*)(pstSavePos->m_pObject->GetObject()))->fn_vSetEngineMatrix (FALSE);
		((Light*)(pstSavePos->m_pObject->GetObject()))->fn_vNotifySave();

		// if we change of sector -> compute the affected sectors
		MTH3D_tdstVector stVertex;
		POS_fn_vGetTranslationVector( pstSavePos->m_hInitialMatrix, &stVertex );
		CPA_SuperObject* poInitialSuperSector = GetInterface()->GetSpecificInterface()->GetCurrentSectorFromPos (&stVertex);

		POS_fn_vGetTranslationVector( pstSavePos->m_hFinalMatrix, &stVertex );
		CPA_SuperObject* poFinalSuperSector = GetInterface()->GetSpecificInterface()->GetCurrentSectorFromPos (&stVertex);

		if (poInitialSuperSector!=poFinalSuperSector)
		{
			((Light*)(pstSavePos->m_pObject->GetObject()))->fn_vComputeSector ();
			Light::fn_pGetDialog()->fn_vRefreshDialog ();
		}
	}

	GetInterface()->fn_vUpdateAll (E_mc_JustDraw);
// Begin Silviu Simen List by Sector and type
	m_p_oDialogList->fn_vUpdateSelection(E_lrm_ReinitList);
// End Silviu Simen List by Sector and type
}

//-------------------------------------------------------------------
// OnModif
//-------------------------------------------------------------------
void Light_Interface::fn_vOnModifDelete  (CPA_List<EDT_SaveParents> *pListObjects, tdeTypeModif eType, tdeStatus eStatus)
{
	if (eStatus!=C_AsConcernedDLL) return;
	if (m_bSkipOnModifDelete) return;

	BOOL bRefreshLight=FALSE;

	fn_vRefreshHierarchyList ();

	POSITION xPos;
	EDT_SaveParents* pstSaveParent;

	for
	(
		pstSaveParent = pListObjects->GetHeadElement(xPos);
		pstSaveParent;
		pstSaveParent = pListObjects->GetNextElement(xPos)
	)
	if (pstSaveParent->m_pChild->GetObjectType()==HIE_C_ulEDT_Light)
	{

		if (eType==C_EDTUndo) ((Light*)(pstSaveParent->m_pChild->GetObject()))->fn_vNotifyRestore ();
		else ((Light*)(pstSaveParent->m_pChild->GetObject()))->fn_vNotifyUnSave ();

		if (eType==C_EDTUndo) fn_vEdit ((Light*)(pstSaveParent->m_pChild->GetObject()));
		else if ( Light::fn_pGetDialog()->fn_pGetEditLight()== (Light*)(pstSaveParent->m_pChild->GetObject()) )
			Light::fn_pGetDialog()->fn_vEdit (NULL);

		if (eType==C_EDTUndo) ((Light*)(pstSaveParent->m_pChild->GetObject()))->fn_bValidate ();
		else ((Light*)(pstSaveParent->m_pChild->GetObject()))->fn_bUnValidate ();

		fn_vRefreshLight ( (Light*)(pstSaveParent->m_pChild->GetObject()), eType!=C_EDTUndo );
	}
}

void Light_Interface::fn_vOnModifParent  (CPA_List<EDT_SaveParents> *pListObjects, tdeTypeModif eType, tdeStatus eStatus)
{
	// check if lights are concerned
	if (eStatus!=C_AsConcernedDLL) 
		return;

	POSITION xPos;
	EDT_SaveParents* pstSaveParent;

	// check if other objects are concerned
	for (pstSaveParent = pListObjects->GetHeadElement(xPos); pstSaveParent;
		 pstSaveParent = pListObjects->GetNextElement(xPos))
	{
		if (pstSaveParent->m_pChild->GetObjectType()!=HIE_C_ulEDT_Light)
			return;
	}

	// if only lights are concerned, cancel the parent coloration
	GetInterface()->fn_vSetLocalColor(M_GetWorld()->GetRoot(), E_lm_ShowNormal);
	// check if other objects are concerned
	for (pstSaveParent = pListObjects->GetHeadElement(xPos); pstSaveParent;
		 pstSaveParent = pListObjects->GetNextElement(xPos))
	{
		GetInterface()->fn_vSetLocalColor(pstSaveParent->m_pChild, E_lm_ShowSelected);
	}
}
		
void Light_Interface::fn_vOnModifInsert (CPA_SuperObject *pEdObj, CPA_SuperObject *pParent, tdstPosition *p_stPosition, tdeTypeModif eType, tdeStatus eStatus)
{
	if (pEdObj->GetObjectType()!=HIE_C_ulEDT_Light) return;
	if (eStatus!=C_AsConcernedDLL) return;

	fn_vRefreshHierarchyList ();


	if (eType==C_EDTUndo)
	{
		Light* poLight = (Light*) pEdObj->GetObject();
		poLight->fn_vNotifyUnSave ();
		if ( Light::fn_pGetDialog()->fn_pGetEditLight()== poLight ) Light::fn_pGetDialog()->fn_vEdit (NULL);
		poLight->fn_bUnValidate ();
		fn_vRefreshLight (poLight, TRUE);
		return;
	}

	if (fn_bGetColorMode())
		((Light*)(pEdObj->GetObject()))->Set2Colors();
	else
		((Light*)(pEdObj->GetObject()))->SetMultiColor();

	if (eType==C_EDTRedo)
	{
		((Light*) (pEdObj->GetObject()))->fn_vNotifyRestore ();
	}

	// rotate the local axis to make Oz toward the floor
	GEO_tdxHandleToMatrix hMatrix = HIE_fn_hGetSuperObjectMatrix ( (HIE_tdxHandleToSuperObject)(pEdObj->GetStruct()) );
	((Light*)(pEdObj->GetObject()))->fn_vSetEngineMatrix(FALSE);


	// search position of superobject
	if (p_stPosition)
	{
		MTH3D_tdstVector stVertex = p_stPosition->stPos.stPos3D;
		((Light*)(pEdObj->GetObject()))->fn_vComputeSector ( &stVertex );
	}

	if (!m_bLoadLight)
	{
		fn_vRefreshLight ((Light*)(pEdObj->GetObject()));

		// refresh the dialog
		if (pEdObj->GetRealTypeName()==C_szLightTypeName )
		{
			// we don't want to clean warning status line
			BOOL bCleanStatus = m_bClearStatus;
			m_bClearStatus = FALSE;

			fn_vEdit ( (Light*)(pEdObj->GetObject()) );

			m_bClearStatus = bCleanStatus;
		}
	}

}


void Light_Interface::fn_vOnModifCopy (CPA_List<EDT_SaveParents> *pListObjects, tdeTypeModif eType, tdeStatus eStatus)
{
	EDT_SaveParents		*pElem;
	POSITION			pos;

	if (eStatus!=C_AsConcernedDLL) return;

	fn_vRefreshHierarchyList ();


	// notify all elements in list
	for (pElem = pListObjects->GetHeadElement(pos); pElem; pElem = pListObjects->GetNextElement(pos))
	{
		// check type 
		if (pElem->m_pChild->GetObjectType() == HIE_C_ulEDT_Light)
		{
			Light* poLight = (Light*) pElem->m_pChild->GetObject();
			// to update selection
			poLight->fn_vUnSelect(FALSE);
			// update section
			if (eType==C_EDTDo)
			{
				poLight->fn_vNotifySave();
				fn_vRefreshLight (poLight);
			}
			else if (eType==C_EDTRedo)
			{
				poLight->fn_vNotifyRestore();
				fn_vRefreshLight (poLight);
			}
			else
			{
				poLight->fn_vNotifyUnSave();
				if (Light::fn_pGetDialog()->fn_pGetEditLight()== poLight) 
					Light::fn_pGetDialog()->fn_vEdit (NULL);
				poLight->fn_bUnValidate ();
				fn_vRefreshLight (poLight, TRUE);
			}
		}
	}
}

long Light_Interface::OnQueryAction	(CPA_EditorBase* poEditorBase, WPARAM wParam, LPARAM lParam)
{
	switch (wParam)
	{
		case C_uiQueryComputeRli:
			m_bModifyAll=TRUE;
			fn_vComputeRLI ();
			m_bNotifyIPO=TRUE;
			break;
	}


	return 0;
}



//---------------- Edition
void Light_Interface::fn_vEdit (Light* poLight, BOOL bSelectInList)
{
	if ( m_o_ModifRadiusLight!=poLight )
	{
		if (m_o_ModifRadiusLight) m_o_ModifRadiusLight->fn_vUnSelect (FALSE);
		if (fn_bIsCurrentEditor())
		{
				m_o_ModifRadiusLight = poLight;
				if (m_o_ModifRadiusLight) m_o_ModifRadiusLight->fn_vSelect ();
				GetInterface()->fn_vCancelCurrentSelection (FALSE);
				if (m_o_ModifRadiusLight) GetInterface()->fn_vAddSelectedObject (m_o_ModifRadiusLight->GetSuperObject(),FALSE);
		}
		GetInterface()->fn_vUpdateAll (E_mc_JustDraw);
	}
	//Light::fn_pGetDialog()->fn_vEdit (poLight);
	Light::fn_pGetDialog()->fn_vEdit ( poLight );
	if (bSelectInList) m_p_oDialogList->fn_vUpdateSelection (E_lrm_ChangeSelection);
//ROMTEAM SelectMode (Ionut Grozea 25/02/98)
	if(m_bSelectModeIsLight==1)
		GetInterface()->SetSelectMode("Light");
//ENDROMTEAM SelectMode (Ionut Grozea)
}


void Light_Interface::fn_vSetRLIDrawMask (BOOL bOnlyRLI )
{
	CPA_List<CPA_SuperObject>* poListOfSector = GetInterface()->GetObjectListByType	(C_szSectorTypeName);

	POSITION xSuperObjectPos;
	CPA_SuperObject* poSuperObject;

	for ( poSuperObject=poListOfSector->GetHeadElement(xSuperObjectPos); poSuperObject; poSuperObject=poListOfSector->GetNextElement(xSuperObjectPos) )


	{
		long lDrawMask =  HIE_fn_lGetSuperObjectDrawMask (poSuperObject->GetStruct());

		if (bOnlyRLI)
		{
			lDrawMask |= GLI_C_lIsUseStaticLights;
			lDrawMask |= GLI_C_lIsUseRLI;
		}
		else
		{
			lDrawMask &= ~GLI_C_lIsUseRLI;
			lDrawMask &= ~GLI_C_lIsUseStaticLights;
		}

		HIE_fn_vSetSuperObjectDrawMask(poSuperObject->GetStruct(),  lDrawMask);
	}
	GetInterface()->fn_vUpdateAll (E_mc_JustDraw);
}

//--------------------------------------------------------------------
// Dialogs preference
//--------------------------------------------------------------------
void Light_Interface::fn_vSaveDialogsPreferences (void)
{
	CString	csFileName;
	CString	csDimension;
	BOOL	bRes = TRUE;

	csFileName = M_GetMainApp()->m_csEditorDataPath + "Objects\\" + C_szLightIniFile;

	// left frame width
	csDimension.Format("%ld", m_p_oSplitFrameLight->m_oCurPos.right - m_p_oSplitFrameLight->m_oCurPos.left);
	bRes &= WritePrivateProfileString ("Preference", "Light Left Frame Width", (char*)(LPCSTR)csDimension, (char*)(LPCSTR)csFileName);
	// dialogs dimensions
	csDimension.Format("%ld", m_p_oSplitFrameLight->GetPaneSize(0));
	bRes &= WritePrivateProfileString ("Preference", "Light DialogList Dimension", (char*)(LPCSTR)csDimension, (char*)(LPCSTR)csFileName);
	csDimension.Format("%ld", m_p_oSplitFrameLight->GetPaneSize(1));
	bRes &= WritePrivateProfileString ("Preference", "Light Edit Dimension", (char*)(LPCSTR)csDimension, (char*)(LPCSTR)csFileName);

	// message
	if (!bRes)
		M_GetMainWnd()->UpdateStatus("Light Editor cannot save your preferences. Light.ini may have a ReadOnly status ?", C_STATUSPANE_INFOS, C_STATUS_WARNING);
	else
		M_GetMainWnd()->UpdateStatus("Preferences saved", C_STATUSPANE_INFOS, C_STATUS_NORMAL);
}




//--------------------------------------------------------------------
// RLI
//--------------------------------------------------------------------
void Light_Interface::fn_vComputeRLI (BOOL bSave)
{
    // for engine mode
	if (m_bRunEngine)
		return;
	
	fn_vSetDisplayFlag(edmDisplayModeUseRLI,1);
    fn_vSetDisplayFlag(edmDisplayModeUseStaticLight,0);
	RAY_vComputeAllSector (GetInterface()->GetSpecificInterface()->GetStaticRoot()->GetStruct());
	if(bSave) m_bSaveRLI=TRUE;

}


//----------------- Tools
// compute all the absolute matrix from World to given super-object
void Light_Interface::fn_vComputeAbsoluteMatrix (CPA_SuperObject* psoWP)
{
	CPA_List<CPA_SuperObject> ListObject;
	POSITION xPos;
	CPA_SuperObject* psObj;
	POS_tdstCompletePosition stIdentityMatrix;
	GEO_tdxHandleToMatrix  hFatherMatrix;

	POS_fn_vSetIdentityMatrix ( &stIdentityMatrix );
	hFatherMatrix = &stIdentityMatrix;
	ListObject.RemoveAll ();

	// list of the tree from object to world
	for ( psObj=psoWP; psObj; psObj=(CPA_SuperObject*)psObj->GetParent() )
		ListObject.AddTail ( psObj );

	// we go from world to object and compute all the absolute matrix
	for ( psObj=ListObject.GetTailElement(xPos); psObj; psObj=ListObject.GetPrevElement(xPos) )
	{
		if (psObj->GetStruct())
		{
			GEO_tdxHandleToMatrix hAbsoluteMatrix = HIE_fn_hGetSuperObjectGlobalMatrix (psObj->GetStruct());
			GEO_tdxHandleToMatrix hRelativeMatrix = HIE_fn_hGetSuperObjectMatrix (psObj->GetStruct());

			POS_fn_vMulMatrixMatrix
			(
				hAbsoluteMatrix,
				hFatherMatrix,
				hRelativeMatrix
			);
			hFatherMatrix = HIE_fn_hGetSuperObjectGlobalMatrix (psObj->GetStruct());
		}
	}

	// clean the list
	ListObject.RemoveAll ();
}

void Light_Interface::fn_vComputeNewRelativeMatrix(HIE_tdxHandleToSuperObject _hSprObj)
{
	GEO_tdxHandleToMatrix hMatrix;
	POS_tdstCompletePosition LocalMatrix;
	hMatrix=&LocalMatrix;

	POS_fn_vSetIdentityMatrix(hMatrix);
	POS_fn_vInvertMatrix(hMatrix, HIE_M_xGetSuperObjectMember(HIE_fn_hGetSuperObjectFather(_hSprObj),hGlobalMatrix));
	POS_fn_vMulMatrixMatrix(HIE_M_xGetSuperObjectMember(_hSprObj, hLocalMatrix), hMatrix, HIE_M_xGetSuperObjectMember(_hSprObj, hGlobalMatrix));
}

void Light_Interface::fn_vComputeInsertMatrix (CPA_SuperObject* poInsertSuperObject, CPA_SuperObject* poParentSuperObject )
{
	POS_tdstCompletePosition * pParentGlobalMatrix = HIE_fn_hGetSuperObjectGlobalMatrix (poParentSuperObject->GetStruct());
	POS_tdstCompletePosition * pInsertGlobalMatrix = HIE_fn_hGetSuperObjectGlobalMatrix (poInsertSuperObject->GetStruct());

	*pInsertGlobalMatrix = *pParentGlobalMatrix;
}


//--------------------------------------------------------------------
// Graphics Models
//--------------------------------------------------------------------
//CHINA WFQ (MT) 16/02/98 {
CPA_SuperObject* Light_Interface::fn_pGetNewBoxGraphicObject (void)
{
	CPA_SuperObject* poSuperObject =  GetInterface()->GetNewSuperObject ( E_ss_NoSave, C_Protected );
//	fn_vAllocSuperObjectMatrix (poSuperObject);
	Geometry3D* poBoxObject = new Geometry3D (GetInterface()->GetMainWorld()->GetObjectDLLWithName (C_szDLLGeometryName), 2, 1);

	MTH3D_tdstVector stPoint [] = {{ 0, 0., 0.},{ 1., 1., 1.}};

	poBoxObject->fn_vSetListOfPoints(2, stPoint);

	ACP_tdxHandleOfElement hElement = poBoxObject->fn_hCreateElementAlignedBox(1);
	poBoxObject->fn_eSetAlignedBox ( hElement, 0, 0, 1);
    poBoxObject->fn_vEndCreation();

	poSuperObject->SetObject (poBoxObject);

	HIE_fn_vSetSuperObjectDrawMask(poSuperObject->GetStruct(), C_lGouraudElement ^ (GLI_C_lIsNotDrawCollideInformationLight) );

	return poSuperObject;
}
//ENDCHINA WFQ }

CPA_SuperObject* Light_Interface::fn_pGetNewSpotGraphicObject (GLI_tdstLight_ *p_stLight)
{
 	CPA_SuperObject* poSuperObject =  GetInterface()->GetNewSuperObject ( E_ss_NoSave, C_Protected );
//ROMTEAM WorldEditor (Ionut 21/11/97)
	ITBox3D* poSpotObject = new ITBox3D( GetInterface()->GetMainWorld()->GetObjectDLLWithName (C_szDLLGeometryName) , 0.25f);
	if(!fn_bGetColorMode())
		fn_vInitGameMaterial ( poSpotObject, poSpotObject->GetHElement(), 1., 1., 1. );
	else
		if (p_stLight==NULL)
			fn_vInitGameMaterial ( poSpotObject, poSpotObject->GetHElement() , 1., 1., 0. );
		else
			if (GLI_ucGetObjectLighted(p_stLight)& GLI_C_LightPerso)
				fn_vInitGameMaterial ( poSpotObject, poSpotObject->GetHElement() , 1., 1., 0. );
			else
				fn_vInitGameMaterial ( poSpotObject, poSpotObject->GetHElement() , 0., 0., 1. );
//ENDROMTEAM WorldEditor (Ionut)

	HIE_fn_vSetSuperObjectDrawMask(poSuperObject->GetStruct(), C_lGouraudElement + GLI_C_lHasNotSinusEffect);
    poSpotObject->fn_vEndCreation();

    poSuperObject->SetObject (poSpotObject);
	return poSuperObject;

}


CPA_SuperObject* Light_Interface::fn_pGetNewAmbientGraphicObject (GLI_tdstLight_ *p_stLight)
{
 	CPA_SuperObject* poSuperObject =  GetInterface()->GetNewSuperObject ( E_ss_NoSave, C_Protected );
//ROMTEAM WorldEditor (Ionut 21/11/97)
	Oktaedron3D* poAmbientObject = new Oktaedron3D(TRUE , GetInterface()->GetMainWorld()->GetObjectDLLWithName (C_szDLLGeometryName), 13, 1 );
//ROMTEAM color lights Ionut Grozea 10-08-1998
	if(!fn_bGetColorMode())
		fn_vInitGameMaterial ( poAmbientObject,  poAmbientObject->GetEngineHandle (), 1., 1., 1. );
	else
		if (p_stLight==NULL)
			fn_vInitGameMaterial ( poAmbientObject,  poAmbientObject->GetEngineHandle () , 1., 1., 0. );
		else
			if (GLI_ucGetObjectLighted(p_stLight)& GLI_C_LightPerso)
				fn_vInitGameMaterial ( poAmbientObject,  poAmbientObject->GetEngineHandle () , 1., 1., 0. );
			else
				fn_vInitGameMaterial ( poAmbientObject,  poAmbientObject->GetEngineHandle () , 0., 0., 1. );
//ROMTEAM color lights Ionut Grozea 10-08-1998
//ENDROMTEAM WorldEditor (Ionut)
	HIE_fn_vSetSuperObjectDrawMask(poSuperObject->GetStruct(), C_lGouraudElement + GLI_C_lHasNotSinusEffect);
    poAmbientObject->fn_vEndCreation();
	poSuperObject->SetObject (poAmbientObject);
	return poSuperObject;

}

//CHINA WFQ (MT) 16/02/98 {
CPA_SuperObject* Light_Interface::fn_pGetNewParallelBoxGraphicObject (void)
{
	CPA_SuperObject* poSuperObject =  GetInterface()->GetNewSuperObject ( E_ss_NoSave, C_Protected );
//	fn_vAllocSuperObjectMatrix (poSuperObject);
	Geometry3D* poParallelBoxObject = new Geometry3D (GetInterface()->GetMainWorld()->GetObjectDLLWithName (C_szDLLGeometryName), 16, 1);

	MTH3D_tdstVector a16_stPoint [16];
	MTH3D_M_vSetVectorElements ( a16_stPoint, 0.05f, 0.05f, 0.4f);
	MTH3D_M_vSetVectorElements ( a16_stPoint+1, -0.05f,0.05f,0.4f);
	MTH3D_M_vSetVectorElements ( a16_stPoint+2, -0.05f,-0.05f,0.4f);
	MTH3D_M_vSetVectorElements ( a16_stPoint+3, 0.05f,-0.05f,0.4f);

	MTH3D_M_vSetVectorElements ( a16_stPoint+4, 0.05f,0.05f,0.2f);
	MTH3D_M_vSetVectorElements ( a16_stPoint+5, -0.05f,0.05f,0.2f);
	MTH3D_M_vSetVectorElements ( a16_stPoint+6, -0.05f,-0.05f,0.2f);
	MTH3D_M_vSetVectorElements ( a16_stPoint+7, 0.05f,-0.05f,0.2f);

	MTH3D_M_vSetVectorElements ( a16_stPoint+8, 0.075f,0.075f,0.2f);
	MTH3D_M_vSetVectorElements ( a16_stPoint+9, -0.075f,0.075f,0.2f);
	MTH3D_M_vSetVectorElements ( a16_stPoint+10, -0.075f,-0.075f,0.2f);
	MTH3D_M_vSetVectorElements ( a16_stPoint+11, 0.075f,-0.075f,0.2f);

	MTH3D_M_vSetVectorElements ( a16_stPoint+12, 0.075f,0.075f,0.0f);
	MTH3D_M_vSetVectorElements ( a16_stPoint+13, -0.075f,0.075f,0.0f);
	MTH3D_M_vSetVectorElements ( a16_stPoint+14, -0.075f,-0.075f,0.0f);
	MTH3D_M_vSetVectorElements ( a16_stPoint+15, 0.075f,-0.075f,0.0f);

	for ( int i=0; i<16; i++ )
	{
		MTH3D_M_vMulScalarVector(a16_stPoint+i,2.f,a16_stPoint+i);
	}

	poParallelBoxObject->fn_vSetListOfPoints(16, a16_stPoint);
	ACP_tdxHandleOfElement hElement = poParallelBoxObject->fn_hCreateElementIndexedTriangle(22,0);

    poParallelBoxObject->fn_eSetIndexedTriangle ( hElement, 0, 0, 1, 3 );
    poParallelBoxObject->fn_eSetIndexedTriangle ( hElement, 1, 1, 2, 3 );
    poParallelBoxObject->fn_eSetIndexedTriangle ( hElement, 2, 4, 5, 1 );
    poParallelBoxObject->fn_eSetIndexedTriangle ( hElement, 3, 1, 0, 4 );
    poParallelBoxObject->fn_eSetIndexedTriangle ( hElement, 4, 1, 5, 6 );
    poParallelBoxObject->fn_eSetIndexedTriangle ( hElement, 5, 1, 6, 2 );
    poParallelBoxObject->fn_eSetIndexedTriangle ( hElement, 6, 3 ,2, 6 );
    poParallelBoxObject->fn_eSetIndexedTriangle ( hElement, 7, 6, 7, 3 );
    poParallelBoxObject->fn_eSetIndexedTriangle ( hElement, 8, 0, 3, 7 );
    poParallelBoxObject->fn_eSetIndexedTriangle ( hElement, 9, 7, 4, 0 );

    poParallelBoxObject->fn_eSetIndexedTriangle ( hElement, 10,8, 9, 11 );
    poParallelBoxObject->fn_eSetIndexedTriangle ( hElement, 11,9, 10, 11 );
    poParallelBoxObject->fn_eSetIndexedTriangle ( hElement, 12,12, 13, 9 );
    poParallelBoxObject->fn_eSetIndexedTriangle ( hElement, 13,9, 8, 12);
    poParallelBoxObject->fn_eSetIndexedTriangle ( hElement, 14,9, 13, 14 );
    poParallelBoxObject->fn_eSetIndexedTriangle ( hElement, 15,9, 14, 10 );
    poParallelBoxObject->fn_eSetIndexedTriangle ( hElement, 16,11 ,10, 14 );
    poParallelBoxObject->fn_eSetIndexedTriangle ( hElement, 17,14, 15, 11);
    poParallelBoxObject->fn_eSetIndexedTriangle ( hElement, 18,8, 11,15);
    poParallelBoxObject->fn_eSetIndexedTriangle ( hElement, 19,15,12,8);
    poParallelBoxObject->fn_eSetIndexedTriangle ( hElement, 20,12,15,14);
	poParallelBoxObject->fn_eSetIndexedTriangle ( hElement, 21,14,13,12 );

//ROMTEAM color lights Ionut Grozea 10-08-1998
	if(!fn_bGetColorMode())
		fn_vInitGameMaterial ( poParallelBoxObject, hElement, 1., 1., 1. );
	else
		fn_vInitGameMaterial ( poParallelBoxObject, hElement, 1., 1., 0. );
//ROMTEAM color lights Ionut Grozea 10-08-1998

	HIE_fn_vSetSuperObjectDrawMask(poSuperObject->GetStruct(), C_lGouraudElement + GLI_C_lHasNotSinusEffect);

    poParallelBoxObject->fn_vEndCreation();

	poSuperObject->SetObject (poParallelBoxObject);

	return poSuperObject;
}
//ENDCHINA WFQ }

CPA_SuperObject* Light_Interface::fn_pGetNewSphericalGraphicObject (GLI_tdstLight_ *p_stLight)
{

 	CPA_SuperObject* poSuperObject =  GetInterface()->GetNewSuperObject ( E_ss_NoSave, C_Protected );
//ROMTEAM WorldEditor (Ionut 21/11/97)
	ITSphere3D* poSpotObject = new ITSphere3D ( GetInterface()->GetMainWorld()->GetObjectDLLWithName (C_szDLLGeometryName) , 0.25f,10/*radius*/);
//ROMTEAM color lights Ionut Grozea 10-08-1998
	if(!fn_bGetColorMode())
		fn_vInitGameMaterial ( poSpotObject, poSpotObject->GetHElement() , 1., 1., 1. );
	else
		if (p_stLight==NULL)
			fn_vInitGameMaterial ( poSpotObject, poSpotObject->GetHElement() , 1., 1., 0. );
		else
			if (GLI_ucGetObjectLighted(p_stLight)& GLI_C_LightPerso)
				fn_vInitGameMaterial ( poSpotObject, poSpotObject->GetHElement() , 1., 1., 0. );
			else
				fn_vInitGameMaterial ( poSpotObject, poSpotObject->GetHElement() , 0., 0., 1. );

//ROMTEAM color lights Ionut Grozea 10-08-1998
//ENDROMTEAM WorldEditor (Ionut)
	HIE_fn_vSetSuperObjectDrawMask(poSuperObject->GetStruct(), GLI_C_lAllIsEnable );
    poSpotObject->fn_vEndCreation();
    poSuperObject->SetObject (poSpotObject);
	return poSuperObject;
}
//ROMTEAM Z_Light Ionut Grozea 01-05-1998
CPA_SuperObject* Light_Interface::fn_pGetNewZGraphicObject	(void)
{
 	CPA_SuperObject* poSuperObject =  GetInterface()->GetNewSuperObject ( E_ss_NoSave, C_Protected );
 	DoubleArrow3D* poDoubleArrow3DObject = new DoubleArrow3D(TRUE , GetInterface()->GetMainWorld()->GetObjectDLLWithName (C_szDLLGeometryName));
//ROMTEAM color lights Ionut Grozea 10-08-1998
	if(!fn_bGetColorMode())
		fn_vInitGameMaterial ( poDoubleArrow3DObject, poDoubleArrow3DObject->GetEngineHandle (), 1., 1., 1. );
	else
		fn_vInitGameMaterial ( poDoubleArrow3DObject, poDoubleArrow3DObject->GetEngineHandle (), 1., 1., 0. );
//ROMTEAM color lights Ionut Grozea 10-08-1998
 	HIE_fn_vSetSuperObjectDrawMask(poSuperObject->GetStruct(), C_lGouraudElement + GLI_C_lHasNotSinusEffect);
    poDoubleArrow3DObject->fn_vEndCreation();
	poSuperObject->SetObject (poDoubleArrow3DObject);
	return poSuperObject;

}
//ENDROMTEAM Z_Light Ionut Grozea 01-05-1998
CPA_SuperObject* Light_Interface::fn_pGetNewFogGraphicObject (GLI_tdstLight_ *p_stLight)
{

 	CPA_SuperObject* poSuperObject =  GetInterface()->GetNewSuperObject ( E_ss_NoSave, C_Protected );
	ITSphere3D* poFogObject = new ITSphere3D ( GetInterface()->GetMainWorld()->GetObjectDLLWithName (C_szDLLGeometryName) , 0.25f,10/*radius*/);
	fn_vInitGameMaterial ( poFogObject, poFogObject->GetHElement() , 1., 1., 1. );
	if(!fn_bGetColorMode())
		fn_vInitGameMaterial ( poFogObject, poFogObject->GetHElement(), 1., 1., 1. );
	else
		if (p_stLight==NULL)
			fn_vInitGameMaterial ( poFogObject, poFogObject->GetHElement() , 1., 1., 0. );
		else
			if (GLI_ucGetObjectLighted(p_stLight)& GLI_C_LightPerso)
				fn_vInitGameMaterial ( poFogObject, poFogObject->GetHElement() , 1., 1., 0. );
			else
				fn_vInitGameMaterial ( poFogObject, poFogObject->GetHElement() , 0., 0., 1. );
	HIE_fn_vSetSuperObjectDrawMask(poSuperObject->GetStruct(), GLI_C_lAllIsEnable );
    poFogObject->fn_vEndCreation();
    poSuperObject->SetObject (poFogObject);
	return poSuperObject;
}



CPA_SuperObject* Light_Interface::fn_pGetNewConeGraphicObject (void)
{
	CPA_SuperObject* poSuperObject =  GetInterface()->GetNewSuperObject ( E_ss_NoSave, C_Protected );
	Geometry3D* poConeObject = new Geometry3D (GetInterface()->GetMainWorld()->GetObjectDLLWithName (C_szDLLGeometryName), 2, 1);
	MTH3D_tdstVector stPoint [] = {{ 5, 1., 1.},{ 0., 0., 0.}};

	poConeObject->fn_vSetListOfPoints(2, stPoint);

	ACP_tdxHandleOfElement hElement = poConeObject->fn_hCreateElementCone(1);
	poConeObject->fn_eSetCone( hElement, 0, 0, 1, 10.);
    poConeObject->fn_vEndCreation();

	poSuperObject->SetObject (poConeObject);

	HIE_fn_vSetSuperObjectDrawMask(poSuperObject->GetStruct(), C_lGouraudElement ^ (GLI_C_lIsNotDrawCollideInformationLight) );
	
	return poSuperObject;
}

CPA_SuperObject* Light_Interface::fn_pGetNewSphereGraphicObject (void)
{
	CPA_SuperObject* poSuperObject =  GetInterface()->GetNewSuperObject ( E_ss_NoSave, C_Protected );
	Geometry3D* poSphereObject = new Geometry3D (GetInterface()->GetMainWorld()->GetObjectDLLWithName (C_szDLLGeometryName), 1, 1 );

    MTH3D_tdstVector stPoint = { 0., 0., 0.};
	poSphereObject->fn_vSetListOfPoints(1, &stPoint);
	poSphereObject->fn_eSetIndexedSphere( poSphereObject->fn_hCreateElementSpheres(1), 0, 0, 0.01f);
    poSphereObject->fn_vEndCreation();

	poSuperObject->SetObject (poSphereObject);

	HIE_fn_vSetSuperObjectDrawMask(poSuperObject->GetStruct(), C_lGouraudElement ^ (GLI_C_lIsNotDrawCollideInformationLight) );
	
	return poSuperObject;
}

CPA_SuperObject* Light_Interface::fn_pGetNewParallelGraphicObject (GLI_tdstLight_ *p_stLight)
{
 	CPA_SuperObject* poSuperObject =  GetInterface()->GetNewSuperObject ( E_ss_NoSave, C_Protected );
//ROMTEAM WorldEditor (Ionut 21/11/97)
	Arrow3D* poParallelObject = new Arrow3D(TRUE , GetInterface()->GetMainWorld()->GetObjectDLLWithName (C_szDLLGeometryName));
//ROMTEAM color lights Ionut Grozea 10-08-1998
	if(!fn_bGetColorMode())
		fn_vInitGameMaterial ( poParallelObject, poParallelObject->GetEngineHandle (), 1., 1., 1. );
	else
		if (p_stLight==NULL)
			fn_vInitGameMaterial ( poParallelObject, poParallelObject->GetEngineHandle () , 1., 1., 0. );
		else
			if (GLI_ucGetObjectLighted(p_stLight)& GLI_C_LightPerso)
				fn_vInitGameMaterial ( poParallelObject, poParallelObject->GetEngineHandle () , 1., 1., 0. );
			else
				fn_vInitGameMaterial ( poParallelObject, poParallelObject->GetEngineHandle () , 0., 0., 1. );
//ROMTEAM color lights Ionut Grozea 10-08-1998
//ENDROMTEAM WorldEditor (Ionut)
	HIE_fn_vSetSuperObjectDrawMask(poSuperObject->GetStruct(), C_lGouraudElement + GLI_C_lHasNotSinusEffect);
    poParallelObject->fn_vEndCreation();
	poSuperObject->SetObject (poParallelObject);
	return poSuperObject;


}

CPA_SuperObject* Light_Interface::fn_pGetNewCursorGraphicObject (GLI_tdstLight_ *p_stLight)
{
	CPA_SuperObject* poSuperObject =  GetInterface()->GetNewSuperObject ( E_ss_NoSave, C_Protected );
    poSuperObject->SetTypeSO (C_Protected);
	Geometry3D* poCursorObject = new Geometry3D (GetInterface()->GetMainWorld()->GetObjectDLLWithName (C_szDLLGeometryName), 8, 1 );

	MTH3D_tdstVector a8_stPoint [8];

	for (int iCounter=0; iCounter<8; iCounter++)
		MTH3D_M_vSetVectorElements ( a8_stPoint+iCounter, 0.0, 0.0, 0.0 );

	poCursorObject->fn_vSetListOfPoints(8, a8_stPoint);

	ACP_tdxHandleOfElement hElement = poCursorObject->fn_hCreateElementIndexedTriangle(12,0);
    poCursorObject->fn_eSetIndexedTriangle ( hElement, 0, 0, 1, 3 );
    poCursorObject->fn_eSetIndexedTriangle ( hElement, 1, 1, 2, 3 );
    poCursorObject->fn_eSetIndexedTriangle ( hElement, 2, 4, 5, 1 );
    poCursorObject->fn_eSetIndexedTriangle ( hElement, 3, 1, 0, 4);
    poCursorObject->fn_eSetIndexedTriangle ( hElement, 4, 1, 5, 6 );
    poCursorObject->fn_eSetIndexedTriangle ( hElement, 5, 1, 6, 2 );
    poCursorObject->fn_eSetIndexedTriangle ( hElement, 6, 3, 2, 6 );
    poCursorObject->fn_eSetIndexedTriangle ( hElement, 7, 6, 7, 3 );
    poCursorObject->fn_eSetIndexedTriangle ( hElement, 8, 0, 3, 7 );
    poCursorObject->fn_eSetIndexedTriangle ( hElement, 9, 7, 4, 0 );
    poCursorObject->fn_eSetIndexedTriangle ( hElement, 10, 4, 7, 5 );
	poCursorObject->fn_eSetIndexedTriangle ( hElement, 11, 6, 5, 7 );

//ROMTEAM color lights Ionut Grozea 10-08-1998
	if(!fn_bGetColorMode())
		fn_vInitGameMaterial ( poCursorObject, hElement, 1., 1., 0. );
	else
		if (p_stLight==NULL)
			fn_vInitGameMaterial ( poCursorObject, hElement, 1., 1., 0. );
		else
			if (GLI_ucGetObjectLighted(p_stLight)& GLI_C_LightPerso)
				fn_vInitGameMaterial ( poCursorObject, hElement , 1., 1., 0. );
			else
				fn_vInitGameMaterial ( poCursorObject, hElement , 0., 0., 1. );
//ROMTEAM color lights Ionut Grozea 10-08-1998
    poCursorObject->fn_vEndCreation();

	HIE_fn_vSetSuperObjectDrawMask(poSuperObject->GetStruct(), C_lGouraudElement + GLI_C_lHasNotSinusEffect);

	poSuperObject->SetObject (poCursorObject);

	return poSuperObject;
}




//--------------------------------------------------------------------
// Tools
//--------------------------------------------------------------------
CPA_BaseObject* Light_Interface::fn_pSelectLightParam ( CPA_List<CPA_BaseObject> *pParams )
{
	POSITION xPos;
	CPA_BaseObject* p_oSuperObject=NULL;
	for
	(
		p_oSuperObject = pParams->GetHeadElement ( xPos );
		p_oSuperObject;
		p_oSuperObject = pParams->GetNextElement ( xPos )
	)
	if (((CPA_SuperObject*)p_oSuperObject)->GetObject()->GetDataType()==HIE_C_ulEDT_Light) return p_oSuperObject;

	// we don't find something interresting
	return NULL;
}

void Light_Interface::fn_vPick ( ACP_tdxIndex* pxNbPicked, HIE_aDEF_stTabOfPickInfo& ra_stPickInfo, tdstMousePos *p_stPos)
{
	*pxNbPicked = HIE_xIsSuperObjectPick
	(
		GLI_C_ModePickingFace,
		GetInterface()->GetMultiDevice()->GetFocusDevice()->GetViewPort()->m_hDisplayDevice,
		GetInterface()->GetMultiDevice()->GetFocusDevice()->GetViewPort()->m_hDisplayViewport,
		&(p_stPos->stPos2D),
		GetInterface()->GetMultiDevice3D()->GetEngineWorld(),
		ra_stPickInfo
	);
}


CPA_SuperObject* Light_Interface::fn_pExplorePicking (ACP_tdxIndex xIndex, HIE_tdstPickInfo *p_stObject, long lTypeObject, ACP_tdxIndex* pxFindIndex )
{
//ROMTEAM selection Ionut Grozea 14-08-1998
 	for (ACP_tdxIndex i=0; i<xIndex; i++)
	{
 		CPA_SuperObject* pChild = GetInterface()->GetEditorObject(p_stObject[i].hSprObject);
		while (pChild)
		{
			if (pChild && pChild->GetObjectType()==lTypeObject)
			{
				if (pxFindIndex) *pxFindIndex = i;
				return pChild;
			}
			pChild = (CPA_SuperObject*)pChild->GetParent();
		}
	}

	return NULL;
//ENDROMTEAM selection Ionut Grozea 14-08-1998
}


void Light_Interface::fn_vRefreshHierarchyList (void)
{
	m_p_oDialogList->fn_vUpdateSelection (E_lrm_ReinitList);
}

void Light_Interface::fn_vMakeLightArray ( long* lNbLight, GLI_tdxHandleToLight* d_hLight )
{
	POSITION xPos;
	CPA_SuperObject* poSuperObject;
	long lCounter=0;

	CPA_List<CPA_SuperObject> * p_oListOfLight = GetInterface()->GetObjectListByType(C_szLightTypeName);

	if (p_oListOfLight)
	{
		*lNbLight = p_oListOfLight->GetCount ();

		for
		(
			poSuperObject=p_oListOfLight->GetHeadElement (xPos), lCounter=0;
			poSuperObject;
			poSuperObject=p_oListOfLight->GetNextElement (xPos), lCounter++
		)
		d_hLight[lCounter]=  (GLI_tdxHandleToLight)(poSuperObject->GetObject()->GetData());
	}
	else
		*lNbLight=0;

}

void Light_Interface::fn_vRefreshLight (Light* poLight, BOOL bDelete, BOOL bDraw )
{
	// refresh the light in engine mode
	if (poLight)
	{
		fn_vRefreshGameLight (poLight, bDelete);
		poLight->fn_vSetModify (TRUE);
	}
	else fn_vRefreshGameLight ();

	if (bDraw) GetInterface()->fn_vUpdateAll (E_mc_JustDraw);
}

void Light_Interface::fn_vRefreshGameLight (void)
{
	//For each sector:
	CPA_List<CPA_SuperObject> * p_oListOfLight = GetInterface()->GetObjectListByType(C_szLightTypeName);
	if (!p_oListOfLight) return;

    CPA_List<CPA_SuperObject>* poList = GetInterface()->GetObjectListByType	(C_szSectorTypeName);

	POSITION xSuperObjectPos;
	CPA_SuperObject* poSuperObject;

	SECT_tdxHandleOfElementLstStaticLights d_DeleteArray [65535];

	for ( poSuperObject=poList->GetHeadElement(xSuperObjectPos); xSuperObjectPos; poSuperObject=poList->GetNextElement(xSuperObjectPos) )
	{
		HIE_tdxHandleToSuperObject hSector;

		hSector = (HIE_tdxHandleToSuperObject)(poSuperObject->GetStruct());

		// remove all the statics lights in the sector
		SECT_tdxHandleOfElementLstStaticLights hStaticLightsElement;
		long i;

		SECT_M_ForEachStaticLightsListInSector(hSector,hStaticLightsElement,i)
		{
			d_DeleteArray[i]=hStaticLightsElement;
		}
		//destructs nodes
		long lNode;
		for (lNode=0; lNode<i; lNode++)
			SECT_fn_vDestructStaticLightsListNode(d_DeleteArray[lNode]);
	}


	// Add other lights
	POSITION xLightPos;
	CPA_SuperObject* poSuperLight;
	for
	(
		poSuperLight=p_oListOfLight->GetHeadElement (xLightPos);
		xLightPos;
		poSuperLight=p_oListOfLight->GetNextElement (xLightPos)
	)
	{
		POSITION xSectPos;
		CPA_SuperObject* poSector;
		HIE_tdxHandleToSuperObject hSector;
		Light* poLight = (Light*)(poSuperLight->GetObject());

		for ( poSector=poLight->fn_pGetSectorList()->GetHeadElement(xSectPos); xSectPos; poSector=poLight->fn_pGetSectorList()->GetNextElement(xSectPos) )
		{
			hSector = (HIE_tdxHandleToSuperObject)(poSector->GetStruct());

			GLI_tdxHandleToLight hStaticLight;
			hStaticLight = (GLI_tdxHandleToLight)(poLight->GetStruct());
			SECT_tdxHandleOfElementLstStaticLights hStaticLightsElement = SECT_fn_hCreateElementLstStaticLights ();
			SECT_fn_vSetHandleOfLightsInStaticLightsList
			(
				hStaticLightsElement,
				hStaticLight
			);
			SECT_fn_vAddTailStaticLightsListNode(hSector,hStaticLightsElement);
		}
	}


	fn_vComputeRLI ();

	// update list by sector
	fn_vUpdateListsBySector();
}


void Light_Interface::fn_vRefreshGameLight (Light* poLight, BOOL bDelete, BOOL bSaveRLI)
{
	//For each sector:
	CPA_List<CPA_BaseObject> oList;
	CPA_List<CPA_SuperObject> * p_oListOfLight = GetInterface()->GetObjectListByType(C_szLightTypeName);
	if (!p_oListOfLight) return;

    CPA_List<CPA_SuperObject>* poList = GetInterface()->GetObjectListByType	(C_szSectorTypeName);

	if (poList->GetCount()==0) return;

	POSITION xSuperObjectPos;
	CPA_SuperObject* poSuperObject;

	for ( poSuperObject=poList->GetHeadElement(xSuperObjectPos); xSuperObjectPos; poSuperObject=poList->GetNextElement(xSuperObjectPos) )
	{
		HIE_tdxHandleToSuperObject hSector;
		hSector = (HIE_tdxHandleToSuperObject)(poSuperObject->GetStruct());

		// remove the static light in the sector
		SECT_tdxHandleOfElementLstStaticLights hStaticLightsElement;
		SECT_tdxHandleOfElementLstStaticLights hDeleteStaticLightsElement=NULL;
		long i;

		SECT_M_ForEachStaticLightsListInSector(hSector,hStaticLightsElement,i)
		{
			GLI_tdxHandleToLight hStaticLight = SECT_GetStaticLightsInList ( hStaticLightsElement );
			if (hStaticLight==poLight->GetStruct()) hDeleteStaticLightsElement=hStaticLightsElement;
		}

		if (hDeleteStaticLightsElement) SECT_fn_vDestructStaticLightsListNode (hDeleteStaticLightsElement);
	}

	POSITION xSectPos;
	CPA_SuperObject* poSector;
	HIE_tdxHandleToSuperObject hSector;


	if (!bDelete)
	{
		for ( poSector=poLight->fn_pGetSectorList()->GetHeadElement(xSectPos); xSectPos; poSector=poLight->fn_pGetSectorList()->GetNextElement(xSectPos) )
		{
			hSector = (HIE_tdxHandleToSuperObject)(poSector->GetStruct());

			GLI_tdxHandleToLight hStaticLight;
			hStaticLight = (GLI_tdxHandleToLight)(poLight->GetStruct());
			SECT_tdxHandleOfElementLstStaticLights hStaticLightsElement = SECT_fn_hCreateElementLstStaticLights ();
			SECT_fn_vSetHandleOfLightsInStaticLightsList
			(
				hStaticLightsElement,
				hStaticLight
			);
			SECT_fn_vAddTailStaticLightsListNode(hSector,hStaticLightsElement);
		}
	}

	fn_vComputeRLI (bSaveRLI);

	// update list by sector
	fn_vUpdateListsBySector();
}

// this function is call only when lights are switch On/Off in editor
void Light_Interface::fn_vSwitchOnLight ( Light* poLight, BOOL bOn )
{
	poLight->fn_vSetLightOn (bOn);
	poLight->fn_vNotifySave();
	if (Light::fn_pGetDialog()) Light::fn_pGetDialog()->fn_vInitOnOff();
	fn_vRefreshGameLight (poLight,!bOn,FALSE);
	GetInterface()->fn_vUpdateAll (E_mc_JustDraw);
}


void Light_Interface::fn_vSetCursor ( UINT i )
{
	HINSTANCE hOldInst = AfxGetResourceHandle();
	AfxSetResourceHandle( m_p_stDLLIdentity->hModule );

	// change cursor
	SetCursor (AfxGetApp()->LoadCursor (i));

	AfxSetResourceHandle( hOldInst );
}

void Light_Interface::fn_vExistSaveFile (void)
{
	CString csPath = fn_csGetSaveFileName ();
	FILE* pFile;

	pFile = fopen (csPath.GetBuffer(128), "r" );

	if ( pFile )
	{
		m_bExistSaveFile=TRUE;
		fclose (pFile);
	}
	else m_bExistSaveFile=FALSE;
}

void Light_Interface::fn_vInitGameMaterial ( Geometry3D* poGeomObject, ACP_tdxHandleOfElement hElement, float fR, float fG, float fB )
{
	GMT_tdxHandleToGameMaterial hGameMaterial = GMT_fn_hCreateGameMaterial();
	ACP_tdxHandleOfMaterial hMaterial;
	GLI_xCreateMaterial ( &hMaterial ) ;
	GMT_fn_vSetVisualMaterial (hGameMaterial, hMaterial);
	GEO_tdstColor stColor;
	stColor.xR = fR;
	stColor.xG = fG;
	stColor.xB = fB;
	stColor.xA = 1.f;
	GLI_xSetMaterialAmbientCoef ( hMaterial, &stColor );
	GLI_xSetMaterialType ( hMaterial, C_lGouraudElement );
    poGeomObject->fn_vSetEngineGameMaterial  (hElement, 0, hGameMaterial );
}

void Light_Interface::fn_vGiveProgressInfo(CString csMessage, signed char cPercentage, BOOL _bNoHighlight /*= TRUE*/)
{
	CString csTrueMessage;
	if ( cPercentage == -1 )
		csTrueMessage = csMessage;
	else if ( cPercentage == 100 )
		csTrueMessage.Format("%s >>> done", csMessage);
	else
		csTrueMessage.Format("%s >>> %i %% completed", csMessage, cPercentage);

	M_GetMainWnd()->UpdateStatus(
		(char *)LPCTSTR(csTrueMessage),
		C_STATUSPANE_INFOS,
		((cPercentage != 100) || _bNoHighlight) ? C_STATUS_NORMAL : C_STATUS_WARNING
	);
}

void Light_Interface::fn_vUpDateAllLight (void)
{
	CPA_SuperObject* poSuperObject;
	POSITION xPos;
	CPA_List<CPA_SuperObject> * p_oListOfLight = GetInterface()->GetObjectListByType(C_szLightTypeName);

	for (poSuperObject=p_oListOfLight->GetHeadElement(xPos); poSuperObject; poSuperObject=p_oListOfLight->GetNextElement(xPos) )
	{
		Light* poLight = (Light*)poSuperObject->GetObject();
		if (poLight->fn_bIs3DsMaxLight())
		{
			poLight->fn_vUpdateLight(FALSE,FALSE);
			poLight->fn_vSetModify (TRUE);
		}
	}

	// compute RLI
	fn_vComputeRLI ();

	// update screen
	GetInterface()->fn_vUpdateAll (E_mc_JustDraw);
}

BOOL Light_Interface::fn_bIs3DsMaxLight (void)
{
	CPA_SuperObject* poSuperObject;
	POSITION xPos;
	CPA_List<CPA_SuperObject> * p_oListOfLight = GetInterface()->GetObjectListByType(C_szLightTypeName);

	for (poSuperObject=p_oListOfLight->GetHeadElement(xPos); poSuperObject; poSuperObject=p_oListOfLight->GetNextElement(xPos) )
	{
		Light* poLight = (Light*)poSuperObject->GetObject();
		if (poLight->fn_bIs3DsMaxLight()) return TRUE;
	}
	return FALSE;
}

void Light_Interface::fn_vSaveRLIModifyIPO (void)
{
	// get list of editor sector
	CPA_List<CPA_SuperObject>* poList = GetInterface()->GetObjectListByType	(C_szSectorTypeName);

	// get light list
	CPA_BaseObjectList* poListOfLight = GetInterface()->GetMainWorld()->fn_p_oGetOriginalObjectList (C_szLightTypeName);
	CPA_BaseObject* poBaseObject;
	Position xLightPos;

	if (poList->IsEmpty()) return;

	// we modify all lights
	if (m_bModifyAll)
	{
		ISI_fn_vSaveISIFromIPOFromHierarchie (GetInterface()->GetSpecificInterface()->GetStaticRoot()->GetStruct());
		m_bModifyAll=FALSE;
	}
	else
	{
		// for each sector
		CPA_SuperObject* poSuperObject;
		POSITION xSectorPos;

		for ( poSuperObject=poList->GetHeadElement(xSectorPos); poSuperObject; poSuperObject=poList->GetNextElement(xSectorPos) )
		{
			BOOL bSaveRLI=FALSE;	// save RLI flag

			if (poListOfLight)
			{
				// sector is in modif list
				if (m_oModifSectorList.Find(poSuperObject)) bSaveRLI=TRUE;
				else
				{
					// for each light
					for ( poBaseObject=poListOfLight->GetHeadElement(xLightPos); poBaseObject && !bSaveRLI; poBaseObject=poListOfLight->GetNextElement(xLightPos) )
					{
						// The sector is affected by a modify light
						Light* poLight = (Light*) poBaseObject;

						if (poLight->fn_bIsModify())
							bSaveRLI = poLight->fn_bIsAffectedSector (poSuperObject);
					}
				}
			}

			// save RLI of sector now
			if(bSaveRLI) ISI_fn_vSaveISIFromIPOFromHierarchie (poSuperObject->GetStruct());
		}
	}

	// clear flags
	if (poListOfLight)
	for ( poBaseObject=poListOfLight->GetHeadElement(xLightPos); poBaseObject; poBaseObject=poListOfLight->GetNextElement(xLightPos) )
	{
		Light* poLight = (Light*) poBaseObject;
		poLight->fn_vSetModify (FALSE);
	}
	// empty modif sectior list
	m_oModifSectorList.RemoveAll ();
}

void Light_Interface::fn_vClearStatus (void)
{
	if (m_bClearStatus)
		M_GetMainWnd()->UpdateStatus( "", C_STATUSPANE_INFOS, C_STATUS_NORMAL );
	m_bClearStatus = FALSE;
}



//ROMTEAM RealLights (Ionut Grozea 05/03/98)

void Light_Interface::RefreshOnlyRealLights()
{
 
	m_ListDeleteLight.RemoveAll ();
	m_ListOfParentDeleteLight.RemoveAll ();

 
	CPA_BaseObjectList* poList = m_poLight->GetInterface()->GetMainWorld()->fn_p_oGetOriginalObjectList (C_szLightTypeName);
	Position xPos;
	CPA_BaseObject* poBaseObject;

	for (poBaseObject = poList->GetHeadElement(xPos); poBaseObject; poBaseObject = poList->GetNextElement(xPos) )
	{
		CPA_SuperObject* poSuperObjectParent = ((Light*)poBaseObject)->GetSuperObject();
		CPA_SuperObject* poSuperObject = (CPA_SuperObject*) poSuperObjectParent->GetHead ();

		if(!((Light*)poBaseObject) ->fn_bGetOnOff ())
		{
			m_ListDeleteLight.AddTail ( poSuperObject );
			m_ListOfParentDeleteLight.AddTail ( poSuperObjectParent );
			GetInterface()->fn_bDeleteObjectInHierarchy ( poSuperObject);
			m_p_oDialogList->GetListFromName( csLightList )->GetSortedList()->fn_bRemoveObject(poSuperObjectParent);
		}
	}
 	GetInterface()->fn_vUpdateAll (E_mc_JustDraw);
	fn_vRefreshHierarchyList ();
	fn_vRefreshGameLight ();
	m_p_oDialogList->SetCurrentType  ( csLightList );
}
//ENDROMTEAM RealLights (Ionut Grozea)

//ROMTEAM RealLights (Ionut Grozea 05/03/98)

void Light_Interface::fn_vRefreshAllLights()
{
	POSITION xPosLight, xPosParent;
	CPA_SuperObject* poSuperObject;
	CPA_SuperObject* poParent;

	for (
		  poSuperObject=m_ListDeleteLight.GetHeadElement(xPosLight),
		  poParent=m_ListOfParentDeleteLight.GetHeadElement(xPosParent);
		  poSuperObject;
		  poSuperObject=m_ListDeleteLight.GetNextElement(xPosLight) ,
		  poParent=m_ListOfParentDeleteLight.GetNextElement(xPosParent)
		)
		{
			GetInterface()->fn_bInsertObjectInHierarchy (poSuperObject, poParent , FALSE, FALSE, FALSE );
			m_p_oDialogList->GetListFromName( csLightList )->GetSortedList()->fn_bAddObject(poParent);			
		}


	m_ListDeleteLight.RemoveAll ();
	m_ListOfParentDeleteLight.RemoveAll ();


	if (m_ListDeleteLightBeforeEngine.GetCount()||m_bNotifyIPO) GetInterface()->fn_vUpdateAll (E_mc_JustDraw);

	m_p_oDialogList->SetCurrentType  ( csLightList );

}
//ENDROMTEAM RealLights (Ionut Grozea)

// Shaitan Scale {
CPA_SuperObject * Light_Interface::GetVisualSuperObject (CPA_SuperObject *pInstance)
{
	return pInstance->GetSuperObjectFirstChild();
}
//End Shaitan Scale }

//CPA2 Corneliu Babiuc 21-05-98
//*******************************************************************************/
//   Keyboard
BOOL Light_Interface::_OnKeyDown (UINT nChar, UINT nRepCnt, UINT nFlags)
{
	//get the first selected lights
	CPA_List<CPA_SuperObject>* poList = GetInterface()->GetSelectedObjects (this);

	if (!poList->GetCount()) m_poRClicLight=NULL;
	else m_poRClicLight = (Light*)(poList->GetHead()->GetObject());

	switch (m_poKeyboard->mfn_uwKeyToAction(nChar))
	{
		case KA_LIGHT_SWITCH:
			if (m_poRClicLight)
			{
				if (m_poRClicLight->fn_bIsLightOn())
				{
					_OnPopUpMenuCommand( c_light_Popup_RealTime_Off );
				}
				else
				{
					_OnPopUpMenuCommand( c_light_Popup_RealTime_On );
				}
			}
			return TRUE;
		case KA_REAL_TIME:
			if (m_poRClicLight)
			{
				if (m_poRClicLight->fn_bGetOnOff())
				{
					_OnPopUpMenuCommand( c_Light_Popup_Off );
				}
				else
				{
					_OnPopUpMenuCommand( c_Light_Popup_On );
				}
				return TRUE;
			}
			break;
	}

	if ((nFlags & VK_CONTROL) && (m_poKeyboard->mfn_uwKeyToAction(nChar) != KA_CONTROL))
		g_bKeyUsed = TRUE;

	return FALSE;
}

BOOL Light_Interface::_OnKeyUp (UINT nChar, UINT nRepCnt, UINT nFlags)
{
	if ((nFlags & VK_CONTROL) && (m_poKeyboard->mfn_uwKeyToAction(nChar) != KA_CONTROL))
		g_bKeyUsed = FALSE;

	return FALSE;
}
//END CPA2 Corneliu Babiuc 21-05-98

void Light_Interface::fn_vUpdateListsBySector (void)
{
	Light_ListBySector	*pList;
	POSITION			pos;

	for (pList = m_stListBySector.GetHeadElement(pos); pList; pList = m_stListBySector.GetNextElement(pos))
	{
		pList->fn_vUpdateList();
	}
}

//--------------------------------------------------------------------
//					LISTS
//--------------------------------------------------------------------
Light_ListBySector::Light_ListBySector (CPA_SuperObject *pSector)
{
	m_pSector = pSector;
	// init list of lights
	fn_vUpdateList();
}

Light_ListBySector::~Light_ListBySector (void)
{

}


void Light_ListBySector::fn_vUpdateList (void)
{
	HIE_tdxHandleToSuperObject hSector = (HIE_tdxHandleToSuperObject)(m_pSector->GetStruct());

	// get the static lights in the sector
	SECT_tdxHandleOfElementLstStaticLights hStaticLightsElement;
	SECT_tdxHandleOfElementLstStaticLights hDeleteStaticLightsElement=NULL;
	long i;

	// empty the list
	m_stList.DeleteAllElements();
	
	SECT_M_ForEachStaticLightsListInSector(hSector,hStaticLightsElement,i)
	{
		GLI_tdxHandleToLight hStaticLight = SECT_GetStaticLightsInList(hStaticLightsElement);
		CPA_BaseObject *p_oLight  = m_pSector->GetEditor()->GetInterface()->GetMainWorld()->fn_p_oFindObjectWithEngine (hStaticLight, C_szLightTypeName);
		if (p_oLight)
			m_stList.fn_bAddObject(((Light *)p_oLight)->GetSuperObject());
	}
}


