//
// Common functions for Object DLL capabilities
// C. Beaudet
//

#include "stdafx.h"
#include "acp_base.h"
#include "afxdllx.h"    
#include "incitf.h"
#include "incgam.h"
#include "incai.h"
#include "WPObj.hpp"
//ANNECY Shaitan Nettoyage (12/05/98) {
/*
#include "WayObj.hpp"
#include "LinkObj.hpp"
*/
//ENDANNECY Shaitan Nettoyage }

#include "Inter.hpp"


//------------------------------------------------------------------------
// Global vars
static char                         *gs_p_szCPAVersion = C_szCPAVersion;
static AFX_EXTENSION_MODULE NEAR    extensionDLL = { NULL, NULL };

#ifdef DLL_ONLY_ONE_INSTANCE
static WaypointObjetcInterface *gs_p_oWaypointInterface = NULL;
#endif 


static CList<CPA_DLLBase*,CPA_DLLBase*> g_oListOfInstances;	//private internal


//------------------------------------------------------------------------
// functions that are present in all DLL :
//------------------------------------------------------------------------

//========================================================================
// Get current CPA version
//========================================================================
extern "C" char __declspec(dllexport) *fn_p_szGetCPAVersion(void)
{
    return gs_p_szCPAVersion;
}

//========================================================================
// Get type of this DLL
//========================================================================
extern "C" tdstDLLIdentity __declspec(dllexport) *fn_p_stGetDLLIdentity(void)
{
    g_stWayPointIdentity . eType              = OBJECT_DLL; 
    g_stWayPointIdentity . csName             = "WayPoint";
    g_stWayPointIdentity . hModule            = NULL;
    g_stWayPointIdentity . p_oListOfInstances = &g_oListOfInstances;
	
	return &g_stWayPointIdentity;
}


//========================================================================
// DLL int function
//========================================================================
extern "C" void __declspec(dllexport) fn_vInitDll(void)
{
	new CDynLinkLibrary(extensionDLL);
}

//========================================================================
// DLL entry point
//========================================================================
extern "C" int __stdcall DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
	if (dwReason == DLL_PROCESS_ATTACH)
	{
		if (!AfxInitExtensionModule(extensionDLL, hInstance))
		   return 0;
	}
	return 1;
}

//========================================================================
// Get the DLL
//========================================================================
extern "C" CPA_DLLBase  __declspec(dllexport) *fn_p_oGetDLL(long lKey)
{
#ifdef DLL_ONLY_ONE_INSTANCE

	switch(lKey)
	{
	case 0:	// the game world
		if (gs_p_oWayPointInterface == NULL)
		{
			gs_p_oWaypointInterface = new Waypoint_Interface();
			ASSERT(gs_p_oWaypointInterface != NULL);
		}
		return gs_p_oWaypointInterface;
		break;

	default:
		return NULL;
	}

#else //DLL_ONLY_ONE_INSTANCE

	switch(lKey)
	{
	case 0:	// the game world
		return new Waypoint_Interface();
		break;

	default:
		return NULL;
	}

#endif //DLL_ONLY_ONE_INSTANCE
}






//------------------------------------------------------------------------
// functions that are present in this type of DLL only :
//------------------------------------------------------------------------

#undef DLL_ONLY_ONE_INSTANCE
