Esempio n. 1
0
enum Process::ProcessResult AttackProc::Update(unsigned long aElapsedTime)
{
	mProgress += int(100*double(aElapsedTime)/mTimeScale);
	mProgress = std::min(mProgress,100);

	std::cout << p_gGame->GetActorName(mAttacker);
	for (int i = 0; i < mProgress; ++i)
	{
		std::cout << ".";
	}
	for (int i = mProgress; i < 100; ++i)
	{
		std::cout << " ";
	}
	std::cout << p_gGame->GetActorName(mTarget);
	std::cout << std::endl;

	std::this_thread::sleep_for(std::chrono::milliseconds(1000));

	if (mProgress == 100)
	{
		StrongActorPtr attacker = p_gGame->GetActor(mAttacker);
		StrongActorPtr target = p_gGame->GetActor(mTarget);
		this->Attack(attacker,target);
		attacker->GET_COMPONENT(BattleTimer)->ResetBattleTimer();
		attacker->GET_COMPONENT(BattleTimer)->SetActorState(BattleTimerState::ATTACKING, false);
		target->GET_COMPONENT(BattleTimer)->SetActorState(BattleTimerState::BEING_ATTACKED,false);
		return SUCCESS;
	}


	return STALL;
}
Esempio n. 2
0
AttackProc::~AttackProc()
{
	//Set target to busy so they can not mutally attack
	StrongActorPtr attacker = p_gGame->GetActor(mAttacker);
	StrongActorPtr target = p_gGame->GetActor(mTarget);
	attacker->GET_COMPONENT(BattleTimer)->SetActorState(BattleTimerState::ATTACKING, false);
	target->GET_COMPONENT(BattleTimer)->SetActorState(BattleTimerState::BEING_ATTACKED, false);
}
Esempio n. 3
0
const Vec3* ActorManager::GetActorPosition(ActorId id) {
	ActorsMap::iterator i = m_ActorMap.find(id);
	if (i != m_ActorMap.end()) {
		StrongActorPtr actor = ((*i).second);
		return &(actor->GetPosition());// Warning here return local or temp address
	}
	return NULL;
}
//
// GetActorXmlSize						- Chapter 22, page 757
//
int GetActorXmlSize ( ActorId actorId )
{
	StrongActorPtr pActor = MakeStrongPtr(g_pApp->m_pGame->VGetActor(actorId));
	if ( !pActor )
	{
		return 0;
	}
	std::string xml = pActor->ToXML();
	return xml.length();
}
Esempio n. 5
0
const StrongActorPtr ActorManager::GetActorByName(unsigned int ip, std::string actorName) {
	std::list<StrongActorPtr> actorList = m_ActorsByIpMap[ip];
//
	for (std::list<StrongActorPtr>::iterator i = actorList.begin(); i != actorList.end(); ++i) {
		StrongActorPtr pActor = *i;
		if (pActor->GetName().compare(actorName)==0) {
			return pActor;
		}
	}
	return NULL;
}
Esempio n. 6
0
void HydrusConsoleView::ActorReadyDelegate(EventData* aEventData)
{
	EventData_ActorReady* eventData = static_cast<EventData_ActorReady*> (aEventData);
	ActorId actorId = eventData->GetActorId();
	HydrusEncounter* encounter = eventData->GetEncounter();

	StrongActorPtr actor = p_gGame->GetActor(actorId);
	Brain* actorBrain = actor->GET_COMPONENT(Brain);
	actorBrain->DetermineAction(encounter);

}
Esempio n. 7
0
void RemoteNetworkView::UpdatePositionActor(IEventDataPtr pEventData) {
	std::shared_ptr<EventData_MoveActor> pCastEventData = std::static_pointer_cast<EventData_MoveActor>(pEventData);
	std::string name = pCastEventData->VGetActorName();
	unsigned int ip = pCastEventData->VGetIp();
	Vec3 newPosition = pCastEventData->VGetPosition();
	//look for actor data in actor manager by ip / actor name
	StrongActorPtr pActor = m_ActorManager->GetActorByName(ip, name);
	if (pActor != NULL) {
		pActor->SetPosition(newPosition);
	}
}
//
// GetActorXml							- Chapter 22, page 758
//
void GetActorXml ( int *actorXMLAddress, ActorId actorId )
{
	StrongActorPtr pActor = MakeStrongPtr(g_pApp->m_pGame->VGetActor(actorId));
	if ( !pActor )
	{
		return;
	}
	std::string xml = pActor->ToXML();
	
	strncpy_s(reinterpret_cast<char *>(actorXMLAddress), xml.length()+1, xml.c_str(), xml.length());
}
//
// CreateActor							- Chapter 22, page 761
//
int CreateActor( BSTR bstrActorXMLFile )
{
	std::string actorResource = ws2s(std::wstring(bstrActorXMLFile, SysStringLen(bstrActorXMLFile))); 
	StrongActorPtr pActor = g_pApp->m_pGame->VCreateActor(actorResource, NULL);
	if (!pActor)
		return INVALID_ACTOR_ID;

	// fire an event letting everyone else know that we created a new actor
	shared_ptr<EvtData_New_Actor> pNewActorEvent(GCC_NEW EvtData_New_Actor(pActor->GetId()));
	IEventManager::Get()->VQueueEvent(pNewActorEvent);
	return pActor->GetId();
}
Esempio n. 10
0
void RemoteNetworkView::GetActor(IEventDataPtr pEventData) {
	char response[4];
	std::string httpinmsg;
	IEventDataPtr pResponseHttpEvent(CREATE_EVENT(EventData_ResponseHTTP::sk_EventType));

	std::shared_ptr<EventData_GetActor> pCastEventData = std::static_pointer_cast<EventData_GetActor>(pEventData);
	std::string name = pCastEventData->VGetActorName();
	unsigned int ip = pCastEventData->VGetIp();
	pResponseHttpEvent->VSetSocketId(pEventData->VGetSocketId());
	pResponseHttpEvent->VSetIp(ip);
	//look for actor data in actor manager by ip / actor name
	StrongActorPtr pActor = m_ActorManager->GetActorByName(ip, name);

	if (pActor == NULL) {
		_itoa_s(http_response_code_t::NOTFOUND, response,10);
		httpinmsg.append(response);
		std::istrstream in(httpinmsg.c_str(),httpinmsg.size());
		pResponseHttpEvent->VDeserialize(in);
		IEventManager::Get()->VTriggerEvent(pResponseHttpEvent);
	}
	else {
		// Better (de-)serialize Actor with streams
		std::string buffer;
		_itoa_s(http_response_code_t::OK, response, 10);
		buffer.append(response);
		buffer.append(" ");

		char* id = new char[10];
		sprintf_s(id, 10, "%d", pActor->GetId());
		buffer.append(id);
		buffer.append("#");
		buffer.append(pActor->GetName());
		buffer.append("#");
		Vec3 position = pActor->GetPosition();
		char *xpos = new char[10];
		sprintf_s(xpos, 10, "%.3f", position.x);
		buffer.append(xpos);
		buffer.append("#");
		char *ypos = new char[10];
		sprintf_s(ypos, 10, "%.3f", position.y);
		buffer.append(ypos);
		buffer.append("#");
		char *zpos = new char[10];
		sprintf_s(zpos, 10, "%.3f", position.z);
		buffer.append(zpos);	
		buffer.push_back('\0');
		// when found, send answer	
		std::istrstream in(buffer.c_str(), buffer.size());
		pResponseHttpEvent->VDeserialize(in);
		IEventManager::Get()->VTriggerEvent(pResponseHttpEvent);
	}
}
Esempio n. 11
0
void ActorManager::RemoveActor(ActorId id) {
	m_ActorMap.erase(id);
	//
	StrongActorPtr actor = GetActor(id);
	std::list<StrongActorPtr> actorList = m_ActorsByIpMap[actor->GetIp()];
	for (std::list<StrongActorPtr>::iterator i = actorList.begin(); i != actorList.end(); ++i) {
		StrongActorPtr pActor = *i;
		if (pActor->GetName().compare(actor->GetName()) == 0) {
			actorList.erase(i);			
			//we break the iterator but we leave ah ah.
			break;
		}
	}
}
Esempio n. 12
0
void HydrusConsoleView::TargetingDelegate(EventData* aEventData)
{
	EventData_Targeting* eventData = static_cast<EventData_Targeting*> (aEventData);
	ActorId actorId = eventData->GetActorId();
	HydrusEncounter* encounter = eventData->GetEncounter();
	enum ActionType action = eventData->GetActionType();

	StrongActorPtr actor = p_gGame->GetActor(actorId);
	Brain* actorBrain = actor->GET_COMPONENT(Brain);

	ActorId attackTargetId = actorBrain->SelectTarget(actor->GetActorId(), encounter, action);

	encounter->CreateTargetedProc(actorId, attackTargetId, action);
}
Esempio n. 13
0
void AttackProc::Attack(StrongActorPtr aAttacker, StrongActorPtr aTarget)
{
	int attackerDamage = -1;
	int targetDamage = -10;

	HydrusActorStats* attackerStats = aAttacker->GET_COMPONENT(HydrusActorStats);
	HydrusActorStats* targetStats = aTarget->GET_COMPONENT(HydrusActorStats);

	tempAttackFunc(attackerStats, targetStats, attackerDamage, targetDamage);

	attackerStats->ModifyStats(attackerDamage,"health",aTarget->GetName(),COUNTER_ATTACK_DAMAGE);
	targetStats->ModifyStats(targetDamage,"health",aAttacker->GetName(),ATTACK_DAMAGE);

}
Esempio n. 14
0
AttackProc::AttackProc(ActorId aAttacker,
					   ActorId aTarget)
					   : Process(),
						 mAttacker(aAttacker),
					     mTarget(aTarget),
						 mTimeScale(2000),
						 mProgress(0)
{
	//Set target to busy so they can not mutally attack
	StrongActorPtr attacker = p_gGame->GetActor(mAttacker);
	StrongActorPtr target = p_gGame->GetActor(mTarget);
	attacker->GET_COMPONENT(BattleTimer)->SetActorState(BattleTimerState::ATTACKING, true);
	target->GET_COMPONENT(BattleTimer)->SetActorState(BattleTimerState::BEING_ATTACKED,true);
}
Esempio n. 15
0
 StrongActorPtr BaseGameLogic::createActor(const std::string& resource_name)
 {
   LOGI << "Creating a new actor from resource '" << resource_name << "'."
        << endl;
   ActorFactory& factory = ActorFactory::getInstance();
   StrongActorPtr actor = factory.createActor(resource_name);
   if (actor)
   {
     LOGI << "Created a new actor with id " << actor->getId() << "." << endl;
     actors_[actor->getId()] = actor;
     return actor;
   }
   else
   {
     LOGE << "Failed to create a new actor from resource '" << resource_name
          << "'." << endl;
     return StrongActorPtr();
   }
 }
Esempio n. 16
0
ActorId ActorManager::AddActor(StrongActorPtr pActor) {
	ActorId id;
	// if an actor already exists, do not create
	StrongActorPtr actorTest = GetActorByName(pActor->GetIp(),pActor->GetName());
	if (actorTest == NULL) {
		id = pActor->GetId();
		// No id affected yet
		if (id == -1) {
			id = GetNextLastId();
			pActor->SetId(id);
			m_ActorMap[id] = pActor;
			//alternative
			//m_ActorMap.insert(std::pair<ActorId, Actor>(id, actor));
			// add the actor for this Ip
			m_ActorsByIpMap[pActor->GetIp()].push_back(pActor);
		}
	}
	else {
		id = actorTest->GetId();
	}
	return id;
}
Esempio n. 17
0
//
// TeapotWarsLogic::VChangeState
//
void TeapotWarsLogic::VChangeState(BaseGameState newState)
{
	BaseGameLogic::VChangeState(newState);

	switch(newState)
	{
		case BGS_WaitingForPlayers:
		{

			// spawn all local players (should only be one, though we might support more in the future)
			GCC_ASSERT(m_ExpectedPlayers == 1);
			for (int i = 0; i < m_ExpectedPlayers; ++i)
			{
				shared_ptr<IGameView> playersView(GCC_NEW TeapotWarsHumanView(g_pApp->m_Renderer));
				VAddView(playersView);

				if (m_bProxy)
				{
					// if we are a remote player, all we have to do is spawn our view - the server will do the rest.
					return;
				}
			}

			// spawn all remote player's views on the game
			for (int i = 0; i < m_ExpectedRemotePlayers; ++i)
			{
				shared_ptr<IGameView> remoteGameView(GCC_NEW NetworkGameView);
				VAddView(remoteGameView);
			}

			// spawn all AI's views on the game
			for (int i = 0; i < m_ExpectedAI; ++i)
			{
				shared_ptr<IGameView> aiView(GCC_NEW AITeapotView(m_pPathingGraph));
				VAddView(aiView);
			}
			break;
		}


		case BGS_SpawningPlayersActors:
		{
			if (m_bProxy)
			{
				// only the server needs to do this.
				return;
			}

			for (auto it = m_gameViews.begin(); it != m_gameViews.end(); ++it)
			{
				shared_ptr<IGameView> pView = *it;
				if (pView->VGetType() == GameView_Human)
				{
					StrongActorPtr pActor = VCreateActor("actors\\player_teapot.xml", NULL);
					if (pActor)
					{
						shared_ptr<EvtData_New_Actor> pNewActorEvent(GCC_NEW EvtData_New_Actor(pActor->GetId(), pView->VGetId()));
                        IEventManager::Get()->VTriggerEvent(pNewActorEvent);  // [rez] This needs to happen asap because the constructor function for Lua (which is called in through VCreateActor()) queues an event that expects this event to have been handled
					}
				}
				else if (pView->VGetType() == GameView_Remote)
				{
					shared_ptr<NetworkGameView> pNetworkGameView = static_pointer_cast<NetworkGameView, IGameView>(pView);
					StrongActorPtr pActor = VCreateActor("actors\\remote_teapot.xml", NULL);
					if (pActor)
					{
						shared_ptr<EvtData_New_Actor> pNewActorEvent(GCC_NEW EvtData_New_Actor(pActor->GetId(), pNetworkGameView->VGetId()));
						IEventManager::Get()->VQueueEvent(pNewActorEvent);
					}
				}
				else if (pView->VGetType() == GameView_AI)
				{
					shared_ptr<AITeapotView> pAiView = static_pointer_cast<AITeapotView, IGameView>(pView);
					StrongActorPtr pActor = VCreateActor("actors\\ai_teapot.xml", NULL);
					if (pActor)
					{
						shared_ptr<EvtData_New_Actor> pNewActorEvent(GCC_NEW EvtData_New_Actor(pActor->GetId(), pAiView->VGetId()));
						IEventManager::Get()->VQueueEvent(pNewActorEvent);
					}
				}
			}

			break;
		}
	}
}