//
/*=========================================================================
File Name:		DIACOL.CPP
Purpose:		Implements functions handling the collisions characteristics
				of the material editor
				Implements Following Classes:

				- DiaCol
				- tdoCopyBufferCol
				- tdoDeleteEngineCollideModif
				- tdoCreateEngineCollideModif
				- tdoPasteCol
				- tdoColNameObject

Author:			Yann Le Tensorer
Date:			April/May,1997
==========================================================================*/

#include "stdafx.h"
#include "Acp_Base.h"
#include <string.h>
#define HieFriend
#include "incgam.h"
#include "dpt.h"
#include "gmt.h"
#include "scr.h"
#include "diacol.hpp"
#include "_interf.hpp"
#include "gmatobj.hpp"
#include "CopyPaste.hpp"
#include "MatList.hpp"
#include "x:\cpa\main\inc\_editid.h"
#include "TUT.h"

extern Material_Interface *gs_p_oMaterialInterface;

DiaCol	*g_oMaterialCol; /* pour les callbacks du chrgement */



/////////////////////////////////////////////////////////////////////////////
// DiaCol dialog


IMPLEMENT_DYNCREATE(DiaCol, CFormView)



//==================================================================================================
//==================================================================================================
DiaCol::DiaCol()
: CFormView(DiaCol::IDD)
{
	m_hHandleToCollideMaterial = GMT_C_InvalidCollideMaterial;
	m_p_oCopyBuffer = NULL;
	int i;
	m_bAutoDispatch = FALSE;
	m_p_oMaterialCombo = NULL;

	g_oMaterialCol = this;

	m_fn_vLoadNames();

	for ( i = 0; i < C_uc_NumberOfNames * 3; i ++ )
	{
		m_p_oMyNameObject[i].m_uc_bit = (unsigned char) (i % C_uc_NumberOfNames);
		if ( (i / C_uc_NumberOfNames) == 0 )
		{
			m_a_csNameZdm[i % C_uc_NumberOfNames]=m_p_oMyNameObject[i].GetName();
		
		}
		else if ( (i / C_uc_NumberOfNames) == 1 )
		{
			m_a_csNameZdr[i % C_uc_NumberOfNames]=m_p_oMyNameObject[i].GetName();
		
		}
		else if ( (i / C_uc_NumberOfNames) == 2 )
		{
			m_a_csNameZde[i % C_uc_NumberOfNames]=m_p_oMyNameObject[i].GetName();
		
		}
	}

	m_p_oMyNameObject[C_uc_NumberOfNames * 3].m_uc_bit=C_uc_NumberOfNames;
	m_p_oMyNameObject[C_uc_NumberOfNames * 3].SetDefaultUniqueName();


	//GMT_fn_vInvalidate(&m_hHandleToGameMaterial);

	//{{AFX_DATA_INIT(DiaCol)
	m_name1 = _T("");
	m_name11 = _T("");
	m_name10 = _T("");
	m_name12 = _T("");
	m_name13 = _T("");
	m_name14 = _T("");
	m_name15 = _T("");
	m_name16 = _T("");
	m_name2 = _T("");
	m_name3 = _T("");
	m_name4 = _T("");
	m_name5 = _T("");
	m_name6 = _T("");
	m_name7 = _T("");
	m_name8 = _T("");
	m_name9 = _T("");
	m_RadioTypeOfZone = -1;
	//}}AFX_DATA_INIT
}

//==================================================================================================
//==================================================================================================
DiaCol::~DiaCol()
{
	if ( m_p_oCopyBuffer )
		delete m_p_oCopyBuffer;
}

//==================================================================================================
//==================================================================================================
void DiaCol::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(DiaCol)
//ROMTEAM WorldEditor (Cristi Petrescu 11/12/97)
	DDX_Control(pDX, IDC_RADIO_ZDM, m_btnRadioTypeOfZone);
//ENDROMTEAM WorldEditor (Cristi Petrescu)
	DDX_Control(pDX, IDC_CHECK_LOCK_NAMES, m_CheckLockNames);
	DDX_Control(pDX, IDC_CHECK9, m_check9);
	DDX_Control(pDX, IDC_CHECK8, m_check8);
	DDX_Control(pDX, IDC_CHECK7, m_check7);
	DDX_Control(pDX, IDC_CHECK6, m_check6);
	DDX_Control(pDX, IDC_CHECK5, m_check5);
	DDX_Control(pDX, IDC_CHECK4, m_check4);
	DDX_Control(pDX, IDC_CHECK3, m_check3);
	DDX_Control(pDX, IDC_CHECK16, m_check16);
	DDX_Control(pDX, IDC_CHECK2, m_check2);
	DDX_Control(pDX, IDC_CHECK15, m_check15);
	DDX_Control(pDX, IDC_CHECK14, m_check14);
	DDX_Control(pDX, IDC_CHECK13, m_check13);
	DDX_Control(pDX, IDC_CHECK12, m_check12);
	DDX_Control(pDX, IDC_CHECK11, m_check11);
	DDX_Control(pDX, IDC_CHECK10, m_check10);
	DDX_Control(pDX, IDC_CHECK1, m_check1);
	DDX_Control(pDX, IDC_CHECK_DISABLE_COLLISIONS, m_CheckDisableCollisions);
	DDX_Text(pDX, IDC_EDIT_NAME1, m_name1);
	DDX_Text(pDX, IDC_EDIT_NAME11, m_name11);
	DDX_Text(pDX, IDC_EDIT_NAME10, m_name10);
	DDX_Text(pDX, IDC_EDIT_NAME12, m_name12);
	DDX_Text(pDX, IDC_EDIT_NAME13, m_name13);
	DDX_Text(pDX, IDC_EDIT_NAME14, m_name14);
	DDX_Text(pDX, IDC_EDIT_NAME15, m_name15);
	DDX_Text(pDX, IDC_EDIT_NAME16, m_name16);
	DDX_Text(pDX, IDC_EDIT_NAME2, m_name2);
	DDX_Text(pDX, IDC_EDIT_NAME3, m_name3);
	DDX_Text(pDX, IDC_EDIT_NAME4, m_name4);
	DDX_Text(pDX, IDC_EDIT_NAME5, m_name5);
	DDX_Text(pDX, IDC_EDIT_NAME6, m_name6);
	DDX_Text(pDX, IDC_EDIT_NAME7, m_name7);
	DDX_Text(pDX, IDC_EDIT_NAME8, m_name8);
	DDX_Text(pDX, IDC_EDIT_NAME9, m_name9);
	DDX_Radio(pDX, IDC_RADIO_ZDM, m_RadioTypeOfZone);
	//}}AFX_DATA_MAP


	//notify save only if the data is moved from the controls to the ministructure
	if ( pDX->m_bSaveAndValidate )
		m_vNotifyChangeToScripts();
}


//==================================================================================================
//==================================================================================================
BEGIN_MESSAGE_MAP(DiaCol, CFormView)
	//{{AFX_MSG_MAP(DiaCol)
	ON_BN_CLICKED(IDC_CHECK_DISABLE_COLLISIONS, OnCheckDisableCollisions)
	ON_BN_CLICKED(IDC_CHECK1, OnCheckButtons)
	ON_BN_CLICKED(IDC_RADIO_ZDE, OnRadioZoneTypes)
	ON_EN_KILLFOCUS(IDC_EDIT_NAME1, OnKillfocusEditName1)
	ON_EN_KILLFOCUS(IDC_EDIT_NAME10, OnKillfocusEditName10)
	ON_EN_KILLFOCUS(IDC_EDIT_NAME11, OnKillfocusEditName11)
	ON_EN_KILLFOCUS(IDC_EDIT_NAME12, OnKillfocusEditName12)
	ON_EN_KILLFOCUS(IDC_EDIT_NAME13, OnKillfocusEditName13)
	ON_EN_KILLFOCUS(IDC_EDIT_NAME14, OnKillfocusEditName14)
	ON_EN_KILLFOCUS(IDC_EDIT_NAME15, OnKillfocusEditName15)
	ON_EN_KILLFOCUS(IDC_EDIT_NAME16, OnKillfocusEditName16)
	ON_EN_KILLFOCUS(IDC_EDIT_NAME2, OnKillfocusEditName2)
	ON_EN_KILLFOCUS(IDC_EDIT_NAME3, OnKillfocusEditName3)
	ON_EN_KILLFOCUS(IDC_EDIT_NAME4, OnKillfocusEditName4)
	ON_EN_KILLFOCUS(IDC_EDIT_NAME5, OnKillfocusEditName5)
	ON_EN_KILLFOCUS(IDC_EDIT_NAME6, OnKillfocusEditName6)
	ON_EN_KILLFOCUS(IDC_EDIT_NAME7, OnKillfocusEditName7)
	ON_EN_KILLFOCUS(IDC_EDIT_NAME8, OnKillfocusEditName8)
	ON_EN_KILLFOCUS(IDC_EDIT_NAME9, OnKillfocusEditName9)
	ON_BN_CLICKED(IDC_CHECK_LOCK_NAMES, OnCheckLockNames)
	ON_BN_CLICKED(IDC_BUTTON_SAVE_NAMES, OnButtonSaveNames)
	ON_BN_CLICKED(IDC_BUTTON_COPYCOL, OnButtonCopyCollideMaterial)
	ON_BN_CLICKED(IDC_BUTTON_RENAMECOL, OnButtonRenameCollideMaterial)
	ON_BN_CLICKED(IDC_BUTTON_PASTECOL, OnButtonPasteCollideMaterial)
	ON_EN_SETFOCUS(IDC_EDIT_NAME1, OnSetfocusEditName1)
	ON_EN_SETFOCUS(IDC_EDIT_NAME10, OnSetfocusEditName10)
	ON_EN_SETFOCUS(IDC_EDIT_NAME11, OnSetfocusEditName11)
	ON_EN_SETFOCUS(IDC_EDIT_NAME12, OnSetfocusEditName12)
	ON_EN_SETFOCUS(IDC_EDIT_NAME13, OnSetfocusEditName13)
	ON_EN_SETFOCUS(IDC_EDIT_NAME14, OnSetfocusEditName14)
	ON_EN_SETFOCUS(IDC_EDIT_NAME15, OnSetfocusEditName15)
	ON_EN_SETFOCUS(IDC_EDIT_NAME16, OnSetfocusEditName16)
	ON_EN_SETFOCUS(IDC_EDIT_NAME2, OnSetfocusEditName2)
	ON_EN_SETFOCUS(IDC_EDIT_NAME3, OnSetfocusEditName3)
	ON_EN_SETFOCUS(IDC_EDIT_NAME4, OnSetfocusEditName4)
	ON_EN_SETFOCUS(IDC_EDIT_NAME5, OnSetfocusEditName5)
	ON_EN_SETFOCUS(IDC_EDIT_NAME6, OnSetfocusEditName6)
	ON_EN_SETFOCUS(IDC_EDIT_NAME7, OnSetfocusEditName7)
	ON_EN_SETFOCUS(IDC_EDIT_NAME8, OnSetfocusEditName8)
	ON_EN_SETFOCUS(IDC_EDIT_NAME9, OnSetfocusEditName9)
	ON_CBN_EDITCHANGE(IDC_COMBO_COLMATNAME, OnComboEditChange)
	ON_CBN_SELCHANGE(IDC_COMBO_COLMATNAME, OnComboSelChange)
	ON_BN_CLICKED(IDC_BUTTON_HIGHLIGHTCOLOR, OnButtonHighlightColor)
	ON_BN_CLICKED(IDC_CHECK_HIGHLIGHT, OnCheckHighlight)
	ON_BN_CLICKED(IDC_CHECK2, OnCheckButtons)
	ON_BN_CLICKED(IDC_CHECK3, OnCheckButtons)
	ON_BN_CLICKED(IDC_CHECK4, OnCheckButtons)
	ON_BN_CLICKED(IDC_CHECK5, OnCheckButtons)
	ON_BN_CLICKED(IDC_CHECK6, OnCheckButtons)
	ON_BN_CLICKED(IDC_CHECK7, OnCheckButtons)
	ON_BN_CLICKED(IDC_CHECK8, OnCheckButtons)
	ON_BN_CLICKED(IDC_CHECK9, OnCheckButtons)
	ON_BN_CLICKED(IDC_CHECK10, OnCheckButtons)
	ON_BN_CLICKED(IDC_CHECK11, OnCheckButtons)
	ON_BN_CLICKED(IDC_CHECK12, OnCheckButtons)
	ON_BN_CLICKED(IDC_CHECK13, OnCheckButtons)
	ON_BN_CLICKED(IDC_CHECK14, OnCheckButtons)
	ON_BN_CLICKED(IDC_CHECK15, OnCheckButtons)
	ON_BN_CLICKED(IDC_CHECK16, OnCheckButtons)
	ON_BN_CLICKED(IDC_RADIO_ZDM, OnRadioZoneTypes)
	ON_BN_CLICKED(IDC_RADIO_ZDR, OnRadioZoneTypes)
	ON_WM_DRAWITEM()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

//==================================================================================================
//==================================================================================================
int DiaCol::OnToolHitTest(CPoint point, TOOLINFO *pTI) const
{
	CString csMessage;
	switch ( CWnd::OnToolHitTest(point, pTI) )
	{
	case IDC_COMBO_COLMATNAME:
		csMessage = "Select the current collision characteristics for the edited game material / edit its name";
		break;

	case IDC_CHECK_DISABLE_COLLISIONS:
		csMessage = "enable/disable collision characteristics for the current game material";
		break;

	case IDC_BUTTON_COPYCOL:
		csMessage = "copy the collision characteristics of the current game material for further pasting or instanciation";
		break;

	case IDC_BUTTON_PASTECOL:
		csMessage = "paste the contents of the last copied collision characteristics into the current game material";
		break;

	case IDC_BUTTON_RENAMECOL:
		csMessage = "accept the new name typed in the edit for the current collision characteristics";
		break;

	case IDC_RADIO_ZDM:
	case IDC_RADIO_ZDE:
	case IDC_RADIO_ZDR:
		csMessage = "select the type of zones";
		break;
		
	case IDC_EDIT_NAME1:
	case IDC_EDIT_NAME2:
	case IDC_EDIT_NAME3:
	case IDC_EDIT_NAME4:
	case IDC_EDIT_NAME5:
	case IDC_EDIT_NAME6:
	case IDC_EDIT_NAME7:
	case IDC_EDIT_NAME8:
	case IDC_EDIT_NAME9:
	case IDC_EDIT_NAME10:
	case IDC_EDIT_NAME11:
	case IDC_EDIT_NAME12:
	case IDC_EDIT_NAME13:
	case IDC_EDIT_NAME14:
	case IDC_EDIT_NAME15:
	case IDC_EDIT_NAME16:
		csMessage = "modify the name of the zone";
		break;

	case IDC_CHECK1:
	case IDC_CHECK2:
	case IDC_CHECK3:
	case IDC_CHECK4:
	case IDC_CHECK5:
	case IDC_CHECK6:
	case IDC_CHECK7:
	case IDC_CHECK8:
	case IDC_CHECK9:
	case IDC_CHECK10:
	case IDC_CHECK11:
	case IDC_CHECK12:
	case IDC_CHECK13:
	case IDC_CHECK14:
	case IDC_CHECK15:
	case IDC_CHECK16:
		csMessage = "make the collision characteristics select this zone";
		break;

	case IDC_CHECK_LOCK_NAMES:
		csMessage = "enable/disable modification of the zone names";
		break;

	case IDC_BUTTON_SAVE_NAMES:
		csMessage = "save names to file";
		break;
	}
	//output the help info in the status bar
	fn_vGiveProgressInfo(csMessage, -1);

	//there is no hit for a true tooltip
	return -1;
}

/*=====================================================================================
Function:	m_vNotifyChangeToScripts()
Purpose:	Notify changes to script
Author:		Benoit Germain
Date:		May 5, 1997
====================================================================================*/
void DiaCol::m_vNotifyChangeToScripts()
{
	if ( m_hHandleToCollideMaterial != GMT_C_InvalidCollideMaterial )
		gs_p_oMaterialInterface->m_p_oGetEditorObjectForEngine(m_hHandleToCollideMaterial)
		->fn_vNotifySave();
}
 

/*=====================================================================================
====================================================================================*/
void DiaCol::fn_vInitDialog ( void )
{
	UpdateData(FALSE);
}

//==================================================================================================
//==================================================================================================
void DiaCol::m_fn_vSetToMotor()
{
	if ( m_hHandleToCollideMaterial != GMT_C_InvalidCollideMaterial )
	{
		GMT_fn_vSetTypeOfCollideMaterial(m_hHandleToCollideMaterial, m_uwTypeOfZone);
		GMT_fn_hSetCollideMaterialIdentifier(m_hHandleToCollideMaterial, m_uwIdentifier);
	}
}

/*=========================================================================
Function Name:  DiaCol::m_fn_vSetMaterial
Purpose:		Sets the collision paramaters of the current material according
				to those edited in the dialog box
Author:			Yann Le Tensorer
Date:			23-04-97

==========================================================================*/
void DiaCol::m_fn_vSetMaterial()
{
	// met les valeurs des check boxes du dialog dans les variables internes
	UpdateData(TRUE);
	// met les variables m_wTypeOfZone, m_wIdentifier a jour en fonction des variables internes des check boxes
	m_fn_vGetCheckBoxesValues(&m_uwTypeOfZone,&m_uwIdentifier);
	// met a jour les noms des identifiants en fonction de m_wTypeOfZone
	m_fn_vUpdateNames();
	// met a jour les variables de la MS moteur
	m_fn_vSetToMotor();
	
}

/*=========================================================================
Function Name:  DiaCol::m_fn_vShowMaterial
Purpose:		Show the collision paramaters of the current material
Author:			Yann Le Tensorer
Date:			23-04-97

This function is called each time a material is selected.
==========================================================================*/
void DiaCol::m_fn_vShowMaterial(GMT_tdxHandleToGameMaterial _hMat)
{
//ANNECY Shaitan DisableFunctions (16/04/98) {
	char *szOwnerName;
	char *szFileName;
//ENDANNECY Shaitan DisableFunctions }
	
	tdoEditorGameMaterial *p_oEditedGameMaterial = gs_p_oMaterialInterface->m_p_oGetEditedMaterial();
	BOOL bAGameMaterialIsEdited = p_oEditedGameMaterial ? TRUE : FALSE;

//ANNECY Shaitan DisableFunctions (16/04/98) {
	if (bAGameMaterialIsEdited)
	{
		szOwnerName = (char *) (LPCSTR) p_oEditedGameMaterial->GetOwner()->GetName();
		szFileName = strchr(szOwnerName, '\\') + 1;
		m_bCommonFile = (!stricmp(szFileName, C_szCommon)); 
	}

	GetDlgItem(IDC_CHECK_DISABLE_COLLISIONS)->EnableWindow(g_bMasterEditor && bAGameMaterialIsEdited);
//ENDANNECY Shaitan DisableFunctions }

	/* if no material is currently selected, disable everything */
	if ( !bAGameMaterialIsEdited || !GMT_fn_b_ulIsValid(_hMat) )
	{
		m_hHandleToCollideMaterial = GMT_C_InvalidCollideMaterial;
		// make display an invalid series of names...
		m_uwTypeOfZone = (unsigned short) -1;
		m_fn_vShowNames();
		//clear the name, and disable choosing if no game material is edited
//ANNECY Shaitan DisableFunctions (16/04/98) {
		m_p_oMaterialCombo->EnableWindow(bAGameMaterialIsEdited && (!m_bCommonFile || g_bMasterEditor));
//ENDANNECY Shaitan DisableFunctions }
		m_p_oMaterialCombo->SetCurSel(bAGameMaterialIsEdited ? 0 : CB_ERR);
		//and disable all controls
		m_CheckDisableCollisions.SetCheck(FALSE);
		m_fn_vEnableWindowFields(FALSE);
		return;
	}	

	//locks the name edition
	m_CheckLockNames.SetCheck(TRUE);
	OnCheckLockNames();

	//normally, the specified engine game material must belong to the current editor game material...
	ASSERT(_hMat == p_oEditedGameMaterial->GetData());
	//  gets the handle to collision mat
	m_hHandleToCollideMaterial = GMT_fn_hGetCollideMaterial(_hMat);

//ANNECY Shaitan DisableFunctions (16/04/98) {
	m_p_oMaterialCombo->EnableWindow(/*TRUE*/!m_bCommonFile || g_bMasterEditor); //enable the selection of another submaterial
//ENDANNECY Shaitan DisableFunctions }

	if ( m_hHandleToCollideMaterial == GMT_C_InvalidCollideMaterial )
	{
		// make display an invalid series of names...
		m_uwTypeOfZone = (unsigned short) -1;
		m_fn_vShowNames();
		//clear the name
		m_p_oMaterialCombo->SetCurSel(0);
		//and disable all controls
		m_CheckDisableCollisions.SetCheck(FALSE);
		m_fn_vEnableWindowFields(FALSE);
	}
	else
	{
		tdoEditorCollideMaterial *p_oMaterial = (tdoEditorCollideMaterial *) gs_p_oMaterialInterface->m_p_oGetEditorObjectForEngine(m_hHandleToCollideMaterial);

		m_uwTypeOfZone = GMT_fn_wGetTypeOfCollideMaterial(m_hHandleToCollideMaterial);
		m_uwIdentifier = GMT_fn_hGetCollideMaterialIdentifier(m_hHandleToCollideMaterial);
		
		// met les variables internes à la classe correspondant aux check boxes à leur bonne valeur.
		m_fn_vSetCheckBoxesValues();

		// affiche les bons noms en fonction
		m_fn_vShowNames();
		UpdateData(FALSE);

		//display the editor material's name
		m_p_oMaterialCombo->SetCurSel(m_p_oMaterialCombo->FindStringExact(
			-1, p_oMaterial->GetName()
		));
		// MS mechanics existe
		m_CheckDisableCollisions.SetCheck(TRUE);
		m_fn_vEnableWindowFields(TRUE);
		((CButton *) GetDlgItem(IDC_CHECK_HIGHLIGHT))->SetCheck(p_oMaterial->m_bGetHighlightColor());
	}
	((CButton *) GetDlgItem(IDC_BUTTON_HIGHLIGHTCOLOR))->Invalidate();
}

/*=========================================================================
Function Name:  DiaCol::m_fn_vUpdateNames
Purpose:		Save the names of the dialog into memory
Author:			Yann Le Tensorer
Date:			24-04-97
==========================================================================*/
void DiaCol::m_fn_vUpdateNames()
{
	switch (m_uwTypeOfZone)
	{
	case GMT_C_wZDM:
		m_a_csNameZdm[0]  = m_name1;	m_a_csNameZdm[1]  = m_name2;
		m_a_csNameZdm[2]  = m_name3;	m_a_csNameZdm[3]  = m_name4;
		m_a_csNameZdm[4]  = m_name5;	m_a_csNameZdm[5]  = m_name6;
		m_a_csNameZdm[6]  = m_name7;	m_a_csNameZdm[7]  = m_name8;
		m_a_csNameZdm[8]  = m_name9;	m_a_csNameZdm[9]  = m_name10;
		m_a_csNameZdm[10] = m_name11;	m_a_csNameZdm[11] = m_name12;
		m_a_csNameZdm[12] = m_name13;	m_a_csNameZdm[13] = m_name14;
		m_a_csNameZdm[14] = m_name15;	m_a_csNameZdm[15] = m_name16;
		break;

	case GMT_C_wZDR:
		m_a_csNameZdr[0]  = m_name1;	m_a_csNameZdr[1]  = m_name2;
		m_a_csNameZdr[2]  = m_name3;	m_a_csNameZdr[3]  = m_name4;
		m_a_csNameZdr[4]  = m_name5;	m_a_csNameZdr[5]  = m_name6;
		m_a_csNameZdr[6]  = m_name7;	m_a_csNameZdr[7]  = m_name8;
		m_a_csNameZdr[8]  = m_name9;	m_a_csNameZdr[9]  =m_name10;
		m_a_csNameZdr[10] = m_name11;	m_a_csNameZdr[11] = m_name12;
		m_a_csNameZdr[12] = m_name13;	m_a_csNameZdr[13] = m_name14;
		m_a_csNameZdr[14] = m_name15;	m_a_csNameZdr[15] = m_name16;
		break;

	case GMT_C_wZDE:
		m_a_csNameZde[0]  = m_name1;	m_a_csNameZde[1]  = m_name2;
		m_a_csNameZde[2]  = m_name3;	m_a_csNameZde[3]  = m_name4;
		m_a_csNameZde[4]  = m_name5;	m_a_csNameZde[5]  = m_name6;
		m_a_csNameZde[6]  = m_name7;	m_a_csNameZde[7]  = m_name8;
		m_a_csNameZde[8]  = m_name9;	m_a_csNameZde[9]  = m_name10;
		m_a_csNameZde[10] = m_name11;	m_a_csNameZde[11] = m_name12;
		m_a_csNameZde[12] = m_name13;	m_a_csNameZde[13] = m_name14;
		m_a_csNameZde[14] = m_name15;	m_a_csNameZde[15] = m_name16;
		break;

	default:
		m_a_csNameZde[0]  = "N/A";	m_a_csNameZde[1]  = "N/A";
		m_a_csNameZde[2]  = "N/A";	m_a_csNameZde[3]  = "N/A";
		m_a_csNameZde[4]  = "N/A";	m_a_csNameZde[5]  = "N/A";
		m_a_csNameZde[6]  = "N/A";	m_a_csNameZde[7]  = "N/A";
		m_a_csNameZde[8]  = "N/A";	m_a_csNameZde[9]  = "N/A";
		m_a_csNameZde[10] = "N/A";	m_a_csNameZde[11] = "N/A";
		m_a_csNameZde[12] = "N/A";	m_a_csNameZde[13] = "N/A";
		m_a_csNameZde[14] = "N/A";	m_a_csNameZde[15] = "N/A";
		break;
	}
}

/*=========================================================================
Function Name:  DiaCol::m_fn_vShowNames
Purpose:		Shows the names in the dialog according to the type of zone
Author:			Yann Le Tensorer
Date:			24-04-97
==========================================================================*/
void DiaCol::m_fn_vShowNames()
{
	switch (m_uwTypeOfZone)
	{
	case GMT_C_wZDM:
		m_name1  = m_a_csNameZdm[0];	m_name2  = m_a_csNameZdm[1];
		m_name3  = m_a_csNameZdm[2];	m_name4  = m_a_csNameZdm[3];
		m_name5  = m_a_csNameZdm[4];	m_name6  = m_a_csNameZdm[5];
		m_name7  = m_a_csNameZdm[6];	m_name8  = m_a_csNameZdm[7];
		m_name9  = m_a_csNameZdm[8];	m_name10 = m_a_csNameZdm[9];
		m_name11 = m_a_csNameZdm[10];	m_name12 = m_a_csNameZdm[11];
		m_name13 = m_a_csNameZdm[12];	m_name14 = m_a_csNameZdm[13];
		m_name15 = m_a_csNameZdm[14];	m_name16 = m_a_csNameZdm[15];
		break;

	case GMT_C_wZDR:
		m_name1  = m_a_csNameZdr[0];	m_name2  = m_a_csNameZdr[1];
		m_name3  = m_a_csNameZdr[2];	m_name4  = m_a_csNameZdr[3];
		m_name5  = m_a_csNameZdr[4];	m_name6  = m_a_csNameZdr[5];
		m_name7  = m_a_csNameZdr[6];	m_name8  = m_a_csNameZdr[7];
		m_name9  = m_a_csNameZdr[8];	m_name10 = m_a_csNameZdr[9];
		m_name11 = m_a_csNameZdr[10];	m_name12 = m_a_csNameZdr[11];
		m_name13 = m_a_csNameZdr[12];	m_name14 = m_a_csNameZdr[13];
		m_name15 = m_a_csNameZdr[14];	m_name16 = m_a_csNameZdr[15];
		break;

	case GMT_C_wZDE:
		m_name1  = m_a_csNameZde[0];	m_name2  = m_a_csNameZde[1];
		m_name3  = m_a_csNameZde[2];	m_name4  = m_a_csNameZde[3];
		m_name5  = m_a_csNameZde[4];	m_name6  = m_a_csNameZde[5];
		m_name7  = m_a_csNameZde[6];	m_name8  = m_a_csNameZde[7];
		m_name9  = m_a_csNameZde[8];	m_name10 = m_a_csNameZde[9];
		m_name11 = m_a_csNameZde[10];	m_name12 = m_a_csNameZde[11];
		m_name13 = m_a_csNameZde[12];	m_name14 = m_a_csNameZde[13];
		m_name15 = m_a_csNameZde[14];	m_name16 = m_a_csNameZde[15];
		break;

	default:
		m_name1  = "N/A";	m_name2  = "N/A";
		m_name3  = "N/A";	m_name4  = "N/A";
		m_name5  = "N/A";	m_name6  = "N/A";
		m_name7  = "N/A";	m_name8  = "N/A";
		m_name9  = "N/A";	m_name10 = "N/A";
		m_name11 = "N/A";	m_name12 = "N/A";
		m_name13 = "N/A";	m_name14 = "N/A";
		m_name15 = "N/A";	m_name16 = "N/A";
		break;
	}
	m_oldname1  = m_name1;	m_oldname2  = m_name2;
	m_oldname3  = m_name3;	m_oldname4  = m_name4;
	m_oldname5  = m_name5;	m_oldname6  = m_name6;
	m_oldname7  = m_name7;	m_oldname8  = m_name8;
	m_oldname9  = m_name9;	m_oldname10 = m_name10;
	m_oldname11 = m_name11;	m_oldname12 = m_name12;
	m_oldname13 = m_name13;	m_oldname14 = m_name14;
	m_oldname15 = m_name15;	m_oldname16 = m_name16;

	UpdateData(FALSE);
}


/*=========================================================================
Function Name:  DiaCol::m_fn_vEnableEditNames(true/false)
Purpose:		Called to enable or disable edit names fields
Parameters:		True: enable them, false: disable them

Author:			Yann Le Tensorer
Date:			24-04-97

==========================================================================*/
void DiaCol::m_fn_vEnableEditNames(BOOL bEnable)
{
	BOOL bReadOnly=!bEnable;

//ANNECY Shaitan DisableFunctions (16/04/98) {
	((CEdit*)GetDlgItem(IDC_EDIT_NAME1))->EnableWindow(g_bMasterEditor && bEnable);
	((CEdit*)GetDlgItem(IDC_EDIT_NAME2))->EnableWindow(g_bMasterEditor && bEnable);
	((CEdit*)GetDlgItem(IDC_EDIT_NAME3))->EnableWindow(g_bMasterEditor && bEnable);
	((CEdit*)GetDlgItem(IDC_EDIT_NAME4))->EnableWindow(g_bMasterEditor && bEnable);
	((CEdit*)GetDlgItem(IDC_EDIT_NAME5))->EnableWindow(g_bMasterEditor && bEnable);
	((CEdit*)GetDlgItem(IDC_EDIT_NAME6))->EnableWindow(g_bMasterEditor && bEnable);
	((CEdit*)GetDlgItem(IDC_EDIT_NAME7))->EnableWindow(g_bMasterEditor && bEnable);
	((CEdit*)GetDlgItem(IDC_EDIT_NAME8))->EnableWindow(g_bMasterEditor && bEnable);
	((CEdit*)GetDlgItem(IDC_EDIT_NAME9))->EnableWindow(g_bMasterEditor && bEnable);
	((CEdit*)GetDlgItem(IDC_EDIT_NAME10))->EnableWindow(g_bMasterEditor && bEnable);
	((CEdit*)GetDlgItem(IDC_EDIT_NAME11))->EnableWindow(g_bMasterEditor && bEnable);
	((CEdit*)GetDlgItem(IDC_EDIT_NAME12))->EnableWindow(g_bMasterEditor && bEnable);
	((CEdit*)GetDlgItem(IDC_EDIT_NAME13))->EnableWindow(g_bMasterEditor && bEnable);
	((CEdit*)GetDlgItem(IDC_EDIT_NAME14))->EnableWindow(g_bMasterEditor && bEnable);
	((CEdit*)GetDlgItem(IDC_EDIT_NAME15))->EnableWindow(g_bMasterEditor && bEnable);
	((CEdit*)GetDlgItem(IDC_EDIT_NAME16))->EnableWindow(g_bMasterEditor && bEnable);
//ENDANNECY Shaitan DisableFunctions }

	//((CEdit*)GetDlgItem(IDC_BUTTON_SAVE_NAMES))->EnableWindow(bEnable);
}


/*=========================================================================
Function Name:  DiaCol::m_fn_vLockEditNames(true/false)
Purpose:		Called to lock or unlock edit names fields
Parameters:		True: Unlock them, false: lock them

Author:			Yann Le Tensorer
Date:			29/05/97

==========================================================================*/
void DiaCol::m_fn_vLockEditNames(BOOL bEnable)
{
	
		m_bEditNamesLocked=!bEnable;
	/*((CEdit*)GetDlgItem(IDC_EDIT_NAME1))->SetReadOnly(bReadOnly);
	((CEdit*)GetDlgItem(IDC_EDIT_NAME2))->SetReadOnly(bReadOnly);
	((CEdit*)GetDlgItem(IDC_EDIT_NAME3))->SetReadOnly(bReadOnly);
	((CEdit*)GetDlgItem(IDC_EDIT_NAME4))->SetReadOnly(bReadOnly);
	((CEdit*)GetDlgItem(IDC_EDIT_NAME5))->SetReadOnly(bReadOnly);
	((CEdit*)GetDlgItem(IDC_EDIT_NAME6))->SetReadOnly(bReadOnly);
	((CEdit*)GetDlgItem(IDC_EDIT_NAME7))->SetReadOnly(bReadOnly);
	((CEdit*)GetDlgItem(IDC_EDIT_NAME8))->SetReadOnly(bReadOnly);
	((CEdit*)GetDlgItem(IDC_EDIT_NAME9))->SetReadOnly(bReadOnly);
	((CEdit*)GetDlgItem(IDC_EDIT_NAME10))->SetReadOnly(bReadOnly);
	((CEdit*)GetDlgItem(IDC_EDIT_NAME11))->SetReadOnly(bReadOnly);
	((CEdit*)GetDlgItem(IDC_EDIT_NAME12))->SetReadOnly(bReadOnly);
	((CEdit*)GetDlgItem(IDC_EDIT_NAME13))->SetReadOnly(bReadOnly);
	((CEdit*)GetDlgItem(IDC_EDIT_NAME14))->SetReadOnly(bReadOnly);
	((CEdit*)GetDlgItem(IDC_EDIT_NAME15))->SetReadOnly(bReadOnly);
	((CEdit*)GetDlgItem(IDC_EDIT_NAME16))->SetReadOnly(bReadOnly);
	((CEdit*)GetDlgItem(IDC_BUTTON_SAVE_NAMES))->SetReadOnly(bReadOnly);*/
}


/*=========================================================================
Function Name:  DiaCol::m_fn_vEnableWindowFields(true/false)
Purpose:		Called to enable or disable all fields of dialog (except check)
Parameters:		True: Rend les champs actifs, False, les rend inactifs

Author:			Yann Le Tensorer
Date:			22-04-97
==========================================================================*/
void DiaCol::m_fn_vEnableWindowFields(BOOL bEnable)
{

	if ( !bEnable )
	{
		m_fn_vLockEditNames(bEnable); 
//ANNECY Shaitan DisableFunctions (16/04/98) {
		GetDlgItem(IDC_BUTTON_SAVE_NAMES)->EnableWindow(g_bMasterEditor && bEnable);
//ENDANNECY Shaitan DisableFunctions }
		//uncheck all checkboxes
		m_uwIdentifier = 0;
		m_fn_vSetCheckBoxesValues();
		((CButton *) GetDlgItem(IDC_CHECK_HIGHLIGHT))->SetCheck(FALSE);
	}


//	GetDlgItem( IDC_BUTTON_SET_DEFAULT  )->EnableWindow( bEnable );
//	GetDlgItem( IDC_BUTTON_LOAD         )->EnableWindow( bEnable );
//	GetDlgItem( IDC_BUTTON_SAVE         )->EnableWindow( bEnable );
//ANNECY Shaitan DisableFunctions (16/04/98) {
	GetDlgItem(IDC_CHECK1)->EnableWindow( g_bMasterEditor && bEnable );
	GetDlgItem(IDC_CHECK2)->EnableWindow( g_bMasterEditor && bEnable );
	GetDlgItem(IDC_CHECK3)->EnableWindow( g_bMasterEditor && bEnable );
	GetDlgItem(IDC_CHECK4)->EnableWindow( g_bMasterEditor && bEnable );
	GetDlgItem(IDC_CHECK5)->EnableWindow( g_bMasterEditor && bEnable );
	GetDlgItem(IDC_CHECK6)->EnableWindow( g_bMasterEditor && bEnable );
	GetDlgItem(IDC_CHECK7)->EnableWindow( g_bMasterEditor && bEnable );
	GetDlgItem(IDC_CHECK8)->EnableWindow( g_bMasterEditor && bEnable );
	GetDlgItem(IDC_CHECK9)->EnableWindow( g_bMasterEditor && bEnable );
	GetDlgItem(IDC_CHECK10)->EnableWindow( g_bMasterEditor && bEnable );
	GetDlgItem(IDC_CHECK11)->EnableWindow( g_bMasterEditor && bEnable );
	GetDlgItem(IDC_CHECK12)->EnableWindow( g_bMasterEditor && bEnable );
	GetDlgItem(IDC_CHECK13)->EnableWindow( g_bMasterEditor && bEnable );
	GetDlgItem(IDC_CHECK14)->EnableWindow( g_bMasterEditor && bEnable );
	GetDlgItem(IDC_CHECK15)->EnableWindow( g_bMasterEditor && bEnable );
	GetDlgItem(IDC_CHECK16)->EnableWindow( g_bMasterEditor && bEnable );
	GetDlgItem(IDC_RADIO_ZDR)->EnableWindow( g_bMasterEditor && bEnable );
	GetDlgItem(IDC_RADIO_ZDE)->EnableWindow( g_bMasterEditor && bEnable );
	GetDlgItem(IDC_RADIO_ZDM)->EnableWindow( g_bMasterEditor && bEnable );
	GetDlgItem(IDC_BUTTON_RENAMECOL)->EnableWindow( g_bMasterEditor && bEnable );
//ENDANNECY Shaitan DisableFunctions }
	GetDlgItem(IDC_CHECK_HIGHLIGHT)->EnableWindow( bEnable );
	GetDlgItem(IDC_BUTTON_HIGHLIGHTCOLOR)->EnableWindow( bEnable );
	
	m_fn_vEnableEditNames(bEnable); 

//ANNECY Shaitan DisableFunctions (16/04/98) {
	GetDlgItem( IDC_CHECK_LOCK_NAMES)->EnableWindow(g_bMasterEditor && bEnable);

	GetDlgItem( IDC_BUTTON_COPYCOL )->EnableWindow(g_bMasterEditor && bEnable);
	
	if (bEnable)
		//there is a target submaterial, hance paste is enabled
		GetDlgItem(IDC_BUTTON_PASTECOL)->EnableWindow(m_p_oCopyBuffer ? g_bMasterEditor /*TRUE*/ : FALSE);
//ENDANNECY Shaitan DisableFunctions }
	else
		//the target has no submaterial, hance we cannot paste
		GetDlgItem(IDC_BUTTON_PASTECOL)->EnableWindow(FALSE);
}

//==================================================================================================
//==================================================================================================
// DiaCol diagnostics

#ifdef _DEBUG
void DiaCol::AssertValid() const
{
	CFormView::AssertValid();
}

void DiaCol::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}
#endif //_DEBUG

//==================================================================================================
//==================================================================================================
// DiaCol message handlers

BOOL DiaCol::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext) 
{
	if (CFormView::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext))
	{
		m_p_oMaterialCombo = (CComboBox *) GetDlgItem(IDC_COMBO_COLMATNAME);
		UpdateData(FALSE);
		m_fn_vEnableWindowFields(FALSE);
		GetDlgItem(IDC_CHECK_DISABLE_COLLISIONS)->EnableWindow(FALSE);
		EnableToolTips(TRUE);

		//control registration for tutorial and assistants, should be unregistered when view is destroyed
		TUT_M_vGetTutDll(); 
		TUT_M_vRegisterControlID(IDC_CHECK1,"TGM_DiaColCheck1",TUT_e_Button);
		TUT_M_vRegisterControlID(IDC_CHECK2,"TGM_DiaColCheck2",TUT_e_Button);
		TUT_M_vRegisterControlID(IDC_CHECK3,"TGM_DiaColCheck3",TUT_e_Button);
		TUT_M_vRegisterControlID(IDC_CHECK4,"TGM_DiaColCheck4",TUT_e_Button);
		TUT_M_vRegisterControlID(IDC_CHECK5,"TGM_DiaColCheck5",TUT_e_Button);
		TUT_M_vRegisterControlID(IDC_CHECK6,"TGM_DiaColCheck6",TUT_e_Button);
		TUT_M_vRegisterControlID(IDC_CHECK7,"TGM_DiaColCheck7",TUT_e_Button);
		TUT_M_vRegisterControlID(IDC_CHECK8,"TGM_DiaColCheck8",TUT_e_Button);
		TUT_M_vRegisterControlID(IDC_CHECK9,"TGM_DiaColCheck9",TUT_e_Button);
		TUT_M_vRegisterControlID(IDC_CHECK10,"TGM_DiaColCheck10",TUT_e_Button);
		TUT_M_vRegisterControlID(IDC_CHECK11,"TGM_DiaColCheck11",TUT_e_Button);
		TUT_M_vRegisterControlID(IDC_CHECK12,"TGM_DiaColCheck12",TUT_e_Button);
		TUT_M_vRegisterControlID(IDC_CHECK13,"TGM_DiaColCheck13",TUT_e_Button);
		TUT_M_vRegisterControlID(IDC_CHECK14,"TGM_DiaColCheck14",TUT_e_Button);
		TUT_M_vRegisterControlID(IDC_CHECK15,"TGM_DiaColCheck15",TUT_e_Button);
		TUT_M_vRegisterControlID(IDC_CHECK16,"TGM_DiaColCheck16",TUT_e_Button);
		TUT_M_vRegisterControlID(IDC_CHECK_DISABLE_COLLISIONS,"TGM_DiaColCheckDisableCollisions",TUT_e_Button);
		TUT_M_vRegisterControlID(IDC_BUTTON_HIGHLIGHTCOLOR,"TGM_DiaColButtonHighlightColor",TUT_e_Button);
		TUT_M_vRegisterControlID(IDC_CHECK_HIGHLIGHT,"TGM_DiaColCheckHighlight",TUT_e_Button);
		TUT_M_vRegisterControlID(IDC_COMBO_COLMATNAME,"TGM_DiaColComboMaterialName",TUT_e_ComboBox);
		TUT_M_vRegisterControlID(IDC_BUTTON_COPYCOL,"TGM_DiaColButtonCopyMaterial",TUT_e_Button);
		TUT_M_vRegisterControlID(IDC_BUTTON_PASTECOL,"TGM_DiaColButtonPasteMaterial",TUT_e_Button);
		TUT_M_vRegisterControlID(IDC_BUTTON_RENAMECOL,"TGM_DiaColButtonRenameMaterial",TUT_e_Button);
		TUT_M_vRegisterControlID(IDC_RADIO_ZDM,"TGM_DiaColRadioZDM",TUT_e_Button);
		TUT_M_vRegisterControlID(IDC_RADIO_ZDR,"TGM_DiaColRadioZDR",TUT_e_Button);
		TUT_M_vRegisterControlID(IDC_RADIO_ZDE,"TGM_DiaColRadioZDE",TUT_e_Button);
		TUT_M_vRegisterControlID(IDC_CHECK_LOCK_NAMES,"TGM_DiaColCheckLockNames",TUT_e_Button);
		TUT_M_vRegisterControlID(IDC_BUTTON_SAVE_NAMES,"TGM_DiaColButtonSaveNames",TUT_e_Button);
		TUT_M_vRegisterControlID(IDC_EDIT_NAME1,"TGM_DiaColEditName1",TUT_e_TextEdit);
		TUT_M_vRegisterControlID(IDC_EDIT_NAME2,"TGM_DiaColEditName2",TUT_e_TextEdit);
		TUT_M_vRegisterControlID(IDC_EDIT_NAME3,"TGM_DiaColEditName3",TUT_e_TextEdit);
		TUT_M_vRegisterControlID(IDC_EDIT_NAME4,"TGM_DiaColEditName4",TUT_e_TextEdit);
		TUT_M_vRegisterControlID(IDC_EDIT_NAME5,"TGM_DiaColEditName5",TUT_e_TextEdit);
		TUT_M_vRegisterControlID(IDC_EDIT_NAME6,"TGM_DiaColEditName6",TUT_e_TextEdit);
		TUT_M_vRegisterControlID(IDC_EDIT_NAME7,"TGM_DiaColEditName7",TUT_e_TextEdit);
		TUT_M_vRegisterControlID(IDC_EDIT_NAME8,"TGM_DiaColEditName8",TUT_e_TextEdit);
		TUT_M_vRegisterControlID(IDC_EDIT_NAME9,"TGM_DiaColEditName9",TUT_e_TextEdit);
		TUT_M_vRegisterControlID(IDC_EDIT_NAME10,"TGM_DiaColEditName10",TUT_e_TextEdit);
		TUT_M_vRegisterControlID(IDC_EDIT_NAME11,"TGM_DiaColEditName11",TUT_e_TextEdit);
		TUT_M_vRegisterControlID(IDC_EDIT_NAME12,"TGM_DiaColEditName12",TUT_e_TextEdit);
		TUT_M_vRegisterControlID(IDC_EDIT_NAME13,"TGM_DiaColEditName13",TUT_e_TextEdit);
		TUT_M_vRegisterControlID(IDC_EDIT_NAME14,"TGM_DiaColEditName14",TUT_e_TextEdit);
		TUT_M_vRegisterControlID(IDC_EDIT_NAME15,"TGM_DiaColEditName15",TUT_e_TextEdit);
		TUT_M_vRegisterControlID(IDC_EDIT_NAME16,"TGM_DiaColEditName16",TUT_e_TextEdit);

		return TRUE; 
	}
	else
		return FALSE;
}

/*=============================================================================
==============================================================================*/

void DiaCol::m_fn_vSetCheckBoxesValues()
{
	/*short _wTypeOfZone,short _wIdentifier*/
	m_check1.SetCheck(m_uwIdentifier & (1 << 0));
	m_check2.SetCheck(m_uwIdentifier & (1 << 1));
	m_check3.SetCheck(m_uwIdentifier & (1 << 2));
	m_check4.SetCheck(m_uwIdentifier & (1 << 3));
	m_check5.SetCheck(m_uwIdentifier & (1 << 4));
	m_check6.SetCheck(m_uwIdentifier & (1 << 5));
	m_check7.SetCheck(m_uwIdentifier & (1 << 6));
	m_check8.SetCheck(m_uwIdentifier & (1 << 7));
	m_check9.SetCheck(m_uwIdentifier & (1 << 8));
	m_check10.SetCheck(m_uwIdentifier & (1 << 9));
	m_check11.SetCheck(m_uwIdentifier & (1 << 10));
	m_check12.SetCheck(m_uwIdentifier & (1 << 11));
	m_check13.SetCheck(m_uwIdentifier & (1 << 12));
	m_check14.SetCheck(m_uwIdentifier & (1 << 13));
	m_check15.SetCheck(m_uwIdentifier & (1 << 14));
	m_check16.SetCheck(m_uwIdentifier & (1 << 15));

	m_RadioTypeOfZone = m_uwTypeOfZone;
	UpdateData(FALSE);
}

// met les variables m_wTypeOfZone, m_wIdentifier a jour en fonction des variables internes des check boxes
void DiaCol::m_fn_vGetCheckBoxesValues(unsigned short *p_wTypeOfZone, unsigned short *p_wIdentifier)
{
	*p_wIdentifier = 0;

	UpdateData(TRUE);
	*p_wTypeOfZone = (unsigned short) m_RadioTypeOfZone;

	if ( m_check1.GetCheck() ) *p_wIdentifier += 1;
	if ( m_check2.GetCheck() ) *p_wIdentifier += 2;
	if ( m_check3.GetCheck() ) *p_wIdentifier += 4;
	if ( m_check4.GetCheck() ) *p_wIdentifier += 8;
	if ( m_check5.GetCheck() ) *p_wIdentifier += 16;
	if ( m_check6.GetCheck() ) *p_wIdentifier += 32;
	if ( m_check7.GetCheck() ) *p_wIdentifier += 64;
	if ( m_check8.GetCheck() ) *p_wIdentifier += 128;
	if ( m_check9.GetCheck() ) *p_wIdentifier += 256;
	if ( m_check10.GetCheck() ) *p_wIdentifier += 512;
	if ( m_check11.GetCheck() ) *p_wIdentifier += 1024;
	if ( m_check12.GetCheck() ) *p_wIdentifier += 2048;
	if ( m_check13.GetCheck() ) *p_wIdentifier += 4096;
	if ( m_check14.GetCheck() ) *p_wIdentifier += 8192;
	if ( m_check15.GetCheck() ) *p_wIdentifier += 16384;
	if ( m_check16.GetCheck() ) *p_wIdentifier += 32768;
}


/*=========================================================================
//  Description : Edit a color, return true if color has changed
==========================================================================*/
BOOL DiaCol::m_bEditColor(GLI_tdstColor *p_stColor)
{
	COLORREF				cr = RGB(p_stColor->xR * 255, p_stColor->xG * 255, p_stColor->xB * 255);
	CColorDialog		CColor( cr, CC_RGBINIT | CC_FULLOPEN, this );
	if (CColor.DoModal() == IDOK)
	{
		cr = CColor.GetColor();
		p_stColor->xR = (GEO_tdxColorValue) (GetRValue(cr) / 255.0);
		p_stColor->xG = (GEO_tdxColorValue) (GetGValue(cr) / 255.0);
		p_stColor->xB = (GEO_tdxColorValue) (GetBValue(cr) / 255.0);
		p_stColor->xA = (GEO_tdxColorValue) 0.0;
		return TRUE;
	}
	return FALSE;
}

/*=========================================================================
Function Name:  DiaCol::OnCheckDisableMechanics()
Purpose:		Called when clicked on the disable mechanics check box
Author:			Yann Le Tensorer
Date:			16-04-97

This function is called each time the check box is clicked
==========================================================================*/
void DiaCol::OnCheckDisableCollisions() 
{
	if ( m_bAutoDispatch )
		return;
	m_bAutoDispatch = TRUE;

	/* avoid errors */
	if ( !gs_p_oMaterialInterface->m_p_oGetEditedMaterial() )
	{
		m_CheckDisableCollisions.SetCheck(FALSE);
		m_fn_vEnableWindowFields(FALSE);
		return;
	}

	//get the handle to the edited game material
	GMT_tdxHandleToGameMaterial hGameMaterial = gs_p_oMaterialInterface->m_p_oGetEditedMaterial()->m_hGetEngineMaterial();
//ROMTEAM WorldEditor (Cristi Petrescu 22/12/97)
	tdoEditorGameMaterial *poGameMaterial = gs_p_oMaterialInterface->m_p_oGetEditedMaterial();
	WORD wTypeOfZone = poGameMaterial -> m_uwTypeOfZonesUsingMe ();
//ENDROMTEAM WorldEditor (Cristi Petrescu)

	//we enable the collide ministructure
	if ( m_CheckDisableCollisions.GetCheck() == TRUE ) 
	{
//ROMTEAM WorldEditor (Cristi Petrescu 22/12/97)
		// Allocate it only if the material is not used by a mixed set of zones
		if (wTypeOfZone &&
			wTypeOfZone != GMT_C_uwZDM &&
			wTypeOfZone != GMT_C_uwZDR &&
			wTypeOfZone != GMT_C_uwZDE &&
			wTypeOfZone != GMT_C_uwZDD &&
			wTypeOfZone != GMT_C_uwBoundingVolume)
		{
			M_GetMainWnd()->UpdateStatus("Mixed set of zones", C_STATUSPANE_INFOS, C_STATUS_ERROR);			
			m_CheckDisableCollisions.SetCheck(FALSE);
		}
		else
		{
			/* Allocate MS Collide (using do/undo) */
			tdoCreateEngineCollideModif *p_oModif = new tdoCreateEngineCollideModif(hGameMaterial);
			if ( M_p_oGetEditManager()->AskFor(p_oModif) == FALSE )
			{
				m_CheckDisableCollisions.SetCheck(FALSE);
				m_fn_vEnableWindowFields(TRUE);
			}
			// And set the right type of zone, if necessary
			// again sorry for name similarities
			switch (wTypeOfZone)
			{
			case GMT_C_uwZDM:
				m_RadioTypeOfZone = GMT_C_wZDM;
				break;
			case GMT_C_uwZDR:
				m_RadioTypeOfZone = GMT_C_wZDR;
				break;
			case GMT_C_uwZDE:
				m_RadioTypeOfZone = GMT_C_wZDE;
				break;
			}
			m_uwTypeOfZone = (unsigned short) m_RadioTypeOfZone;
			UpdateData (FALSE);
		}
//ENDROMTEAM WorldEditor (Cristi Petrescu)
	}
	else //we disable the mini structure
	{
		/* Free MS Collide */
		tdoDeleteEngineCollideModif *p_oModif = new tdoDeleteEngineCollideModif(
			hGameMaterial,
			GMT_fn_hGetCollideMaterial(hGameMaterial)
		);
		if ( M_p_oGetEditManager()->AskFor(p_oModif) == FALSE )
		{
			m_CheckDisableCollisions.SetCheck(TRUE);		 
//ROMTEAM WorldEditor (Cristi Petrescu 22/12/97)
			// only if the selected item will be 0 ("nothing")
			// [QUESTION] why this line, anyway (Cristi P) ???
			if (m_p_oMaterialCombo -> GetCurSel () == 0)
				m_fn_vEnableWindowFields(FALSE);
//ENDROMTEAM WorldEditor (Cristi Petrescu)
		}
	}

	m_bAutoDispatch = FALSE;
}

//==================================================================================================
//==================================================================================================
void DiaCol::OnCheckButtons() 
{
	if ( m_bAutoDispatch )
		return;
	m_bAutoDispatch = TRUE;

	m_fn_vSetMaterial();

	m_bAutoDispatch = FALSE;
}

//==================================================================================================
//==================================================================================================
void DiaCol::OnRadioZoneTypes() 
{
	if ( m_bAutoDispatch )
		return;
	m_bAutoDispatch = TRUE;
	UpdateData(TRUE);

//ROMTEAM WorldEditor (Cristi Petrescu 22/12/97)
	// check for coherence of zones...
	tdoEditorCollideMaterial *poCollideMaterial = (tdoEditorCollideMaterial *) gs_p_oMaterialInterface->m_p_oGetEditorObjectForEngine(m_hHandleToCollideMaterial);
	ASSERT (poCollideMaterial);
	WORD uwZoneType = poCollideMaterial -> m_uwTypeOfZonesUsingMe ();
	if (m_bReportCollisionIncoherence (uwZoneType, m_RadioTypeOfZone))
	{
		// set the button to the old position
		m_RadioTypeOfZone = m_uwTypeOfZone;
		UpdateData (FALSE);
	}
	else
	{
		m_uwTypeOfZone = (unsigned short) m_RadioTypeOfZone;
		m_fn_vShowNames();
		m_fn_vSetToMotor();
	}
//ENDROMTEAM WorldEditor (Cristi Petrescu)

	m_bAutoDispatch = FALSE;
}

//==================================================================================================
//==================================================================================================
BOOL DiaCol::m_fn_bChangeName(int i,CString *_csName,CString *_csOldName,BOOL _bMessage)
{
	
	UpdateData(TRUE);
	if (*_csName==*_csOldName) return TRUE;
	if (m_p_oMyNameObject[m_uwTypeOfZone*C_uc_NumberOfNames+i].fn_eRename(*_csName))
	{
		m_fn_vSetMaterial();
		*_csOldName=*_csName;
		return TRUE;
	}
	else
	{
		if (_bMessage && (*_csName!=*_csOldName))
		{
			AfxMessageBox("You can't use this Name. It is already used.");
			*_csName=*_csOldName;
			UpdateData(FALSE);
		}
		return FALSE;
	}
}
	


//==================================================================================================
//==================================================================================================
void DiaCol::OnKillfocusEditName1() 
{
	m_fn_bChangeName(0,&m_name1,&m_oldname1,TRUE);
}

//==================================================================================================
void DiaCol::OnKillfocusEditName10() 
{
	m_fn_bChangeName(9,&m_name10,&m_oldname10,TRUE);
	
	
}

//==================================================================================================
void DiaCol::OnKillfocusEditName11() 
{
	m_fn_bChangeName(10,&m_name11,&m_oldname11,TRUE);
	
}

//==================================================================================================
void DiaCol::OnKillfocusEditName12() 
{
	m_fn_bChangeName(11,&m_name12,&m_oldname12,TRUE);
	
}

//==================================================================================================
void DiaCol::OnKillfocusEditName13() 
{
	m_fn_bChangeName(12,&m_name13,&m_oldname13,TRUE);
	
}

//==================================================================================================
void DiaCol::OnKillfocusEditName14() 
{
	m_fn_bChangeName(13,&m_name14,&m_oldname14,TRUE);
}

//==================================================================================================
void DiaCol::OnKillfocusEditName15() 
{
	m_fn_bChangeName(14,&m_name15,&m_oldname15,TRUE);
	
}

//==================================================================================================
void DiaCol::OnKillfocusEditName16() 
{
	m_fn_bChangeName(15,&m_name16,&m_oldname16,TRUE);
	
}

//==================================================================================================
void DiaCol::OnKillfocusEditName2() 
{
	m_fn_bChangeName(1,&m_name2,&m_oldname2,TRUE);
	
}

//==================================================================================================
void DiaCol::OnKillfocusEditName3() 
{
	m_fn_bChangeName(2,&m_name3,&m_oldname3,TRUE);
	
}

//==================================================================================================
void DiaCol::OnKillfocusEditName4() 
{
	m_fn_bChangeName(3,&m_name4,&m_oldname4,TRUE);
	
}

//==================================================================================================
void DiaCol::OnKillfocusEditName5() 
{
	m_fn_bChangeName(4,&m_name5,&m_oldname5,TRUE);
}

//==================================================================================================
void DiaCol::OnKillfocusEditName6() 
{
	m_fn_bChangeName(5,&m_name6,&m_oldname6,TRUE);
}

//==================================================================================================
void DiaCol::OnKillfocusEditName7() 
{
	m_fn_bChangeName(6,&m_name7,&m_oldname7,TRUE);
}

//==================================================================================================
void DiaCol::OnKillfocusEditName8() 
{
	m_fn_bChangeName(7,&m_name8,&m_oldname8,TRUE);
}

//==================================================================================================
void DiaCol::OnKillfocusEditName9() 
{
	m_fn_bChangeName(8,&m_name9,&m_oldname9,TRUE);
}

//==================================================================================================
//==================================================================================================
void DiaCol::OnCheckLockNames() 
{
	if ( m_bAutoDispatch )
		return;
	m_bAutoDispatch = TRUE;

	if (m_CheckLockNames.GetCheck()==1) 
	{
		m_fn_vLockEditNames(FALSE);
		GetDlgItem(IDC_BUTTON_SAVE_NAMES)->EnableWindow(FALSE);
	}
	else
	{
		m_fn_vLockEditNames(TRUE);
//ANNECY Shaitan DisableFunctions (16/04/98) {
		GetDlgItem(IDC_BUTTON_SAVE_NAMES)->EnableWindow(g_bMasterEditor /*TRUE*/);
//ENDANNECY Shaitan DisableFunctions }
	}

	m_bAutoDispatch = FALSE;
}

//==================================================================================================
//==================================================================================================
void DiaCol::OnButtonSaveNames() 
{
	//SCR_tdst_File_Description stFile;
	SCR_tdst_File_Description stFileDesc;
	SCR_FILE xFileHandle;

	CString csBaseDataPath = "GameData\\World\\Libraries\\Materials\\";

	//FILE    *p_xFile;
	CString csFileName(csBaseDataPath + "ED.emc");
	char*	TmpName=(char*)malloc(255);

	//p_stFile=&stFile;
    
  //p_xFile = fopen(p_FileName, "wb");
	xFileHandle = SCR_M_p_x_File_OpenWrite(csFileName);

	if ( xFileHandle == NULL )
	{
		CString ErrorMsg;

		ErrorMsg = "Could not create file: " + csFileName;
		ErrorMsg += "\n\nEither the path \"" + csBaseDataPath + "\" doesn't exist, or the file is write protected";
		AfxMessageBox( ErrorMsg );
		return;
	}
	
	//make a dummy notification so that the section appears in the scripts's list of modified sections
	SCR_fn_v_SvL1_RegisterNotify(
    (char *)LPCTSTR(csFileName), //section name
    NULL, //callback
    NULL, //data
    SCR_EA_Ntfy_AddOrModifySection //action
	);

	SCR_fn_v_File_InitFileDes(&stFileDesc,(char*)LPCTSTR(csFileName), xFileHandle);
	SCR_M_SvL0_SaveScriptFileHeader(&stFileDesc);
	SCR_M_SvL0_SaveComment(&stFileDesc,"Editeur de matériaux, paramètres de collision, sauvegarde des noms");
	
	for (int i=0;i<C_uc_NumberOfNames*3;i++)
	{
		if (i%C_uc_NumberOfNames==0)
		{
			switch (i/C_uc_NumberOfNames)
			{
			case 0:
				SCR_M_SvL0_SaveBeginSection(&stFileDesc, "ZDM:", SCR_CC_C_Cfg_EOL); 
				break;
			case 1:
				SCR_M_SvL0_SaveEndSection(&stFileDesc, SCR_CC_C_Cfg_EOL); 
				SCR_M_SvL0_SaveBeginSection(&stFileDesc, "ZDR:", SCR_CC_C_Cfg_EOL); 
				break;
			case 2:
				SCR_M_SvL0_SaveEndSection(&stFileDesc, SCR_CC_C_Cfg_EOL); 
				SCR_M_SvL0_SaveBeginSection(&stFileDesc, "ZDE:", SCR_CC_C_Cfg_EOL); 
				break;
			}
		}
	
		//char *p_szTmpName = (char *);
		//strcpy (TmpName ,m_p_oMyNameObject[i].GetName());
		SCR_M_SvL0_SaveEntry(&stFileDesc, (char*)LPCTSTR(m_p_oMyNameObject[i].GetName()), SCR_CC_C_Cfg_EOL);
	}

	SCR_M_SvL0_SaveEndSection(&stFileDesc, SCR_CC_C_Cfg_EOL); 

	SCR_M_File_Close(&stFileDesc);
	SCR_fn_v_File_CloseFileDes(&stFileDesc);
	//fclose(p_xFile);

	/*CString EndMsg(p_FileName);
	EndMsg += " Saved";*/
		
	fn_vGiveProgressInfo("Collision identifier names saved in " + csFileName, -1);

	m_CheckLockNames.SetCheck(TRUE);
	OnCheckLockNames();

/*	free(TmpName);
	free(p_FileName);*/
}


//==================================================================================================
//==================================================================================================
SCR_tde_Anl_ReturnValue DiaCol::fn_v_LoadZDMNames(
	SCR_tdst_File_Description * /*_p_stFile*/,
	char *_p_szName,
	char * /*_ap_szPars*/[],
	SCR_tde_Anl_Action _eAction
)
{
	SCR_tde_Anl_ReturnValue eReturnValue = SCR_ERV_Anl_NormalReturn;
  
	if(_eAction==SCR_EA_Anl_BeginSection)
	{
		/* If a section is detected */      
		g_oMaterialCol->m_currentNameRead = 0;

	}
	else if ( _eAction == SCR_EA_Anl_Entry )
	{  
		BOOL result;

		result = g_oMaterialCol->m_p_oMyNameObject[g_oMaterialCol->m_currentNameRead].fn_eRename((CString)_p_szName);
	
		g_oMaterialCol->m_currentNameRead ++;

	}
	return eReturnValue; 

}

//==================================================================================================
//==================================================================================================
SCR_tde_Anl_ReturnValue DiaCol::fn_v_LoadZDRNames
(
	SCR_tdst_File_Description * /*_p_stFile*/,
	char *_p_szName,
	char * /*_ap_szPars*/[],
	SCR_tde_Anl_Action _eAction
)
{

	SCR_tde_Anl_ReturnValue eReturnValue = SCR_ERV_Anl_NormalReturn;
  
	if ( _eAction == SCR_EA_Anl_BeginSection )
	{
	/* If a section is detected */      
		g_oMaterialCol->m_currentNameRead=C_uc_NumberOfNames;

	}
	else if ( _eAction == SCR_EA_Anl_Entry )
	{  
		BOOL result = g_oMaterialCol->m_p_oMyNameObject[g_oMaterialCol->m_currentNameRead].fn_eRename((CString)_p_szName);

		g_oMaterialCol->m_currentNameRead ++;

	}
	return eReturnValue;
}

//==================================================================================================
//==================================================================================================
SCR_tde_Anl_ReturnValue DiaCol::fn_v_LoadZDENames
(
	SCR_tdst_File_Description * /*_p_stFile*/,
	char *_p_szName,
	char * /*_ap_szPars*/[],
	SCR_tde_Anl_Action _eAction
)
{
	SCR_tde_Anl_ReturnValue eReturnValue = SCR_ERV_Anl_NormalReturn;
  
	if ( _eAction == SCR_EA_Anl_BeginSection )
	{
	
		g_oMaterialCol->m_currentNameRead = C_uc_NumberOfNames * 2;

	}
	else if ( _eAction == SCR_EA_Anl_Entry )
	{  
		BOOL result = g_oMaterialCol->m_p_oMyNameObject[g_oMaterialCol->m_currentNameRead].fn_eRename((CString)_p_szName);

		g_oMaterialCol->m_currentNameRead ++;	

	}
	return eReturnValue; 

}

//==================================================================================================
//==================================================================================================
/* à appeler dans justafterregistered...*/
void DiaCol::m_fn_vInitLoad() 
{
	SCR_fn_v_RdL0_RegisterCallback("ZDM",DiaCol::fn_v_LoadZDMNames, SCR_CRC_c_RdL0_ForSection);
	SCR_fn_v_RdL0_RegisterCallback("ZDR",DiaCol::fn_v_LoadZDRNames, SCR_CRC_c_RdL0_ForSection);
	SCR_fn_v_RdL0_RegisterCallback("ZDE",DiaCol::fn_v_LoadZDENames, SCR_CRC_c_RdL0_ForSection);
}


void DiaCol::m_fn_vLoadNames() 
{
	CString csBaseDataPath = "GameData\\World\\Libraries\\Materials\\";
	char *p_FileName=(char*)malloc(255);
	FILE *myfile;

	strcpy(p_FileName, csBaseDataPath + "ED.emc");
	m_currentNameRead = 0;
    
	if ( (myfile = fopen(p_FileName,"rb")) != NULL) /* if file exists */
	{
		fclose(myfile);
		SCR_fnp_st_RdL0_AnalyseSection(p_FileName, SCR_CDF_uw_Anl_Normal);
	}

	free(p_FileName);
}


/*======================================================
Class tdoColNameObject
========================================================*/

/*----------------------------
Constructor
------------------------------*/
tdoColNameObject::tdoColNameObject()
: CPA_BaseObject(
	gs_p_oMaterialInterface, //editor
	C_szMaterialColName, //type
	NULL, //owner
	TRUE //availability
)
{
}


/*----------------------------
Destructor
----------------------------*/
tdoColNameObject::~tdoColNameObject()
{
}

/*==================================================================================================
  Réponses à l'appui sur le bouton Copy
==================================================================================================*/
void DiaCol::OnButtonCopyCollideMaterial() 
{
	if ( m_bAutoDispatch )
		return;
	m_bAutoDispatch = TRUE;

	if ( m_p_oCopyBuffer )
		delete m_p_oCopyBuffer;
	m_p_oCopyBuffer = new tdoCopyBuffer(m_hHandleToCollideMaterial);

//ANNECY Shaitan DisableFunctions (16/04/98) {
	GetDlgItem(IDC_BUTTON_PASTECOL)->EnableWindow(g_bMasterEditor /*TRUE*/);
//ENDANNECY Shaitan DisableFunctions }

	m_bAutoDispatch = FALSE;
}

/*==================================================================================================
  when the submaterial is renamed
==================================================================================================*/
void DiaCol::OnButtonRenameCollideMaterial() 
{
	if ( m_bAutoDispatch )
		return;
	m_bAutoDispatch = TRUE;

	tdoEditorCollideMaterial *p_oCollideMaterial = (tdoEditorCollideMaterial *) gs_p_oMaterialInterface->m_p_oGetEditorObjectForEngine(m_hHandleToCollideMaterial);
	if ( p_oCollideMaterial )
	{
		CString csOldName = p_oCollideMaterial->GetName();
		CString csNewName;
		m_p_oMaterialCombo->GetWindowText(csNewName);
		if ( csNewName.IsEmpty() )
			csNewName = 	C_szCollideMaterialTypeName "1";
	  csNewName = gs_p_oMaterialInterface->GetInterface()->GetPrefixedName(csNewName);
		//this will cause a OnModifyChild() message to be sent for each referencing game material
		p_oCollideMaterial->fn_eRename(csNewName);
		//now update the combo with the new name
		short wIndex = m_p_oMaterialCombo->FindStringExact(-1, csOldName);
		m_p_oMaterialCombo->DeleteString(wIndex);
		m_p_oMaterialCombo->InsertString(wIndex, p_oCollideMaterial->GetName());
		m_p_oMaterialCombo->SetItemDataPtr(wIndex, p_oCollideMaterial);
		m_p_oMaterialCombo->SetCurSel(wIndex);
	}

	m_bAutoDispatch = FALSE;
}

/*==================================================================================================
  Réponses à l'appui sur le bouton Paste
==================================================================================================*/
void DiaCol::OnButtonPasteCollideMaterial() 
{
	if ( m_bAutoDispatch )
		return;
	m_bAutoDispatch = TRUE;

	if ( m_p_oCopyBuffer )
	{
//ROMTEAM WorldEditor (Cristi Petrescu 22/12/97)
		if (m_p_oCopyBuffer -> m_eGetType () == E_cbt_Collide)
		{
			// collision materials involved, check for incoherencies...
			tdoEditorGameMaterial *p_oGameMaterial = gs_p_oMaterialInterface->m_p_oGetEditedMaterial();
			WORD wNewTypeOfZone =  p_oGameMaterial -> m_uwTypeOfZonesUsingMe ();
			GMT_tdxHandleToCollideMaterial hHandleToCollideMaterial = m_p_oCopyBuffer -> m_hGetCollideMaterial ();
			if (hHandleToCollideMaterial == GMT_C_InvalidCollideMaterial)
			{
				//  this should never happen
				// ASSERT (FALSE);
				// but i'm not sure, so why give headaches to the user?
				m_bAutoDispatch = FALSE;
				return;
			}	
			// this is only because of the laxism of the previuos version...
			tdoEditorCollideMaterial *p_oNewCollideMaterial = (tdoEditorCollideMaterial *) gs_p_oMaterialInterface->m_p_oGetEditorObjectForEngine(hHandleToCollideMaterial);
			WORD wOldTypeOfZone = p_oNewCollideMaterial -> m_uwTypeOfZonesUsingMe (); 
			WORD wTypeOfCollision = GMT_fn_wGetTypeOfCollideMaterial(hHandleToCollideMaterial);
			if (m_bReportCollisionIncoherence2 (wNewTypeOfZone, wOldTypeOfZone, wTypeOfCollision))
			{
				m_bAutoDispatch = FALSE;
				return;
			}
		}
//ENDROMTEAM WorldEditor (Cristi Petrescu)
		M_p_oGetEditManager()->AskFor(new tdoPasteSubMaterialModif(m_p_oCopyBuffer));
	}

	m_bAutoDispatch = FALSE;

	//fake a subsequent copy, so that we can paste or instaciate again if we want to
	OnButtonCopyCollideMaterial();
}

/*==================================================================================================
  when the text changes in the edit part of the combo
==================================================================================================*/
void DiaCol::OnComboEditChange() 
{
	if ( m_bAutoDispatch )
		return;
	m_bAutoDispatch = TRUE;

	CString csMaterialName;
	m_p_oMaterialCombo->GetWindowText(csMaterialName);
	if ( csMaterialName.IsEmpty() )
		csMaterialName = 	C_szCollideMaterialTypeName "1";
	csMaterialName = gs_p_oMaterialInterface->GetInterface()->GetPrefixedName(csMaterialName);

	tdoEditorCollideMaterial *p_oCollideMaterial = NULL;
	//if we did not find a material with the engine, try to find one with the name, in case the script was
	//parsed and editor materials were created for unloaded sections -> they have no valid engine material
	if ( !csMaterialName.IsEmpty() )
		p_oCollideMaterial = (tdoEditorCollideMaterial *) gs_p_oMaterialInterface->GetMainWorld()->fn_p_oFindObject(
			csMaterialName, C_szCollideMaterialTypeName
		);

	//to enable a rename, the name must be unique, and a current material must be selected
//ANNECY Shaitan DisableFunctions (16/04/98) {
	GetDlgItem(IDC_BUTTON_RENAMECOL)->EnableWindow(p_oCollideMaterial ? FALSE : g_bMasterEditor /*TRUE*/);
//ENDANNECY Shaitan DisableFunctions }

	m_bAutoDispatch = FALSE;
}

/*==================================================================================================
  When the user selects another submaterial
==================================================================================================*/
void DiaCol::OnComboSelChange() 
{
	if ( m_bAutoDispatch )
		return;
	m_bAutoDispatch = TRUE;

	short wIndex = m_p_oMaterialCombo->GetCurSel();
	if ( wIndex != CB_ERR )
	{
		tdoEditorGameMaterial *p_oGameMaterial = gs_p_oMaterialInterface->m_p_oGetEditedMaterial();
		GMT_tdxHandleToGameMaterial hGameMaterial = p_oGameMaterial->m_hGetEngineMaterial();
		tdoEditorCollideMaterial *p_oNewCollideMaterial = (tdoEditorCollideMaterial *) m_p_oMaterialCombo->GetItemDataPtr(wIndex);
		tdoEditorCollideMaterial *p_oPrevCollideMaterial = (tdoEditorCollideMaterial *) gs_p_oMaterialInterface->m_p_oGetEditorObjectForEngine(m_hHandleToCollideMaterial);
		//if the newly selected material is not the previous one
		if ( p_oPrevCollideMaterial != p_oNewCollideMaterial )
		{
//ROMTEAM WorldEditor (Cristi Petrescu 22/12/97)
			WORD wNewTypeOfZone =  p_oGameMaterial -> m_uwTypeOfZonesUsingMe ();
			// to detect mixtures & empty usages
			if (p_oNewCollideMaterial)
			{
				p_oNewCollideMaterial->m_vLoadAssociatedEngineMaterial(); //in case it was not analyzed yet...
				// this is only because of the laxism of the previuos version...
				WORD wOldTypeOfZone = p_oNewCollideMaterial -> m_uwTypeOfZonesUsingMe (); 
				GMT_tdxHandleToCollideMaterial hHandleToCollideMaterial = p_oNewCollideMaterial -> m_hGetEngineMaterial ();

				if (hHandleToCollideMaterial != GMT_C_InvalidCollideMaterial)
				{
					WORD wTypeOfCollision = GMT_fn_wGetTypeOfCollideMaterial(hHandleToCollideMaterial);
					if (m_bReportCollisionIncoherence2 (wNewTypeOfZone, wOldTypeOfZone, wTypeOfCollision))
					{
						// undo the combo box selection, we do not want to change 
						// the colision submaterial for this game material
						int iComboIndex;
						if (p_oPrevCollideMaterial)
							iComboIndex = m_p_oMaterialCombo->FindStringExact(-1, p_oPrevCollideMaterial->GetName());
						else
							iComboIndex = 0;

						if (iComboIndex != CB_ERR)
						{
							m_p_oMaterialCombo -> SetCurSel (iComboIndex);
							// exit from this function
							m_bAutoDispatch = FALSE;
							return;
						}
					}
				}
			}
//ENDROMTEAM WorldEditor (Cristi Petrescu)

			//update coherence manager links
			if ( p_oPrevCollideMaterial )
				g_oCoherenceManager.m_fn_vRemoveALink(p_oGameMaterial, p_oPrevCollideMaterial);
			if ( p_oNewCollideMaterial )
				g_oCoherenceManager.m_fn_vAddALink(p_oGameMaterial,	p_oNewCollideMaterial);

			//get the engine handle for the new submaterial
			GMT_tdxHandleToCollideMaterial hNewCollideMaterial;
			if ( p_oNewCollideMaterial )
			{
				p_oNewCollideMaterial->m_vLoadAssociatedEngineMaterial(); //in case it was not analyzed yet...
				hNewCollideMaterial = p_oNewCollideMaterial->m_hGetEngineMaterial();
			}
			else
				hNewCollideMaterial = GMT_C_InvalidCollideMaterial;

			//give the handle to the game material
			GMT_fn_vSetCollideMaterial(hGameMaterial, hNewCollideMaterial);
			//the game material will have to be saved
			p_oGameMaterial->fn_vNotifySave();
			//update the display
			m_fn_vShowMaterial(hGameMaterial);
			//and update world display if necessary as well
			if 
			( 
				(p_oPrevCollideMaterial ? p_oPrevCollideMaterial->m_bGetHighlightColor() : FALSE) 
				|| (p_oNewCollideMaterial ? p_oNewCollideMaterial->m_bGetHighlightColor() : FALSE)
			)
				M_GetMainDevice3D()->DrawObject();
		}
	}

	m_bAutoDispatch = FALSE;
}

/*==================================================================================================
  When one of the edits looses focus
==================================================================================================*/
void DiaCol::OnSetfocusEditName1() 
{
	if (m_bEditNamesLocked) 
	{
		GetDlgItem(IDC_CHECK1)->SetFocus();
		((CButton*)GetDlgItem(IDC_CHECK1))->SetCheck( !(( (CButton*)GetDlgItem(IDC_CHECK1) )->GetCheck()) );
		m_fn_vSetMaterial();
	}
	
}

//==================================================================================================
void DiaCol::OnSetfocusEditName10() 
{
	if (m_bEditNamesLocked) 
	{
		GetDlgItem(IDC_CHECK10)->SetFocus();
		((CButton*)GetDlgItem(IDC_CHECK10))->SetCheck( !(( (CButton*)GetDlgItem(IDC_CHECK10) )->GetCheck()) );
		m_fn_vSetMaterial();
	}
}

//==================================================================================================
void DiaCol::OnSetfocusEditName11() 
{
	if (m_bEditNamesLocked) 
	{
		GetDlgItem(IDC_CHECK11)->SetFocus();
		((CButton*)GetDlgItem(IDC_CHECK11))->SetCheck( !(( (CButton*)GetDlgItem(IDC_CHECK11) )->GetCheck()) );
		m_fn_vSetMaterial();
	}
}

//==================================================================================================
void DiaCol::OnSetfocusEditName12() 
{
	if (m_bEditNamesLocked) 
	{
		GetDlgItem(IDC_CHECK12)->SetFocus();
		((CButton*)GetDlgItem(IDC_CHECK12))->SetCheck( !(( (CButton*)GetDlgItem(IDC_CHECK12) )->GetCheck()) );
		m_fn_vSetMaterial();
	}
}

//==================================================================================================
void DiaCol::OnSetfocusEditName13() 
{
	if (m_bEditNamesLocked) 
	{
		GetDlgItem(IDC_CHECK13)->SetFocus();
		((CButton*)GetDlgItem(IDC_CHECK13))->SetCheck( !(( (CButton*)GetDlgItem(IDC_CHECK13) )->GetCheck()) );
		m_fn_vSetMaterial();
	}
	
}

//==================================================================================================
void DiaCol::OnSetfocusEditName14() 
{
	if (m_bEditNamesLocked) 
	{
		GetDlgItem(IDC_CHECK14)->SetFocus();
		((CButton*)GetDlgItem(IDC_CHECK14))->SetCheck( !(( (CButton*)GetDlgItem(IDC_CHECK14) )->GetCheck()) );
		m_fn_vSetMaterial();
	}
}

//==================================================================================================
void DiaCol::OnSetfocusEditName15() 
{
	if (m_bEditNamesLocked) 
	{
		GetDlgItem(IDC_CHECK15)->SetFocus();
		((CButton*)GetDlgItem(IDC_CHECK15))->SetCheck( !(( (CButton*)GetDlgItem(IDC_CHECK15) )->GetCheck()) );
		m_fn_vSetMaterial();
	}
}

//==================================================================================================
void DiaCol::OnSetfocusEditName16() 
{
	if (m_bEditNamesLocked) 
	{
		GetDlgItem(IDC_CHECK16)->SetFocus();
		((CButton*)GetDlgItem(IDC_CHECK16))->SetCheck( !(( (CButton*)GetDlgItem(IDC_CHECK16) )->GetCheck()) );
		m_fn_vSetMaterial();
	}
}

//==================================================================================================
void DiaCol::OnSetfocusEditName2() 
{
	if (m_bEditNamesLocked) 
	{
		GetDlgItem(IDC_CHECK2)->SetFocus();
		((CButton*)GetDlgItem(IDC_CHECK2))->SetCheck( !(( (CButton*)GetDlgItem(IDC_CHECK2) )->GetCheck()) );
		m_fn_vSetMaterial();
	}
}

//==================================================================================================
void DiaCol::OnSetfocusEditName3() 
{
	if (m_bEditNamesLocked) 
	{
		GetDlgItem(IDC_CHECK3)->SetFocus();
		((CButton*)GetDlgItem(IDC_CHECK3))->SetCheck( !(( (CButton*)GetDlgItem(IDC_CHECK3) )->GetCheck()) );
		m_fn_vSetMaterial();
	}

}

//==================================================================================================
void DiaCol::OnSetfocusEditName4() 
{
	if (m_bEditNamesLocked) 
	{
		GetDlgItem(IDC_CHECK4)->SetFocus();
		((CButton*)GetDlgItem(IDC_CHECK4))->SetCheck( !(( (CButton*)GetDlgItem(IDC_CHECK4) )->GetCheck()) );
		m_fn_vSetMaterial();
	}
}

//==================================================================================================
void DiaCol::OnSetfocusEditName5() 
{
	if (m_bEditNamesLocked) 
	{
		GetDlgItem(IDC_CHECK5)->SetFocus();
		((CButton*)GetDlgItem(IDC_CHECK5))->SetCheck( !(( (CButton*)GetDlgItem(IDC_CHECK5) )->GetCheck()) );
		m_fn_vSetMaterial();
	}
	
}

//==================================================================================================
void DiaCol::OnSetfocusEditName6() 
{
	if (m_bEditNamesLocked) 
	{
		GetDlgItem(IDC_CHECK6)->SetFocus();
		((CButton*)GetDlgItem(IDC_CHECK6))->SetCheck( !(( (CButton*)GetDlgItem(IDC_CHECK6) )->GetCheck()) );
		m_fn_vSetMaterial();
	}
}

//==================================================================================================
void DiaCol::OnSetfocusEditName7() 
{
	if (m_bEditNamesLocked) 
	{
		GetDlgItem(IDC_CHECK7)->SetFocus();
		((CButton*)GetDlgItem(IDC_CHECK7))->SetCheck( !(( (CButton*)GetDlgItem(IDC_CHECK7) )->GetCheck()) );
		m_fn_vSetMaterial();
	}
}

//==================================================================================================
void DiaCol::OnSetfocusEditName8() 
{
	if (m_bEditNamesLocked) 
	{
		GetDlgItem(IDC_CHECK8)->SetFocus();
		((CButton*)GetDlgItem(IDC_CHECK8))->SetCheck( !(( (CButton*)GetDlgItem(IDC_CHECK8) )->GetCheck()) );	
		m_fn_vSetMaterial();
	}
}

//==================================================================================================
void DiaCol::OnSetfocusEditName9() 
{
	if (m_bEditNamesLocked) 
	{
		GetDlgItem(IDC_CHECK9)->SetFocus();
		((CButton*)GetDlgItem(IDC_CHECK9))->SetCheck( !(( (CButton*)GetDlgItem(IDC_CHECK9) )->GetCheck()) );
		m_fn_vSetMaterial();
	}
}

//==================================================================================================
//called when the user wants to change the highlight color of these characteristics
//==================================================================================================
void DiaCol::OnButtonHighlightColor() 
{
	GEO_tdstColor stTempColor;
	tdoEditorCollideMaterial *p_oMaterial = (tdoEditorCollideMaterial *) gs_p_oMaterialInterface->m_p_oGetEditorObjectForEngine(m_hHandleToCollideMaterial);
	if ( p_oMaterial && p_oMaterial->m_bGetHighlightColor(&stTempColor) && m_bEditColor(&stTempColor) )
	{
		p_oMaterial->m_vSetHighlightColor(stTempColor);
		GetDlgItem(IDC_BUTTON_HIGHLIGHTCOLOR)->Invalidate();
		//tell the main view to redraw itself because a material highlight changed aspect
		M_GetMainDevice3D()->DrawObject();
	}
}

//==================================================================================================
//called when the user enables / disables the highlight for this submaterial
//==================================================================================================
void DiaCol::OnCheckHighlight() 
{
	tdoEditorCollideMaterial *p_oMaterial = (tdoEditorCollideMaterial *) gs_p_oMaterialInterface->m_p_oGetEditorObjectForEngine(m_hHandleToCollideMaterial);
	if ( p_oMaterial )
	{
		p_oMaterial->m_vEnableHighlight(((CButton *)GetDlgItem(IDC_CHECK_HIGHLIGHT))->GetCheck());
		//the highlight color is no longer displayed in the button...
		GetDlgItem(IDC_BUTTON_HIGHLIGHTCOLOR)->Invalidate();
		M_GetMainDevice3D()->DrawObject();
	}
}

//==================================================================================================
//==================================================================================================
void DiaCol::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct) 
{
	switch ( nIDCtl )
	{
	default:
		CFormView::OnDrawItem(nIDCtl, lpDrawItemStruct);
		break;

	case IDC_BUTTON_HIGHLIGHTCOLOR:
		{
			CDC      *pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
			RECT					*rect = &lpDrawItemStruct->rcItem;
			GEO_tdstColor stColor;
			COLORREF			xColor;
			tdoEditorCollideMaterial *p_oMaterial = (tdoEditorCollideMaterial *) gs_p_oMaterialInterface->m_p_oGetEditorObjectForEngine(m_hHandleToCollideMaterial);
			if ( p_oMaterial && p_oMaterial->m_bGetHighlightColor(&stColor) )
			{
				xColor = RGB( stColor.xR * 255, stColor.xG * 255, stColor.xB * 255 );
			}
			else
				xColor = RGB(192,192,192);
			pDC->FillSolidRect( rect, xColor);
		}
		break;
	}
}

//==================================================================================================
//==================================================================================================
//==================================================================================================
//==================================================================================================
//==================================================================================================
//==================================================================================================
//==================================================================================================
//==================================================================================================
tdoCreateEngineCollideModif::tdoCreateEngineCollideModif(GMT_tdxHandleToGameMaterial _MyMatHandle)
: CPA_Modif(0, "Enable Collisions")
{
	m_hEditedGameMaterial = _MyMatHandle;
	m_p_oDestroyModif = NULL;
	m_hCollideAfterDo = GMT_C_InvalidCollideMaterial;
}

//==================================================================================================
//==================================================================================================
tdoCreateEngineCollideModif::~tdoCreateEngineCollideModif()
{
	if ( m_p_oDestroyModif )
	{
		delete m_p_oDestroyModif;
		m_p_oDestroyModif = NULL;
	}
}

//==================================================================================================
//==================================================================================================
BOOL tdoCreateEngineCollideModif::Do()
{
	if ( m_p_oDestroyModif ) //if it is created, this is a Redo -> An Undo of our destroy modif
		return m_p_oDestroyModif->Undo();
	else //this is the first time we Do() the action
	{
		//create an engine material and the associated editor material
		GMT_tdxHandleToCollideMaterial hNewCollideMaterial = GMT_fn_hCreateCollideMaterial();
		if ( hNewCollideMaterial != GMT_C_InvalidCollideMaterial )
		{
			//get the material that we see in the dialog, and the material modified by the operation
			tdoEditorGameMaterial *p_oCurrentEditedGameMaterial = (tdoEditorGameMaterial *) gs_p_oMaterialInterface->m_p_oGetEditedMaterial();
			tdoEditorGameMaterial *p_oModifiedGameMaterial = (tdoEditorGameMaterial *) gs_p_oMaterialInterface->m_p_oGetEditorObjectForEngine(m_hEditedGameMaterial);

			//put the default values in the engine material
			GMT_fn_vSetTypeOfCollideMaterial(hNewCollideMaterial, GMT_C_wZDM);
			GMT_fn_hSetCollideMaterialIdentifier(hNewCollideMaterial, 0);

			//create the associated editor material
			tdoEditorCollideMaterial *p_oNewEditorCollideMaterial = new tdoEditorCollideMaterial(
				p_oGetFileObjectForReferencedPath(CString("ED") + tdoEditorCollideMaterial::m_csGetScriptExtension()),
				p_oModifiedGameMaterial->GetName() /*C_szCollideMaterialTypeName "1"*/,
				FALSE, 
				hNewCollideMaterial
			);

			//add the new submaterial in the display combo
			CComboBox *p_oCombo = gs_p_oMaterialInterface->m_p_oGetCollView()->m_p_oMaterialCombo;
			short wComboIndex = p_oCombo->AddString(p_oNewEditorCollideMaterial->GetName());
			p_oCombo->SetItemDataPtr(wComboIndex, p_oNewEditorCollideMaterial);

			//give the mechanics material to the game material
			GMT_fn_vSetCollideMaterial(m_hEditedGameMaterial, hNewCollideMaterial);

			//notify that the game material section is to be updated
			p_oModifiedGameMaterial->fn_vNotifySave();
			//tell the coherence manager that the game material references the collide material
			g_oCoherenceManager.m_fn_vAddALink(p_oModifiedGameMaterial,	p_oNewEditorCollideMaterial);

			//if the modified game material in displayed in the dialogs, update display
			if ( p_oCurrentEditedGameMaterial == p_oModifiedGameMaterial )
			{
				//update controls
				gs_p_oMaterialInterface->m_p_oGetCollView()->m_fn_vEnableWindowFields(TRUE);
				if ( !gs_p_oMaterialInterface->m_p_oGetCollView()->m_CheckDisableCollisions.GetCheck() ) 
					gs_p_oMaterialInterface->m_p_oGetCollView()->m_CheckDisableCollisions.SetCheck(TRUE);
				//fill them with the contents of the edited material
				gs_p_oMaterialInterface->m_p_oGetCollView()->m_fn_vShowMaterial(p_oCurrentEditedGameMaterial->m_hGetEngineMaterial());
			}

			//create the destroy modif for future undo/redo actions
			m_p_oDestroyModif = new tdoDeleteEngineCollideModif(m_hEditedGameMaterial, p_oNewEditorCollideMaterial->m_hGetEngineMaterial());
			return TRUE;
		}
		else //the engine object could not be created
			return FALSE;
	}
}

//==================================================================================================
//==================================================================================================
BOOL tdoCreateEngineCollideModif::Undo()
{
	return m_p_oDestroyModif ? m_p_oDestroyModif->Do() : FALSE;
}

//==================================================================================================
//==================================================================================================
//==================================================================================================
//==================================================================================================
tdoDeleteEngineCollideModif::tdoDeleteEngineCollideModif(
	GMT_tdxHandleToGameMaterial _MyMatHandle,
	GMT_tdxHandleToCollideMaterial _hCollideMaterial
) : CPA_Modif(0, "Disable Collisions")
{
	m_hEditedGameMaterial = _MyMatHandle;
	m_hEditedCollideMaterial = _hCollideMaterial;
	m_p_oEditedGameMaterial = (tdoEditorGameMaterial *) gs_p_oMaterialInterface->m_p_oGetEditorObjectForEngine(m_hEditedGameMaterial);
	m_p_oEditedCollideMaterial = (tdoEditorCollideMaterial *) gs_p_oMaterialInterface->m_p_oGetEditorObjectForEngine(m_hEditedCollideMaterial);
}

//==================================================================================================
//==================================================================================================
tdoDeleteEngineCollideModif::~tdoDeleteEngineCollideModif()
{
	if ( HasBeenDone() ) //if the removal is done when the object is destroyed
	{
		//if the collide material is not used by any game material, destroy it
		if ( !m_p_oEditedCollideMaterial->m_bIsReferenced() )
		{
			//we are the only one to hold the handle for the collide material
			//hence we can free it from memory
			GMT_fn_vDestroyCollideMaterial(&m_hEditedCollideMaterial);
			m_hEditedCollideMaterial = GMT_C_InvalidCollideMaterial;
			//do not forget to destroy the editor object as well
			delete m_p_oEditedCollideMaterial;
			m_p_oEditedCollideMaterial = NULL;
		}
	}
}

//==================================================================================================
//==================================================================================================
BOOL tdoDeleteEngineCollideModif::Do()
{
	if ( m_hEditedCollideMaterial != GMT_C_InvalidCollideMaterial )
	{
//ROMTEAM WorldEditor (Cristi Petrescu 22/12/97)
		ASSERT (m_p_oEditedGameMaterial);
		WORD wTypeOfZone = m_p_oEditedGameMaterial -> m_uwTypeOfZonesUsingMe ();
		if (wTypeOfZone)
		{
			M_GetMainWnd()->UpdateStatus("Collision material used by a zone", C_STATUSPANE_INFOS, C_STATUS_ERROR);			
			return FALSE;
		}
//ENDROMTEAM WorldEditor (Cristi Petrescu)
		//tell the coherence manager that the game material does not reference the collide material
		g_oCoherenceManager.m_fn_vRemoveALink(m_p_oEditedGameMaterial, m_p_oEditedCollideMaterial);
		//if there remains no game material using this submaterial
		if ( !m_p_oEditedCollideMaterial->m_bIsReferenced() )
		{
			//try to remove the object from the hierarchy
			if ( !m_p_oEditedCollideMaterial->fn_bUnValidate() ) //if we failed
			{
				//restore the link as it was before
				g_oCoherenceManager.m_fn_vAddALink(m_p_oEditedGameMaterial, m_p_oEditedCollideMaterial);
				//the operation could not be done
				return FALSE;
			}
			//now that the object no longer exists for the hierarchy, tell the scripts not to save it
			m_p_oEditedCollideMaterial->fn_vNotifyUnSave();
			//and remove it from the combo in which it is listed
			CComboBox *p_oCombo = gs_p_oMaterialInterface->m_p_oGetCollView()->m_p_oMaterialCombo;
			short wComboIndex = p_oCombo->FindStringExact(-1, m_p_oEditedCollideMaterial->GetName());
			p_oCombo->DeleteString(wComboIndex);
		}
		//tell the game material not to use the mechanics material any more
		GMT_fn_vSetCollideMaterial(m_hEditedGameMaterial, GMT_C_InvalidCollideMaterial);
		//and tell the scripts that the game material section is to be updated
		m_p_oEditedGameMaterial->fn_vNotifySave();

		//update the display if the modified game material is being displayed by the editor
		if ( m_p_oEditedGameMaterial == gs_p_oMaterialInterface->m_p_oGetEditedMaterial() )
		{
			GMT_tdxHandleToGameMaterial hInvalidGameMaterial;
			GMT_fn_vInvalidate(&hInvalidGameMaterial);
			gs_p_oMaterialInterface->m_p_oGetCollView()->m_fn_vShowMaterial(hInvalidGameMaterial);
		}
		return TRUE;
	}
	//we did nothing
	return FALSE;
}

//==================================================================================================
//==================================================================================================
BOOL tdoDeleteEngineCollideModif::Undo()
{
	if ( m_hEditedCollideMaterial != GMT_C_InvalidCollideMaterial )
	{
		//give back the mechanics material to the game material
		GMT_fn_vSetCollideMaterial(m_hEditedGameMaterial, m_hEditedCollideMaterial);

		//tell we want to save it again
		if ( !m_p_oEditedCollideMaterial->fn_bIsValid() )
		{
			m_p_oEditedCollideMaterial->fn_bValidate();
			m_p_oEditedCollideMaterial->fn_vNotifyRestore();
			//and restore it in the combo in which it was listed
			CComboBox *p_oCombo = gs_p_oMaterialInterface->m_p_oGetCollView()->m_p_oMaterialCombo;
			short wComboIndex = p_oCombo->AddString(m_p_oEditedCollideMaterial->GetName());
			p_oCombo->SetItemDataPtr(wComboIndex, m_p_oEditedCollideMaterial);
		}
		//tell the scripts that the game material section is to be updated
		m_p_oEditedGameMaterial->fn_vNotifySave();

		//tell the coherence manager that the game material references the collide material
		g_oCoherenceManager.m_fn_vAddALink(m_p_oEditedGameMaterial, m_p_oEditedCollideMaterial);

		//update the display if the modified game material is being displayed by the editor
		if ( m_p_oEditedGameMaterial == gs_p_oMaterialInterface->m_p_oGetEditedMaterial() )
			gs_p_oMaterialInterface->m_p_oGetCollView()->m_fn_vShowMaterial(m_p_oEditedGameMaterial->m_hGetEngineMaterial());
		return TRUE;
	}
	//we did nothing
	return FALSE;
}

//ROMTEAM WorldEditor (Cristi Petrescu 22/12/97)

//////////////////////////////////////////////////////////////////////////////////////////////////////
// Method : DiaCol::m_bReportCollisionIncoherence(WORD wTypeOfZones, WORD wTypeOfCollision)
// Date   : 97.12.18
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Description : Reports any incoherence between the type of a collision material and the type of the 
//               zones objects using that material
// Author      : Cristi Petrescu
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Modification :
// Date         :
// By           :
//////////////////////////////////////////////////////////////////////////////////////////////////////
BOOL DiaCol::m_bReportCollisionIncoherence(WORD wTypeOfZones, WORD wTypeOfCollision)
{
	// sorry for the name similarities!
	if (wTypeOfZones)
	{
		// there is at least a zone using this material
		BOOL bWrongZoneType = FALSE;
		switch (wTypeOfCollision)
		{
		case GMT_C_wZDM:
			if (! (wTypeOfZones & GMT_C_uwZDM))
				bWrongZoneType = TRUE;
			break;
		case GMT_C_wZDR:
			if (! (wTypeOfZones & GMT_C_uwZDR))
				bWrongZoneType = TRUE;
			break;
		case GMT_C_wZDE:
			if (! (wTypeOfZones & GMT_C_uwZDE))
				bWrongZoneType = TRUE;
			break;
		}

		if (wTypeOfZones != GMT_C_uwZDM &&
			wTypeOfZones != GMT_C_uwZDR &&
			wTypeOfZones != GMT_C_uwZDE &&
			wTypeOfZones != GMT_C_uwZDD &&
			wTypeOfZones != GMT_C_uwBoundingVolume)
		{
			// we have an incoherence, maybe somebody will fix it...
			::MessageBox (NULL,
						  "There are zones using this collision material\n"
						  "which are of wrong type (mixed zone types)",
						  "Material warning",
						  MB_ICONEXCLAMATION | MB_OK);	
			bWrongZoneType = TRUE;
		}

		if (bWrongZoneType)
		{
			// we canot change, because of incoherence rising...
			M_GetMainWnd()->UpdateStatus("Unable to change the type because of rising incoherence", C_STATUSPANE_INFOS, C_STATUS_ERROR);
			return TRUE;
		}
		else
		{
			return FALSE;
		}
	}
	else
	{
		// maybe in other levels ?
		if (IDYES == ::MessageBox (NULL,
								   "No zones using the material in this level, but\n"
								   "there might be zones using the material in other levels.\n"
								   "Changing its collision properties might rise incoherences.\n"
								   "          Are you sure you want to do this?",
								   "Material warning",
								   MB_YESNO))
		{
			return FALSE;
		}
		else
		{
			return TRUE;
		}
	}
}

//////////////////////////////////////////////////////////////////////////////////////////////////////
// Method : DiaCol::m_bReportCollisionIncoherence(WORD wTypeOfZones, WORD wTypeOfCollision)
// Date   : 97.12.18
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Description : Reports any incoherence between the type of a collision material and the type of the 
//               zones objects using that material
//				 For the old type check usage by mixed zone
//				 For the new type, check that only zones with the right type are using that material
// Author      : Cristi Petrescu
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Modification :
// Date         :
// By           :
//////////////////////////////////////////////////////////////////////////////////////////////////////
BOOL DiaCol::m_bReportCollisionIncoherence2(WORD wNewTypeOfZones, WORD wOldTypeOfZones, WORD wTypeOfCollision)
{
	// Old
	// sorry for the name similarities!
	if (wOldTypeOfZones)
	{
		// there is at least a zone using this material
		BOOL bWrongZoneType = FALSE;
		switch (wTypeOfCollision)
		{
		case GMT_C_wZDM:
			if (! (wOldTypeOfZones & GMT_C_uwZDM))
				bWrongZoneType = TRUE;
			break;
		case GMT_C_wZDR:
			if (! (wOldTypeOfZones & GMT_C_uwZDR))
				bWrongZoneType = TRUE;
			break;
		case GMT_C_wZDE:
			if (! (wOldTypeOfZones & GMT_C_uwZDE))
				bWrongZoneType = TRUE;
			break;
		}

		if (wOldTypeOfZones != GMT_C_uwZDM &&
			wOldTypeOfZones != GMT_C_uwZDR &&
			wOldTypeOfZones != GMT_C_uwZDE &&
			wOldTypeOfZones != GMT_C_uwZDD &&
			wOldTypeOfZones != GMT_C_uwBoundingVolume)
		{
			// we have an incoherence, maybe somebody will fix it...
			::MessageBox (NULL,
						  "There are zones using this collision material\n"
						  "which are of wrong type (mixed zone types)",
						  "Material warning",
						  MB_ICONEXCLAMATION | MB_OK);	
			bWrongZoneType = TRUE;
		}

		else if (bWrongZoneType)
		{
			// we have an incoherence, maybe somebody will fix it...
			::MessageBox (NULL,
						  "This change may raise an incoherence (mixed zone types)",
						  "Material warning",
						  MB_ICONEXCLAMATION | MB_OK);	
		}
	}
	else
	{
		/*
		// maybe in other levels ?
		if (IDYES == ::MessageBox (NULL,
								   "There might be zones using the material in other levels.\n"
								   "Changing its collision properties might rise incoherences.\n"
								   "          Are you sure you want to do this?",
								   "Material warning",
								   MB_YESNO))
		{
			return FALSE;
		}
		else
		{
			return TRUE;
		}
		*/
	}
	// New
	// sorry for the name similarities!
	if (wNewTypeOfZones)
	{
		// there is at least a zone using this material
		BOOL bWrongZoneType = FALSE;
		switch (wTypeOfCollision)
		{
		case GMT_C_wZDM:
			if (! (wNewTypeOfZones & GMT_C_uwZDM))
				bWrongZoneType = TRUE;
			break;
		case GMT_C_wZDR:
			if (! (wNewTypeOfZones & GMT_C_uwZDR))
				bWrongZoneType = TRUE;
			break;
		case GMT_C_wZDE:
			if (! (wNewTypeOfZones & GMT_C_uwZDE))
				bWrongZoneType = TRUE;
			break;
		}

		if (wNewTypeOfZones != GMT_C_uwZDM &&
			wNewTypeOfZones != GMT_C_uwZDR &&
			wNewTypeOfZones != GMT_C_uwZDE &&
			wNewTypeOfZones != GMT_C_uwZDD &&
			wNewTypeOfZones != GMT_C_uwBoundingVolume)
		{
			// we have an incoherence, maybe somebody will fix it...
			::MessageBox (NULL,
						  "There will be zones using this collision material\n"
						  "which will be of wrong type (mixed zone types)",
						  "Material warning",
						  MB_ICONEXCLAMATION | MB_OK);	
			bWrongZoneType = TRUE;
		}

		else if (bWrongZoneType)
		{
			// we have an incoherence, maybe somebody will fix it...
			::MessageBox (NULL,
						  "This change may raise an incoherence (mixed zone types)",
						  "Material warning",
						  MB_ICONEXCLAMATION | MB_OK);	
		}
	}
	else
	{
		// maybe in other levels ?
		if (IDYES == ::MessageBox (NULL,
								   "No zones using the material in this level, but\n"
								   "there might be zones using the material in other levels.\n"
								   "Changing its collision properties might rise incoherences.\n"
								   "          Are you sure you want to do this?",
								   "Material warning",
								   MB_YESNO))
		{
			return FALSE;
		}
		else
		{
			return TRUE;
		}
	}
	return FALSE;
}
//ENDROMTEAM WorldEditor (Cristi Petrescu)
