示例#1
0
int GetLastFileName(const CKBehaviorContext& behcontext)
{

    CKBehavior* beh = behcontext.Behavior;
    CKContext* ctx = behcontext.Context;

    XString Inpath (ctx->GetLastCmoLoaded());



    CKParameterOut *pout = beh->GetOutputParameter(0);
    pout->SetStringValue(Inpath.Str());

    PathRemoveFileSpec(Inpath.Str());


    CKParameterOut *pout2 = beh->GetOutputParameter(1);
    pout2->SetStringValue(Inpath.Str());



    beh->ActivateOutput(0);


    return 0;

}
示例#2
0
 /*
 *******************************************************************
 * Function: CKBehavior* BGLoader(CKSTRING fileName,const CKBehaviorContext& behContext)
 *
 * Description : Load a virtools script.and add it to the current level.
 *
 * Parameters :
 *    fileName				  string containing	the script filename to be loaded.
 *    behaviourContext	      Behavior context reference, which gives access to 
 *                            frequently used global objects ( context, level, manager, etc... )
 *
 * Returns : CKBehavior* the loaded behaviour, NULL if failed.
 *
 *******************************************************************
 */
CKBehavior* GBLCOBGWrapper::BGLoader(CKSTRING fileName,const CKBehaviorContext& behContext)
{
	CKERROR	result = CKBR_GENERICERROR;

	// Initialize common pointers.	
	CKBehavior *behaviour   = behContext.Behavior;
	CKContext  *context   = behContext.Context;
	CKLevel    *level = behContext.CurrentLevel;
	CKBeObject *owner = behContext.Behavior->GetOwner();

	if ( behaviour == NULL || context == NULL || level == NULL )
		return NULL;
	
	char fileToLoad[_MAX_PATH],nakedFileName[_MAX_PATH];
	char drive[_MAX_DRIVE], dir[_MAX_DIR], fname[_MAX_FNAME], ext[_MAX_EXT];
	_splitpath(fileName, drive, dir, fname, ext);

	if ( ext[0] == 0 )
		strcpy(ext,".nms");

	strcpy(fileToLoad,drive);
	strcat(fileToLoad,dir);
	strcat(fileToLoad,fname);
	strcat(fileToLoad,ext);

	if ( strcmp(_strlwr(ext),".nms") != 0 ) 
	{
		context->OutputToConsoleExBeep("BGWrapper : Can only load .nms files %s",fileToLoad);
		return NULL;
	}
	
	CKObjectArray* array = CreateCKObjectArray();

	context->SetAutomaticLoadMode(CKLOAD_OK, CKLOAD_OK, CKLOAD_USECURRENT, CKLOAD_USECURRENT);

	// Virtools Load the BGs nms file.first try the absolute path, then the lastCmoloaded path, and then the PathManager manager data paths
	if (context->Load(fileToLoad, array, (CK_LOAD_FLAGS)(CK_LOAD_AUTOMATICMODE | CK_LOAD_AS_DYNAMIC_OBJECT )) != CK_OK)
	{
		strcpy(nakedFileName,fname);
		strcat(nakedFileName,ext);

		CKSTRING lastCmo = context->GetLastCmoLoaded();
		char driveCmo[_MAX_DRIVE], dirCmo[_MAX_DIR], fnameCmo[_MAX_FNAME], extCmo[_MAX_EXT];
		_splitpath(lastCmo, driveCmo, dirCmo, fnameCmo, extCmo);

		strcpy(fileToLoad,driveCmo);strcat(fileToLoad,dirCmo);strcat(fileToLoad,nakedFileName);

		if (context->Load(fileToLoad, array, (CK_LOAD_FLAGS)(CK_LOAD_AUTOMATICMODE | CK_LOAD_AS_DYNAMIC_OBJECT )) != CK_OK)
		{
			// failed then try to go thru the data path.
			CKPathManager* pathmanager = behContext.Context->GetPathManager();
			if (!pathmanager) 
			{
				context->OutputToConsoleExBeep("BGWrapper : Cannot find the Path Manager");
				return NULL;
			}

			XString resolved(nakedFileName);
			array->Clear();
			pathmanager->ResolveFileName(resolved,DATA_PATH_IDX,-1);
			if (context->Load(resolved.Str(), array, (CK_LOAD_FLAGS)(CK_LOAD_AUTOMATICMODE | CK_LOAD_AS_DYNAMIC_OBJECT )) != CK_OK)
			{
				context->OutputToConsoleExBeep("BGWrapper : Cannot Load %s", nakedFileName);
				return NULL;
			}
		}


	}

	// Check if only one Object is loaded (we should have only one BG here)
	if ( array->GetCount() != 1 )
	{
		context->OutputToConsoleExBeep("BGWrapper : To many objects inside the nms %s.It should contain one BG only.",fileToLoad);

		level->BeginRemoveSequence(TRUE);
		for (array->Reset(); !array->EndOfList(); array->Next()) 
		{
			CKObject* curObject = array->GetData(context);
			level->RemoveObject(curObject);
			CKDestroyObject(curObject);
		}
		level->BeginRemoveSequence(FALSE);		
		DeleteCKObjectArray(array);

		return NULL;
	}

	array->Reset();
	CKObject* curObject = array->GetData(context);
	
	if ( curObject == NULL )
	{
		context->OutputToConsoleExBeep("BGWrapper : Object NULL in loaded array.");
		return NULL;
	}

	// Make it not to be saved even if it is loaded as dynamic... (not needed ?)
	curObject->ModifyObjectFlags( CK_OBJECT_NOTTOBESAVED,0 );
	
	// Check if the object we've loaded is derivated from the BEHAVIOR
	if ( !CKIsChildClassOf(curObject, CKCID_BEHAVIOR) )
	{
		context->OutputToConsoleExBeep("BGWrapper : no behavior in the nms : %s",fileToLoad);

		level->BeginRemoveSequence(TRUE);
		level->RemoveObject(curObject);
		level->BeginRemoveSequence(FALSE);		
		CKDestroyObject(curObject);
		DeleteCKObjectArray(array);

		return NULL;
	}

	CKBehavior*pBG = (CKBehavior*)curObject;

	// Check if the behavior we've loaded is a BG and not a BB.
	if ( pBG->IsUsingFunction() )
	{
		context->OutputToConsoleExBeep("BGWrapper : BGWrapper accepts only a BG not a BB : %s",fileToLoad);

		level->BeginRemoveSequence(TRUE);
		level->RemoveObject(curObject);
		level->BeginRemoveSequence(FALSE);		
		CKDestroyObject(curObject);
		DeleteCKObjectArray(array);

		return NULL;
	}

	// Check if the BG can be applied to the <BGWrapper BB>'s BeObject owner.
	char*nameee = pBG->GetName();
	CK_CLASSID cid = pBG->GetCompatibleClassID();
	
	
	if (owner!=NULL)
		if ( !CKIsChildClassOf(owner, pBG->GetCompatibleClassID()) )
		{
			context->OutputToConsoleExBeep("BGWrapper : Incompatible Class, cannot add BG to script %s",fileToLoad);

			level->BeginRemoveSequence(TRUE);
			level->RemoveObject(curObject);
			level->BeginRemoveSequence(FALSE);		
			CKDestroyObject(curObject);
			DeleteCKObjectArray(array);

			return NULL;
		}

	// Add the BG to the <BGWrapper BB>'s level.
	level->BeginAddSequence(TRUE);
	level->AddObject(curObject);
	level->BeginAddSequence(FALSE);
	DeleteCKObjectArray(array);

	if (owner!=NULL)
		OwnerSubBB(pBG,owner);

	return pBG;
}