/*
 *******************************************************************
 * Function: int BehaviourFunction( const CKBehaviorContext& behaviorContext )
 *
 * Description : The execution function is the function that will be called 
 *               during the process loop of the behavior engine, if the behavior 
 *               is defined as using an execution function. This function is not 
 *               called if the behavior is defined as a graph. This function is the 
 *               heart of the behavior: it should compute the essence of the behavior, 
 *               in an incremental way. The minimum amount of computing should be 
 *               done at each call, to leave time for the other behaviors to run. 
 *               The function receives the delay in milliseconds that has elapsed 
 *               since the last behavioral process, and should rely on this value to 
 *               manage the amount of effect it has on its computation, if the effect 
 *               of this computation relies on time.
 *
 * Parameters :
 *    behaviourContext    r   Behavior context reference, which gives access to 
 *                            frequently used global objects ( context, level, manager, etc... )
 *
 * Returns : int, If it is done, it should return CKBR_OK. If it returns 
 *                CKBR_ACTIVATENEXTFRAME, the behavior will again be called 
 *                during the next process loop.
 *
 *******************************************************************
 */
int GBLPFGetTeamLeader::BehaviourFunction( const CKBehaviorContext& behaviorContext )
{
    CKBehavior *behaviour=behaviorContext.Behavior;
    CKContext *context = behaviorContext.Context;
    CGBLCOError returnValue;

    behaviour->ActivateInput(EGBLGetTeamLeaderBehInputs::In, false);
    XString FieldName("TeamLeaderID");
    CKDataArray* FieldData = (CKDataArray*)context->CreateObject(CKCID_DATAARRAY, "FieldData", CK_OBJECTCREATION_DYNAMIC);
    
    CGBLTeamID TeamId ;
    behaviour->GetInputParameterValue(EGBLGetTeamLeaderParamInputs::TeamId, &TeamId);
    CGBLUserID PlayerId;

    CGBLProfileManager *pm = (CGBLProfileManager *)context->GetManagerByGuid(GBLProfileManagerGUID);
    returnValue = pm->GetProfileField((CGBLProfileID)TeamId, FieldName, (CKDataArray*)FieldData);
    int value;
    if(!FieldData->GetElementValue(0,0,&value))
    {
        returnValue = CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL;
    }
    else
    {
        PlayerId = value;
    }
    
    
    if ((int)returnValue == CGBLCOError::EGBLCOErrorType::GBLCO_OK)
    {
        behaviour->ActivateOutput(EGBLGetTeamLeaderBehOutputs::Success, true);
        behaviour->SetOutputParameterValue(EGBLGetTeamLeaderParamOutputs::UserID, &PlayerId);
    }
    else
    {
        CKParameterOut *pOut = behaviour->GetOutputParameter(EGBLGetTeamLeaderParamOutputs::ErrorCode);
        CGBLCOError::EGBLCOErrorType tType = CGBLCOError::EGBLCOErrorType::GBLCO_OK ;
        switch((CGBLCOError::EGBLCOErrorType)returnValue)
        {
        case 0:
            tType = CGBLCOError::EGBLCOErrorType::GBLCO_OK;
            break;
        case 1:
            tType = CGBLCOError::EGBLCOErrorType::GBLCO_FATAL;
            break;
        case 2:
            tType = CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL;
            break;
        case 3:
            tType = CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL;
            break;
        }
        
        
		const char*errorString = returnValue;
        TGBLError::SetTGBLError(pOut, tType,returnValue, (CKSTRING)errorString);
        behaviour->ActivateOutput(EGBLGetTeamLeaderBehOutputs::Error, true);
    }
    context->DestroyObject(FieldData);
    return CKBR_OK;
}
示例#2
0
/*
 *******************************************************************
 * Function: int BehaviourFunction( const CKBehaviorContext& behaviorContext )
 *
 * Description : The execution function is the function that will be called 
 *               during the process loop of the behavior engine, if the behavior 
 *               is defined as using an execution function. This function is not 
 *               called if the behavior is defined as a graph. This function is the 
 *               heart of the behavior: it should compute the essence of the behavior, 
 *               in an incremental way. The minimum amount of computing should be 
 *               done at each call, to leave time for the other behaviors to run. 
 *               The function receives the delay in milliseconds that has elapsed 
 *               since the last behavioral process, and should rely on this value to 
 *               manage the amount of effect it has on its computation, if the effect 
 *               of this computation relies on time.
 *
 * Paramters :
 *    behaviourContext    r   Behavior context reference, which gives access to 
 *                            frequently used global objects ( context, level, manager, etc... )
 *
 * Returns : int, If it is done, it should return CKBR_OK. If it returns 
 *                CKBR_ACTIVATENEXTFRAME, the behavior will again be called 
 *                during the next process loop.
 *
 *******************************************************************
 */
int CGBLLAEGetLA::BehaviourFunction( const CKBehaviorContext& behaviorContext )
{
	CKBehavior* beh = behaviorContext.Behavior;
  	CKContext* ctx = behaviorContext.Context;


	IGBLSMProfileAccess* pin = NULL;
    CGBLSMStorageManager *storageManager = (CGBLSMStorageManager *)ctx->GetManagerByGuid(GBLSMStorageManagerGUID);
	IGBLSMLAAccess *laInterface = storageManager->GetLAInterface();

	char *arrayName = "laList";
	CKDataArray* array;

	array = (CKDataArray *)ctx->GetObjectByNameAndClass(arrayName,CKCID_DATAARRAY,NULL);

	if ( !array )
	{
		array = (CKDataArray *)ctx->CreateObject(CKCID_DATAARRAY,arrayName, CK_OBJECTCREATION_DYNAMIC);
		behaviorContext.CurrentLevel->AddObject( array );
	
		array->InsertColumn( -1, CKARRAYTYPE_INT,	 "LAID" );
	}
	else
	{
		array->Clear();
	}

	CGBLCOError res = laInterface->RetrieveLAList(array);
	if ( res == CGBLCOError::EGBLCOErrorType::GBLCO_OK)
	{
		beh->ActivateInput(0, FALSE);
		beh->SetOutputParameterObject(0, array);
		beh->ActivateOutput(0);
	}
	else
	{
		beh->ActivateInput(0, FALSE);
		CKParameterOut *parameterOutError = beh->GetOutputParameter(1);
		TGBLError::SetTGBLError(parameterOutError,CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL,GBLLAE_ERROR_GETLISTOFLAIDS,GBLLAE_ERROR_GETLISTOFLAIDS_DESC);
		beh->ActivateOutput(1);
	}

    return CKBR_OK;
}
示例#3
0
/*
 *******************************************************************
 * Function: int CISIteratorBB( const CKBehaviorContext& behaviorContext )
 *
 * Description : The execution function is the function that will be called 
 *               during the process loop of the behavior engine, if the behavior 
 *               is defined as using an execution function. This function is not 
 *               called if the behavior is defined as a graph. This function is the 
 *               heart of the behavior: it should compute the essence of the behavior, 
 *               in an incremental way. The minimum amount of computing should be 
 *               done at each call, to leave time for the other behaviors to run. 
 *               The function receives the delay in milliseconds that has elapsed 
 *               since the last behavioral process, and should rely on this value to 
 *               manage the amount of effect it has on its computation, if the effect 
 *               of this computation relies on time.
 *
 * Parameters :
 *    behaviourContext    r   Behavior context reference, which gives access to 
 *                            frequently used global objects ( context, level, manager, etc... )
 *
 * Returns : int, If it is done, it should return CKBR_OK. If it returns 
 *                CKBR_ACTIVATENEXTFRAME, the behavior will again be called 
 *                during the next process loop.
 *
 *******************************************************************
 */
int CISIteratorBB(const CKBehaviorContext& behcontext)
{
	
	/************************************************************************/
	/* collecting data :													*/
	/*  																	*/
	
	CKBehavior* beh = behcontext.Behavior;
  	CKContext* ctx = behcontext.Context;
	CGBLCIConfigurationController* cman=(CGBLCIConfigurationController*)ctx->GetManagerByGuid(CONFIGURATION_MAN_GUID);
	

    	
	/*get the last index */
	int index = 0;
	beh->GetLocalParameterValue(BEH_LOCAL_PAR_INDEX_INDEX, &index);

	BOOL getFromDB = false;
	beh->GetLocalParameterValue(BEH_LOCAL_PAR_INDEX_DB_MODE,&getFromDB);
    
	using namespace GBLCommon::BehaviorTools;
	using namespace GBLCommon::ParameterTools;

	using namespace Customisation::typedefs;


	/************************************************************************/
	/*   behavior trigger event processing  :							    */
	/*																		*/
	/*																		*/
    


	/* Reset/On : sets the index to zero and save it  */
	if( beh->IsInputActive(0) )
	{
		beh->ActivateInput(0,FALSE);
		

		if (getFromDB)
		{
			CKDataArray * resultArray = NULL; 
			beh->GetLocalParameterValue(BEH_LOCAL_PAR_INDEX_CIID_LIST,&resultArray);
			if (resultArray)
			{
				resultArray->Clear();
				while ( resultArray->GetColumnCount() )
					resultArray->RemoveColumn(0);
			}
			else
			{
				resultArray  = static_cast<CKDataArray*>(ctx->CreateObject( CKCID_DATAARRAY, "IGBLSMConfigurationAccess::CIS_IDLIST", CK_OBJECTCREATION_DYNAMIC ));
			}
			ctx->GetCurrentLevel()->AddObject( resultArray );
			
			////////////////////////////////////////////////////////////////////////// retrieve list of CI ID's  :
			CGBLSMStorageManager *storageManager = static_cast<CGBLSMStorageManager *>(ctx->GetManagerByGuid(GBLSMStorageManagerGUID));
			IGBLSMConfigurationAccess* smCIS = storageManager->GetConfigurationInterface();

			int idCIS = GetInputParameterValue<int>(beh,BEH_IN_PAR_CIS_ID);
			smCIS->RetrieveCIList(resultArray,CGBLCISID(idCIS));
			
			beh->SetLocalParameterValue(BEH_LOCAL_PAR_INDEX_CIID_LIST,&resultArray,sizeof(CKDataArray*));
			
			int cis_size = resultArray->GetRowCount();
			beh->SetLocalParameterValue(BEH_LOCAL_PAR_INDEX_CIS_SIZE,&cis_size);
		}else
		{
			Customisation::typedefs::CIS* currentCIS = cman->GetCIS();
			if(!currentCIS)
				Logger::ShowDebugMessage(ctx,Logger::ELOGERROR,"CISIterator : couldn't find CIS");	

		}
		//reset counter : 
		index = 0 ;
		beh->SetLocalParameterValue(BEH_LOCAL_PAR_INDEX_INDEX,&index);
		beh->ActivateInput(1,TRUE);
	}

	//get LA_ID :

	
	
	int cisSize;
	beh->GetLocalParameterValue(BEH_LOCAL_PAR_INDEX_CIS_SIZE,&cisSize);
	    

	/* bounding check for the index: if out of range, set to zero and save it.*/ 
	if(index > cisSize -1  )
	{
		index = 0;
		beh->SetLocalParameterValue(BEH_LOCAL_PAR_INDEX_INDEX,&index);
		beh->ActivateOutput(0);
		return CKBR_OK;
	}


	/* Loop In :  */
	if( beh->IsInputActive(1)  ) 
	{ 
		 beh->ActivateInput(1,FALSE);


		 CGBLCI *currentCI = NULL;
		 //ctx->OutputToConsole("asfasdf");

		 if (getFromDB)
		 {
			 CKDataArray * resultArray = NULL;
			 beh->GetLocalParameterValue(BEH_LOCAL_PAR_INDEX_CIID_LIST,&resultArray);
			 if (resultArray)
			 {
				 CGBLSMStorageManager *storageManager = static_cast<CGBLSMStorageManager *>(ctx->GetManagerByGuid(GBLSMStorageManagerGUID));
				 IGBLSMConfigurationAccess* smCIS = storageManager->GetConfigurationInterface();

				 CGBLCIConfigurationController* cman=static_cast<CGBLCIConfigurationController*>(ctx->GetManagerByGuid(CONFIGURATION_MAN_GUID));
				 IGBLCIAccessInterface * accessInterface  = cman->GetCISAccessInterface(); 
				 
				 currentCI = new CGBLCI("temp",CKPGUID_INT);
                 
				 int idCI;
				 resultArray->GetElementValue(index,0,&idCI);
				 accessInterface->GetCI(currentCI,idCI);
				 beh->SetOutputParameterValue(BEH_OUT_PAR_INDEX_DB_INDEX,&idCI);

			 }else
			 {
				 ctx->OutputToConsole("wrong array");
			 }
		 }else
		 {
			 Customisation::typedefs::CISIterator it = cman->GetCIS()->GetIteratorByIndex(index);
			 currentCI = (CGBLCI *)*it;
		 }
        if (currentCI)
        {
			//output name : 
			CKParameterOut *outName = beh->GetOutputParameter(BEH_OUT_PAR_INDEX_UNAME);
			outName->SetStringValue(currentCI->name.Str());
			
			//output description:
			CKParameterOut *outDescr = beh->GetOutputParameter(BEH_OUT_PAR_INDEX_DESCRIPTION);
			outDescr->SetStringValue(currentCI->description.Str());
			
			//output type 
			int type = ctx->GetParameterManager()->ParameterGuidToType(currentCI->type);
			beh->SetOutputParameterValue(BEH_OUT_PAR_INDEX_TYPE,&type);
			
			//output  value: 
			CKParameterOut *outStrValue = beh->GetOutputParameter(BEH_OUT_PAR_INDEX_VALUE);
			outStrValue->SetStringValue(GetParameterAsString(currentCI->realValue));

			//output default value: 
			CKParameterOut *outDefaultStrValue = beh->GetOutputParameter(BEH_OUT_PAR_INDEX_DEFAULTVALUE);
			outDefaultStrValue->SetStringValue(GetParameterAsString(currentCI->defaultValue));
                            
			//output flags : 
			beh->SetOutputParameterValue(BEH_OUT_PAR_INDEX_FLAGS,&currentCI->flags);

		}else
		{            
			Logger::ShowDebugMessage(ctx,Logger::ELOGERROR,"CISIterator : couldn't find CI Parameter");	
		}

		//increase counter :
		index++;
		beh->SetLocalParameterValue(BEH_LOCAL_PAR_INDEX_INDEX,&index);
		beh->ActivateOutput(1);
	}
	return CKBR_OK;
}
示例#4
0
/*
 *******************************************************************
 * Function: int BehaviourFunction( const CKBehaviorContext& behaviorContext )
 *
 * Description : The execution function is the function that will be called 
 *               during the process loop of the behavior engine, if the behavior 
 *               is defined as using an execution function. This function is not 
 *               called if the behavior is defined as a graph. This function is the 
 *               heart of the behavior: it should compute the essence of the behavior, 
 *               in an incremental way. The minimum amount of computing should be 
 *               done at each call, to leave time for the other behaviors to run. 
 *               The function receives the delay in milliseconds that has elapsed 
 *               since the last behavioral process, and should rely on this value to 
 *               manage the amount of effect it has on its computation, if the effect 
 *               of this computation relies on time.
 *
 * Paramters :
 *    behaviourContext    r   Behavior context reference, which gives access to 
 *                            frequently used global objects ( context, level, manager, etc... )
 *
 * Returns : int, If it is done, it should return CKBR_OK. If it returns 
 *                CKBR_ACTIVATENEXTFRAME, the behavior will again be called 
 *                during the next process loop.
 *
 *******************************************************************
 */
int CGBLLAEGetLAE::BehaviourFunction( const CKBehaviorContext& behaviorContext )
{
	CKBehavior* beh = behaviorContext.Behavior;
  	CKContext* ctx = behaviorContext.Context;


	IGBLSMProfileAccess* pin = NULL;
    CGBLSMStorageManager *storageManager = (CGBLSMStorageManager *)ctx->GetManagerByGuid(GBLSMStorageManagerGUID);
	IGBLSMLAAccess *laInterface = storageManager->GetLAInterface();
	IGBLSMLAEAccess *laeInterface = storageManager->GetLAEInterface();

	char *laListArrayName = "laList";
	CKDataArray* laListArray;
	laListArray = (CKDataArray *)ctx->CreateObject(CKCID_DATAARRAY,laListArrayName, CK_OBJECTCREATION_DYNAMIC);
	behaviorContext.CurrentLevel->AddObject( laListArray );
	laListArray->InsertColumn( -1, CKARRAYTYPE_INT,	 "LAID" );

	char *laeArrayName = "laeidList";
	CKDataArray* laeArray;
	laeArray = (CKDataArray *)ctx->CreateObject(CKCID_DATAARRAY,laeArrayName, CK_OBJECTCREATION_DYNAMIC);
	behaviorContext.CurrentLevel->AddObject( laeArray );
	laeArray->InsertColumn( -1, CKARRAYTYPE_INT,	 "LAEID" );


	char *laelaArrayName = "laelaIDList";
	CKDataArray* laelaArray;
	laelaArray = (CKDataArray *)ctx->GetObjectByNameAndClass(laelaArrayName,CKCID_DATAARRAY,NULL);

	if ( !laelaArray )
	{
		laelaArray = (CKDataArray *)ctx->CreateObject(CKCID_DATAARRAY,laelaArrayName, CK_OBJECTCREATION_DYNAMIC);
		behaviorContext.CurrentLevel->AddObject( laelaArray );
	
		laelaArray->InsertColumn( -1, CKARRAYTYPE_INT,	 "LAEID" );
		laelaArray->InsertColumn( -1, CKARRAYTYPE_STRING,	 "LAID" );
	}
	else
	{
		laelaArray->Clear();
	}

	CGBLCOError res = laInterface->RetrieveLAList(laListArray);

	if ( res == CGBLCOError::EGBLCOErrorType::GBLCO_OK)
	{
		int count = laListArray->GetRowCount();
		for (int i=0; i < count; i++)
		{
			//get list of laes for given la and add it to results list

			XString xLAID;

			CKSTRING valueField = NULL;
			int labelLength =  laListArray->GetElementStringValue(i, 0, NULL);
			valueField = new CKCHAR[labelLength];
			labelLength =  laListArray->GetElementStringValue(i, 0, valueField);
			xLAID = valueField;
			delete valueField;


			CGBLLAID laid; 
			laid.FromString(xLAID);

			CGBLCOError res = laeInterface->RetrieveLAEList(laeArray,laid);
			if ( res == CGBLCOError::EGBLCOErrorType::GBLCO_OK)
			{
				int count = laeArray->GetRowCount();
				for (int j=0; j < count; j++)
				{
					CKSTRING valueField = NULL;
					int labelLength =  laeArray->GetElementStringValue(j, 0, NULL);
					valueField = new CKCHAR[labelLength];

					labelLength =  laeArray->GetElementStringValue(j, 0, valueField);

					laelaArray->AddRow();
					laelaArray->SetElementStringValue(laelaArray->GetRowCount()-1, 0, valueField);
					laelaArray->SetElementStringValue(laelaArray->GetRowCount()-1, 1, xLAID.Str());

					delete valueField;
				}
			}
		}
		beh->ActivateInput(0, FALSE);
		beh->SetOutputParameterObject(0, laelaArray);
		beh->ActivateOutput(0);
	}
	else
	{
		
		beh->ActivateInput(0, FALSE);
		CKParameterOut *parameterOutError = beh->GetOutputParameter(1);
		TGBLError::SetTGBLError(parameterOutError,CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL,GBLLAE_ERROR_GETLISTOFLAIDS,GBLLAE_ERROR_GETLISTOFLAIDS_DESC);
		beh->ActivateOutput(1);
	}

	behaviorContext.CurrentLevel->RemoveObject(laListArray);
	ctx->DestroyObject(laListArray);
	behaviorContext.CurrentLevel->RemoveObject(laeArray);
	ctx->DestroyObject(laeArray);
    return CKBR_OK;
}
示例#5
0
/*
 *******************************************************************
 * Function: int BehaviourFunction( const CKBehaviorContext& behaviorContext )
 *
 * Description : The execution function is the function that will be called 
 *               during the process loop of the behavior engine, if the behavior 
 *               is defined as using an execution function. This function is not 
 *               called if the behavior is defined as a graph. This function is the 
 *               heart of the behavior: it should compute the essence of the behavior, 
 *               in an incremental way. The minimum amount of computing should be 
 *               done at each call, to leave time for the other behaviors to run. 
 *               The function receives the delay in milliseconds that has elapsed 
 *               since the last behavioral process, and should rely on this value to 
 *               manage the amount of effect it has on its computation, if the effect 
 *               of this computation relies on time.
 *
 * Parameters :
 *    behaviourContext    r   Behavior context reference, which gives access to 
 *                            frequently used global objects ( context, level, manager, etc... )
 *
 * Returns : int, If it is done, it should return CKBR_OK. If it returns 
 *                CKBR_ACTIVATENEXTFRAME, the behavior will again be called 
 *                during the next process loop.
 *
 *******************************************************************
 */
int GBLPFGetPlayers::BehaviourFunction( const CKBehaviorContext& behaviorContext )
{
    CKBehavior *behaviour=behaviorContext.Behavior;
    CKContext *context = behaviorContext.Context;
    CGBLCOError returnValue;

    behaviour->ActivateInput(EGBLGetPlayersBehInputs::In, false);

    
    //initialise data array
    CKDataArray* FieldData = (CKDataArray*)context->CreateObject(CKCID_DATAARRAY, "FieldData", CK_OBJECTCREATION_DYNAMIC);
    
    
    CKDataArray *PlayerList;
    PlayerList = (CKDataArray*)behaviour->GetInputParameterObject(EGBLGetPlayersParamInputs::GetPlayerList);

    if(PlayerList == NULL)
    {
        behaviour->ActivateOutput(EGBLGetPlayersBehOutputs::Error, true);
        CKParameterOut *pOut = behaviour->GetOutputParameter(EGBLGetPlayersParamOutputs::ErrorCode);
        CGBLCOError::EGBLCOErrorType tType;
        tType= CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL;
        TGBLError::SetTGBLError(pOut, tType , 19021, "Missing or incorrect parameter provided");
    }
    else
    {
        CGBLProfileManager *pm = (CGBLProfileManager *)context->GetManagerByGuid(GBLProfileManagerGUID);
        returnValue = pm->GetPlayers(PlayerList);
        
        if ((int)returnValue == CGBLCOError::EGBLCOErrorType::GBLCO_OK)
        {
            behaviour->ActivateOutput(EGBLGetPlayersBehOutputs::Success, true);
        }
        else
        {
            CKParameterOut *pOut = behaviour->GetOutputParameter(EGBLGetPlayersParamOutputs::ErrorCode);
            CGBLCOError::EGBLCOErrorType tType = CGBLCOError::EGBLCOErrorType::GBLCO_OK ;
            switch((CGBLCOError::EGBLCOErrorType)returnValue)
            {
            case 0:
                tType = CGBLCOError::EGBLCOErrorType::GBLCO_OK;
                break;
            case 1:
                tType = CGBLCOError::EGBLCOErrorType::GBLCO_FATAL;
                break;
            case 2:
                tType = CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL;
                break;
            case 3:
                tType = CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL;
                break;
            }
            
            
			const char*errorString = returnValue;
            TGBLError::SetTGBLError(pOut, tType,returnValue, (CKSTRING)errorString);
            behaviour->ActivateOutput(EGBLGetPlayersBehOutputs::Error, true);
        }
    }


    return CKBR_OK;
}