예제 #1
0
//Process possible events
bool BodyChainAgent::HandleEvent(const EventData& data)
{
	bool eventprocessed(false);

	if(!mActive)
		return false;

	//IF - A Monkey attached
	if(data.GetEventType() == Event_MonkeyAttached)
	{
		const MonkeyAttachedEvent& eventdata (static_cast<const MonkeyAttachedEvent&>(data));
		
		//IF - Attached to this agent
		if(eventdata.GetAgentId() == mId)
		{
			//Find branch (bodychain)
			BodyChain::BodyChainListIterator itr;
			std::string bodychainid (eventdata.GetBodyChainId());
			//LOOP - Find the affected bodychain list
			for(itr = mParams.bodychainlist.begin();itr != mParams.bodychainlist.end();++itr)
			{
				//IF - Found
				if((*itr)->GetId() == bodychainid)
				{
					(*itr)->IncrementAttached();
				}//IF
			}//LOOP
		}//IF

	}//ELSE - A Monkey detached
	else if(data.GetEventType() == Event_MonkeyDetached)
	{
		const MonkeyDetachedEvent& eventdata (static_cast<const MonkeyDetachedEvent&>(data));
		
		//IF - Attached to this agent
		if(eventdata.GetAgentId() == mId)
		{
			//Find branch (bodychain)
			BodyChain::BodyChainListIterator itr;
			std::string bodychainid (eventdata.GetBodyChainId());
			//LOOP - Find the affected bodychain list
			for(itr = mParams.bodychainlist.begin();itr != mParams.bodychainlist.end();++itr)
			{
				//IF - Found
				if((*itr)->GetId() == bodychainid)
				{
					(*itr)->DecrementAttached();
				}//IF
			}//LOOP
		}//IF
	}//IF

	return eventprocessed;
}
예제 #2
0
//Process possible events
bool CollectableAgent::HandleEvent(const EventData& data)
{
	bool eventprocessed = false;
	
	//Collectable receives event of being collected
	//IF - "Drop Collected event"
	if(data.GetEventType() == Event_DropCollision)
	{
		//Check if this was collected
		const DropCollidedEvent& theevent = static_cast<const DropCollidedEvent&>(data);
		//IF - Pointers match
		if(theevent.GetCollectedAgent() == this && !mCollected)
		{
			//Drop collected!
			//Destroy body
			mPhysicsManager->DestroyBody(mParams.physicbody);
			mCollected = true; //Memorize collected
			//Send event as drop was collected
			SingletonGameEventMgr::Instance()->QueueEvent(
												EventDataPointer(new EventData(Event_DropCollected))
											);
		}	
	}//IF
	
	return eventprocessed;
}
//Events plugin
bool StateMachine_MadMonkey::HandleEvent(const EventData& data)			
{
	bool eventprocessed(false);

	//IF - Exists state
	if(mCurrentState)
	{
		//Process overall state change

		//IF - A branch broke
		if(data.GetEventType() == Event_BranchBroke)
		{
			const BranchBrokeEvent& eventdata (static_cast<const BranchBrokeEvent&>(data));

			//IF - The target was this branch
			if(mTargetBodyChainId == eventdata.GetBodyChainId()
			   &&
			   mTargetAgentId == eventdata.GetAgentId())
			{
				//Reset state to search, as this branch is broken to hang
				mActor->ChangeState("Search");

				//Detach from Point 
				mActor->DetachFromPoint();
			}//IF 
		}
		
		//Forward event to current state
		return(eventprocessed || mCurrentState->HandleEvent(data));
	}

	//No state defined
	return eventprocessed;
}
예제 #4
0
//Event handling
bool AntiVirusLogic::HandleEvents(const EventData& theevent)
{
    bool eventprocessed(false);

    //IF - Target position changed
    if(theevent.GetEventType() == Event_AgentPosition)
    {
        const AgentPositionEvent& eventdata (static_cast<const AgentPositionEvent&>(theevent));
        if(eventdata.GetAgentId() == mTargetId)
        {
            mTargetPosition = eventdata.GetPosition();
        }
    }//IF - New target received
    else if (theevent.GetEventType() ==  Event_NewAntiVirusTarget)
    {
        const NewAntiVirusTargetEvent& eventdata (static_cast<const NewAntiVirusTargetEvent&>(theevent));
        mTargetId = eventdata.GetAgentId();
        mTargetPosition = eventdata.GetPosition();
        mTrackingPlayer = eventdata.IsPlayer();
        mCounter = mScanTime;
        mTarget = true;
    }//ELSE - New virus created!
    else if (theevent.GetEventType() == Event_NewAgentCreated)
    {
        const NewAgentCreatedEvent& eventdata (static_cast<const NewAgentCreatedEvent&>(theevent));

        //IF - It is a virus and we are tracking the player
        if(mTrackingPlayer
                &&
                eventdata.GetAgentType() == AI
                &&
                eventdata.GetAgentAI() == "SpawnVirus")
        {
            //F**k! Go to next virus!
            mTarget = false;
        }
    }
    return eventprocessed;
}
예제 #5
0
//Process possible events
bool MainGameScreen::HandleEvent(const EventData& theevent)
{
	bool eventprocessed(false);

	//IF - Event type is exit
	if(theevent.GetEventType() == Event_ExitGame)
	{
		//Just store request to exit on update
		mExit = true;
	}//IF

	return eventprocessed;
}
//Events plugin
bool State_MadMonkey_Search::HandleEvent(const EventData& data)
{
	bool eventprocessed(false);

	//Receive a new target from game\
	//IF - New AI target event
	if(data.GetEventType() == Event_NewAITarget)
	{
		const NewAITargetEvent& eventdata (static_cast<const NewAITargetEvent&>(data));
		//IF- Target is for ME!
		if(eventdata.GetAIAgentName() == mActor->GetId())
		{
			mTargetBody = eventdata.GetTargetBody();
			mTargetId = eventdata.GetAgentName();
			mTargetBodyChainId = eventdata.GetBodyChainId();
			mTargetFound = true;
			eventprocessed = true;
		}//IF
	}//IF

	return eventprocessed;
}