/*
 *******************************************************************
 * 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 CGBLLAETriggerSaving::BehaviourFunction( const CKBehaviorContext& behaviorContext )
{
	CKBehavior* beh = behaviorContext.Behavior;
  	CKContext* ctx = behaviorContext.Context;

	CGBLLAEManager *laeManager = (CGBLLAEManager *)ctx->GetManagerByGuid(GBLLAEManagerGUID);

	if (laeManager)
	{
		if ( beh->IsInputActive(0) )
		{
			laeManager->HandleSave ( ctx, beh->GetID() );
			beh->ActivateInput(0, FALSE);
			return CKBR_ACTIVATENEXTFRAME;
		}
	}
	return CKBR_BEHAVIORERROR;
   
}
Exemple #2
0
int CallPythonFunc2(const CKBehaviorContext& behcontext)
{
	CKBehavior* beh = behcontext.Behavior;
	CKContext* ctx = behcontext.Context;


	XString File((CKSTRING) beh->GetInputParameterReadDataPtr(0));
	XString Func((CKSTRING) beh->GetInputParameterReadDataPtr(1));
	int reload=false;  //= BehaviorTools::GetInputParameterValue<bool>(beh,2);
	
	beh->GetInputParameterValue(2,&reload);

	vt_python_man *pm = (vt_python_man*)ctx->GetManagerByGuid(INIT_MAN_GUID);
	CKParameterManager *pam = static_cast<CKParameterManager *>(ctx->GetParameterManager());

	Python *py = pm->py;
    
	if (!pm->pLoaded)
	{
		pm->m_Context->OutputToConsoleEx("You must load Python before !");
		beh->ActivateOutput(1,false);
		return CKBR_BEHAVIORERROR;

	}


	//////////////////////////////////////////////////////////////////////////
	if( beh->IsInputActive(0) )
	{
		try 
		{
			PyObject *module = pm->InsertPModule(beh->GetID(),File,reload);
			PyObject* val = PyInt_FromLong(beh->GetID());
			PyObject_SetAttrString( module , "bid", val);
            pm->CallPyModule(beh->GetID(),Func);
		
		}
		catch (Python_exception ex)
		{
			pm->m_Context->OutputToConsoleEx("PyErr : \t %s",(CKSTRING)ex.what());
			std::cout << ex.what() << "pyexeption in beh : " << beh->GetName();
			PyErr_Clear();
			beh->ActivateOutput(1,false);
		}
		beh->ActivateInput(0,false);

	}
	//////////////////////////////////////////////////////////////////////////
	else
	{
		for (int i  = 1 ; i < beh->GetOutputCount() ; i++ )
		{
			
			try 
			{
				PyObject *module = pm->GetPModule(beh->GetID());
				if(module)
					pm->CallPyModule(beh->GetID(),Func);
			}
			catch (Python_exception ex)
			{
				pm->m_Context->OutputToConsoleEx("PyErr : \t %s",(CKSTRING)ex.what());
				std::cout << ex.what() << "pyexeption in beh : " << beh->GetName();
				beh->ActivateOutput(1,TRUE);
				return CKBR_BEHAVIORERROR;
			}
			beh->ActivateInput(i,false);
		}

	}
	
	return CKBR_OK;

}
/*
*******************************************************************
* Function: int CGBLBuildCommand::DoBuildCommand(const CKBehaviorContext& behaviorContext)
*
* Description : Starts building the command. Find required GBLWaitForCommand BB,
*				determine its target (GBLTarget) and take corresponded actions.
*
* Parameters :
*    behaviourContext    r   Behavior context reference, which gives 
*                            access to frequently used global objects 
*                            ( context, level, manager, etc... )
*
*******************************************************************
*/
int CGBLBuildCommand::DoBuildCommand(const CKBehaviorContext& behaviorContext)
{
	CKBehavior* behavior = behaviorContext.Behavior;
  	CKContext* context = behaviorContext.Context;

	//set to initial state
	int stateValue = EGBLBuildCommandState::Initial;
	behavior->SetLocalParameterValue (gblBuildCommandStateLocalPos, &stateValue);

	int initialParameterPosition = 0;
	behavior->SetLocalParameterValue (currentParameterPositionLocalPos, &initialParameterPosition);

	char *emptyString = "";
	behavior->SetLocalParameterValue(commandStringLocalPos, emptyString, strlen(emptyString)+1);

	ClearParameterOutputs(behaviorContext);


	int targetID = 0;
	behavior->GetInputParameterValue (EGBLBuildCommandParamInputs::SetCommandID, &targetID);


	CKBehavior* targetBB = CGBLCommandUtil::GetTargetCommand (targetID, behaviorContext);

	if (targetBB == NULL)
	{
		CKParameterOut *parameterOutError = behavior->GetOutputParameter(EGBLBuildCommandParamOutputs::GetError);
		TGBLError::SetTGBLError(parameterOutError,CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL,GBLFC_ERROR_BUILDCOMMAND_TARGET_NOT_FOUND,GBLFC_ERROR_BUILDCOMMAND_TARGET_NOT_FOUND_DESC);

		behavior->ActivateOutput (EGBLBuildCommandBehOutputs::Error);
		return CKBR_OK;
	}
	CK_ID targetBBID = targetBB->GetID();
	behavior->SetLocalParameterValue (targetBBLocalPos, &targetBBID);

	int gblTatgetType = -1;
	targetBB->GetLocalParameterValue (CGBLWaitForCommand::EGBLWaitForCommandLocalVariables::EGBLFCTarget, &gblTatgetType);

	switch (gblTatgetType)
	{
	case CGBLWaitForCommand::EGBLFCTarget::Untargeted:
		{
			XString commandString;
			commandString << targetID << CGBLCommandUtil::commandSeparator;

			behavior->SetLocalParameterValue(commandStringLocalPos, commandString.Str(), strlen(commandString.Str()) + 1 );

			return DoHandleNextLocalArgument (behaviorContext);
		}
		break;

		case CGBLWaitForCommand::EGBLFCTarget::Player:
		case CGBLWaitForCommand::EGBLFCTarget::Team:
		{
			//set state to GetTargets
			int stateValue = EGBLBuildCommandState::GetTargets;
			behavior->SetLocalParameterValue (gblBuildCommandStateLocalPos,&stateValue);

			//get list of recipients
			behavior->SetOutputParameterValue (EGBLBuildCommandParamOutputs::GetTarget, &gblTatgetType); 
			behavior->ActivateOutput (EGBLBuildCommandBehOutputs::ListRecipients);
			return CKBR_OK;
		}
		break;

		default:
			CKParameterOut *parameterOutError = behavior->GetOutputParameter(EGBLBuildCommandParamOutputs::GetError);
			TGBLError::SetTGBLError(parameterOutError,CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL,GBLFC_ERROR_BUILDCOMMAND_UNSPECIFIED_RECIPIENT,GBLFC_ERROR_BUILDCOMMAND_UNSPECIFIED_RECIPIENT_DESC);

			behavior->ActivateOutput (EGBLBuildCommandBehOutputs::Error);
		break;
	}
	return CKBR_OK;
}