Beispiel #1
0
void CMPTutorial::OnShowBuyMenuPage(int page)
{
	if(page == CHUDPowerStruggle::E_AMMO)
		TriggerEvent(eTE_BuyAmmo);
	else if(page == CHUDPowerStruggle::E_PROTOTYPES)
		TriggerEvent(eTE_PrototypeBuyMenu);
}
void AnimatedWarrior_cl::UpdateUpperBodyFade()
{
  if (m_eUpperBodyFadeState == FADESTATE_NONE)
    return;

  VASSERT(m_iPrimaryUpperBodyControlIndex>=0);

  if (m_eUpperBodyFadeState == FADESTATE_FADEIN)
  {
    // test for finished easing in
    if (!m_spLayerMixer->IsEasingIn(m_iPrimaryUpperBodyControlIndex+1))
    {
      VASSERT(m_spLayerMixer->GetCurrentEaseValue(m_iPrimaryUpperBodyControlIndex+1) >= 1.f);
      m_eUpperBodyFadeState = FADESTATE_NONE;
      TriggerEvent(EVENT_UPPERBODYFADEIN_FINISHED);
    }
  }
  else if(m_eUpperBodyFadeState == FADESTATE_FADEOUT)
  {
    // test for finished easing out
    if (!m_spLayerMixer->IsEasingOut(m_iPrimaryUpperBodyControlIndex+1))
    {
      VASSERT(m_spLayerMixer->GetCurrentEaseValue(m_iPrimaryUpperBodyControlIndex+1) <= 0.f);
      m_eUpperBodyFadeState = FADESTATE_NONE;
      m_iPrimaryUpperBodyControlIndex = -1;
      TriggerEvent(EVENT_UPPERBODYFADEOUT_FINISHED);
    }
  }
  else VASSERT(false);
}
Beispiel #3
0
void Player::Update()
{
	float value = 0.0f;
	if((value = game->input->GetAxis("Horizontal")) != 0.0f)
	{
		TriggerEvent("Move", game->scene->mainCamera->owner->transform->GetRight() * value);
	//	TriggerEvent("Move", owner->transform->GetRight() * value);
	}
	if((value = game->input->GetAxis("Vertical")) != 0.0f)
	{
		TriggerEvent("Move", game->scene->mainCamera->owner->transform->GetDirection() * value);
	//	TriggerEvent("Move", owner->transform->GetDirection() * value);
	}
	if((value = game->input->GetAxis("HRotation")) != 0.0f)
	{
		TriggerEventWithChildren("Look", vec3(0, 0, value));
	}
	if((value = game->input->GetAxis("VRotation")) != 0.0f)
	{
		TriggerEventWithChildren("Look", vec3(-value, 0, 0));
	}
	if((value = game->input->GetAxis("ZRotation")) != 0.0f)
	{
		TriggerEventWithChildren("Look", vec3(0, value, 0));
	}
	if (game->input->GetButtonDown("ShowLoc"))
	{
		Log("Player position: ", lexical_cast<string>(owner->transform->GetPosition()));
	}
	if (game->input->GetButtonDown("ShowRot"))
	{
		Log("Player rotation: ", lexical_cast<string>(owner->transform->GetRotation()));
		Log("Camera rotation: ", lexical_cast<string>(game->scene->mainCamera->owner->transform->GetRotation()));
		Log("Camera direction: ", lexical_cast<string>(game->scene->mainCamera->owner->transform->GetDirection()));
	//	Log("Camera right: ", lexical_cast<string>(game->scene->mainCamera->owner->transform->GetRight()));
	//	Log("Camera up: ", lexical_cast<string>(game->scene->mainCamera->owner->transform->GetUp()));
	//	Log("Camera matrix: ", lexical_cast<string>(game->scene->mainCamera->owner->transform->GetMatrix()));
	}
	if(game->input->GetButtonDown("ShowFPS"))
	{
		Log("deltaTime: ", game->time->deltaTime);
		Log("Game FPS: ", game->time->frameRate);
	}
	if (game->input->GetButtonDown("Quit"))
	{
		Log("Calling exit function");
	//	game->console->Input("quit");
		game->Exit();
	}
	if(game->input->GetButtonDown("Reload"))
	{
		inventory->TriggerEvent("Reload");
	}
}
bool CSocket::DoPulse()
{
    // Make sure the socket exists before taking action
    if (m_pSocket != ERR_INVALID_SOCKET)
    {
        // Wait for connect to complete before proceeding
        if (!m_bConnected)
        {
            struct timeval tv = { 0, 0 };
            fd_set wfds;
            FD_ZERO(&wfds);
            FD_SET(m_pSocket, &wfds);
            // See if socket it writable
            int ret = select(m_pSocket+1, NULL, &wfds, NULL, &tv);
            if (ret == 0)
               return true;     // Not writable yet
            if (ret == -1)
               return false;    // select error
        }

        // Create a buffer for catching received data
        // (1 byte larger than receive limit, because another character has to be added)
        char chBuffer[SOCK_RECV_LIMIT + 1];

        // Receive the data
        int iLength = recv(m_pSocket, chBuffer, SOCK_RECV_LIMIT, 0);

        // Check if there were any errors
        int iError = GetLastSocketError();

        // Check if the socket just connected. If connection failed, return false
        if (!m_bConnected && (HandleConnection(iError) == ERR_CONNECT_FAILURE))
            return false;

        // If connected, handle data processing
        if (m_bConnected)
        {
            // Process data if there is any
            if (iLength > 0)
            {
                // Add a NULL at the end of the data, or the data will appear corrupted
                chBuffer[iLength] = '\0';

                TriggerEvent("onSockData",chBuffer);
            }
            else if (iError != ERR_NO_ERROR && iError != ERR_WOULD_BLOCK)
            {
                // An error has occured, so time to kill the socket
                m_bConnected = false;
                return false;
            }
        }
    }
    else
        // If the socket doesn't exist, well, error?
        return false;

    // If the call makes it up till here, it has been a huge success! Cake and true as a reward!
    return true;
}
Beispiel #5
0
bool CMPTutorial::CheckVehicles(const CPlayer* pPlayer)
{
	FUNCTION_PROFILER(GetISystem(), PROFILE_GAME);

	bool showPrompt = false;
	if(!pPlayer)
		return showPrompt;

	IVehicle* pVehicle = pPlayer->GetLinkedVehicle();

	if(m_wasInVehicle && !pVehicle)
	{
		// got out of vehicle. Move HUD box back to normal place.
		SAFE_HUD_FUNC(SetTutorialTextPosition(2));
		m_wasInVehicle = false;
		return showPrompt;
	}
 
 	if(pVehicle && !m_wasInVehicle)
 	{
		// just got in. Move HUD box up so it doesn't overlap vehicle hud.
		SAFE_HUD_FUNC(SetTutorialTextPosition(1));

		m_wasInVehicle = true;

		// generic 'boarding a vehicle' message
		TriggerEvent(eTE_BoardVehicle);
	}

	return showPrompt;
}
Beispiel #6
0
void Sequence::ProcessSequenceData(int checkControlChannels) {
	if (IsEffectRunning())
		OverlayEffects(m_seqData);

	if (UsingMemoryMapInput())
		OverlayMemoryMap(m_seqData);

	if (checkControlChannels && getControlMajor() && getControlMinor())
	{
		char thisMajor = NormalizeControlValue(m_seqData[getControlMajor()-1]);
		char thisMinor = NormalizeControlValue(m_seqData[getControlMinor()-1]);

		if ((m_seqLastControlMajor != thisMajor) ||
			(m_seqLastControlMinor != thisMinor))
		{
			m_seqLastControlMajor = thisMajor;
			m_seqLastControlMinor = thisMinor;

			if (m_seqLastControlMajor && m_seqLastControlMinor)
				TriggerEvent(m_seqLastControlMajor, m_seqLastControlMinor);
		}
	}

	if (channelTester->Testing())
		channelTester->OverlayTestData(m_seqData);
}
Beispiel #7
0
void Player::ProcessChannelData(void)
{
	if (IsEffectRunning())
		OverlayEffects(m_seqData);

	if (UsingMemoryMapInput())
		OverlayMemoryMap(m_seqData);

	if (getControlMajor() && getControlMinor())
	{
		char thisMajor = NormalizeControlValue(m_seqData[getControlMajor()-1]);
		char thisMinor = NormalizeControlValue(m_seqData[getControlMinor()-1]);

		if ((m_seqLastControlMajor != thisMajor) ||
			(m_seqLastControlMinor != thisMinor))
		{
			m_seqLastControlMajor = thisMajor;
			m_seqLastControlMinor = thisMinor;

			if (m_seqLastControlMajor && m_seqLastControlMinor)
				TriggerEvent(m_seqLastControlMajor, m_seqLastControlMinor);
		}
	}

	if (channelTester->Testing())
		channelTester->OverlayTestData(m_seqData);

	if (m_brightness)
		AdjustBrightness();
}
Beispiel #8
0
void Player::Jump(float value)
{
	if(value == 1)
	{
		Log("Jumping");
		TriggerEvent("Jump");
	}
}
void CSocket::CloseSocketWithEvent()
{
    // Close the socket, if it exists, and trigger the closed event
    if (m_pSocket != ERR_INVALID_SOCKET)
    {
        CloseSocket();
        TriggerEvent("onSockClosed");
    }
}
Beispiel #10
0
void Client::OnConnect(const boost::system::error_code& error, net::Connection* con)
{
	if (error)
	{
//		GetGame()->Log(error.message());
		return;
	}
	TriggerEvent("Connect", error.message());
	con->GetData();
}
Beispiel #11
0
void CMPTutorial::OnBuyItem(const char* itemname)
{
	if(m_events[eTE_ClaymoreOrMineBought].m_status == eMS_Checking)
	{
		if(!strcmp(itemname, "claymore") || !strcmp(itemname, "avmine"))
		{
			TriggerEvent(eTE_ClaymoreOrMineBought);
		}
	}
}
Beispiel #12
0
void ExtObject::CheckEndDrag(int button)
{
	// If the right kind of click
	if (button == mouseButton) {

		if (dragging)
			TriggerEvent(2);	// On Dropped

		dragging = false;
	}
}
bool AShooterPlayerController::SetPause(bool bPause, FCanUnpause CanUnpauseDelegate /*= FCanUnpause()*/)
{
	const bool Result = APlayerController::SetPause(bPause, CanUnpauseDelegate);

	// Update rich presence.
	const auto PresenceInterface = Online::GetPresenceInterface();
	const auto Events = Online::GetEventsInterface();
	if(PresenceInterface.IsValid() && PlayerState->UniqueId.IsValid())
	{
		FPresenceProperties Props;
		if(Result && bPause)
		{
			Props.Add(DefaultPresenceKey, FString("Paused"));
		}
		else
		{
			Props.Add(DefaultPresenceKey, FString("InGame"));
		}
		PresenceInterface->SetPresence(*PlayerState->UniqueId, Props);

	}

	if(Events.IsValid() && PlayerState->UniqueId.IsValid())
	{
		FOnlineEventParms Params;
		Params.Add( TEXT( "GameplayModeId" ), FVariantData( (int32)1 ) );
		Params.Add( TEXT( "DifficultyLevelId" ), FVariantData( (int32)0 ) );
		if(Result && bPause)
		{
			Events->TriggerEvent(*PlayerState->UniqueId, TEXT("PlayerSessionPause"), Params);
		}
		else
		{
			Events->TriggerEvent(*PlayerState->UniqueId, TEXT("PlayerSessionResume"), Params);
		}
	}

	return Result;
}
Beispiel #14
0
void CMPTutorial::OnMapOpen(bool open)
{
	if(!m_enabled)
		return;

	// hide any previous messages which are waiting for this event.
	if(open && m_currentEvent.m_msgRemovalCondition == eMRC_OpenMap)
	{
		if(!m_currentEvent.m_pCurrentSound.get())
			HideMessage();
		else
			m_currentEvent.m_msgRemovalCondition = eMRC_SoundFinished;
	}

	if(open)
	{
		TriggerEvent(eTE_OpenMap);
	}
	else
	{
		TriggerEvent(eTE_CloseMap);
	}
}
Beispiel #15
0
void CMPTutorial::OnEntityAddedToRadar(EntityId id)
{
	// if the entity is an enemy player, show the prompt.
	if(m_events[eTE_EnemySpotted].m_status != eMS_Checking)
		return;

	IEntity* pEntity = gEnv->pEntitySystem->GetEntity(id);
	if(pEntity && pEntity->GetClass() == m_pPlayerClass)
	{
		if(g_pGame->GetGameRules()->GetTeam(id) != g_pGame->GetGameRules()->GetTeam(g_pGame->GetIGameFramework()->GetClientActor()->GetEntityId()))
		{
			TriggerEvent(eTE_EnemySpotted);
		}
	}
}
void AShooterPlayerController::OnDeathMessage(class AShooterPlayerState* KillerPlayerState, class AShooterPlayerState* KilledPlayerState, const UDamageType* KillerDamageType) 
{
	AShooterHUD* ShooterHUD = GetShooterHUD();
	if (ShooterHUD)
	{
		ShooterHUD->ShowDeathMessage(KillerPlayerState, KilledPlayerState, KillerDamageType);		
	}

	ULocalPlayer* LocalPlayer = Cast<ULocalPlayer>(Player);
	if (LocalPlayer && LocalPlayer->GetUniqueNetId().IsValid() && KilledPlayerState->UniqueId.IsValid())
	{
		// if this controller is the player who died, update the hero stat.
		if (*LocalPlayer->GetUniqueNetId() == *KilledPlayerState->UniqueId)
		{
			const auto Events = Online::GetEventsInterface();
			const auto Identity = Online::GetIdentityInterface();

			if (Events.IsValid() && Identity.IsValid())
			{							
				int32 UserIndex = LocalPlayer->ControllerId;
				TSharedPtr<FUniqueNetId> UniqueID = Identity->GetUniquePlayerId(UserIndex);
				if (UniqueID.IsValid())
				{				
					ACharacter* Pawn = GetCharacter();
					check(Pawn);
					FVector Location = Pawn->GetActorLocation();

					FOnlineEventParms Params;
					Params.Add( TEXT( "SectionId" ), FVariantData( (int32)1 ) );
					Params.Add( TEXT( "GameplayModeId" ), FVariantData( (int32)1 ) );
					Params.Add( TEXT( "DifficultyLevelId" ), FVariantData( (int32)0 ) );

					Params.Add( TEXT( "PlayerRoleId" ), FVariantData( (int32)0 ) );
					Params.Add( TEXT( "PlayerWeaponId" ), FVariantData( (int32)0 ) );
					Params.Add( TEXT( "EnemyRoleId" ), FVariantData( (int32)0 ) );
					Params.Add( TEXT( "EnemyWeaponId" ), FVariantData( (int32)0 ) );	
				
					Params.Add( TEXT( "LocationX" ), FVariantData( Location.X ) );
					Params.Add( TEXT( "LocationY" ), FVariantData( Location.Y ) );
					Params.Add( TEXT( "LocationZ" ), FVariantData( Location.Z ) );
										
					Events->TriggerEvent(*UniqueID, TEXT("PlayerDeath"), Params);
				}
			}
		}
	}	
}
Beispiel #17
0
void CThread::Terminate()
{
	if (this->hThread) {
		terminate = 1;
		TriggerEvent();

		if (::WaitForSingleObject (this->hThread, this->Timeout) == WAIT_TIMEOUT)
		{
			DebugMsg("CThread","CThread: Forcing termination of thread %s 0x%X",name.c_str(),(int)hThreadId);
			//TerminateThread (this->hThread, 99);
		}

		CloseHandle (this->hThread);

		this->hThread = 0;
	}
}
Beispiel #18
0
void ResourceManager::Tick()
{
	for (auto& resource : m_resources)
	{
		resource.second->Tick();
	}

	//for (auto& qEvent : m_eventQueue)
	for (auto it = m_eventQueue.begin(); it < m_eventQueue.end(); it++) // as the queue's end may change during this iteration
	{
		auto& qEvent = *it;

		TriggerEvent(qEvent.eventName, qEvent.argsSerialized, qEvent.source);
	}

	m_eventQueue.clear();
}
Beispiel #19
0
TEST_F(INotifyTests, test_inotify_fire_event) {
  // Assume event type is registered.
  StartEventLoop();
  auto sub = std::make_shared<TestINotifyEventSubscriber>();
  sub->init();

  // Create a subscriptioning context, note the added Event to the symbol
  auto sc = sub->GetSubscription(kRealTestPath, 0);
  sub->subscribe(&TestINotifyEventSubscriber::SimpleCallback, sc, nullptr);

  TriggerEvent(kRealTestPath);
  sub->WaitForEvents(kMaxEventLatency);

  // Make sure our expected event fired (aka subscription callback was called).
  EXPECT_TRUE(sub->count() > 0);
  StopEventLoop();
}
int CSocket::HandleConnection(const int& iError)
{
    if (iError == ERR_NO_ERROR || iError == ERR_WOULD_BLOCK)
    {
        m_bConnected = true;
        TriggerEvent("onSockOpened");
        return 1;
    }
    else if (iError == ERR_NOT_CONNECTED)
    {
        return 0;
    }
    else
    {
        printf("Could not connect due to error: %i",iError); // TEMP DEBUG
        return -1;
    }
}
void AShooterPlayerController::OnKill()
{
	UpdateAchievementProgress(ACH_FRAG_SOMEONE, 100.0f);

	const auto Events = Online::GetEventsInterface();
	const auto Identity = Online::GetIdentityInterface();

	if (Events.IsValid() && Identity.IsValid())
	{
		ULocalPlayer* LocalPlayer = Cast<ULocalPlayer>(Player);
		if (LocalPlayer)
		{
			int32 UserIndex = LocalPlayer->ControllerId;
			TSharedPtr<FUniqueNetId> UniqueID = Identity->GetUniquePlayerId(UserIndex);			
			if (UniqueID.IsValid())
			{			
				ACharacter* Pawn = GetCharacter();
				// If player is dead, use location stored during pawn cleanup.
				FVector Location = LastDeathLocation;
				if (Pawn)
				{
					Pawn->GetActorLocation();
				}

				FOnlineEventParms Params;		

				Params.Add( TEXT( "SectionId" ), FVariantData( (int32)1 ) );
				Params.Add( TEXT( "GameplayModeId" ), FVariantData( (int32)1 ) );
				Params.Add( TEXT( "DifficultyLevelId" ), FVariantData( (int32)0 ) );

				Params.Add( TEXT( "PlayerRoleId" ), FVariantData( (int32)0 ) );
				Params.Add( TEXT( "PlayerWeaponId" ), FVariantData( (int32)0 ) );
				Params.Add( TEXT( "EnemyRoleId" ), FVariantData( (int32)0 ) );
				Params.Add( TEXT( "KillTypeId" ), FVariantData( (int32)0 ) );			
				Params.Add( TEXT( "LocationX" ), FVariantData( Location.X ) );
				Params.Add( TEXT( "LocationY" ), FVariantData( Location.Y ) );
				Params.Add( TEXT( "LocationZ" ), FVariantData( Location.Z ) );
				Params.Add( TEXT( "EnemyWeaponId" ), FVariantData( (int32)0 ) );			
			
				Events->TriggerEvent(*UniqueID, TEXT("KillOponent"), Params);				
			}
		}
	}
}
Beispiel #22
0
TEST_F(INotifyTests, test_inotify_event_action) {
  // Assume event type is registered.
  StartEventLoop();
  auto sub = std::make_shared<TestINotifyEventSubscriber>();
  EventFactory::registerEventSubscriber(sub);

  auto sc = sub->GetSubscription(real_test_path, 0);
  sub->subscribe(&TestINotifyEventSubscriber::Callback, sc, nullptr);

  TriggerEvent(real_test_path);
  sub->WaitForEvents(kMaxEventLatency, 3);

  // Make sure the inotify action was expected.
  EXPECT_GT(sub->actions().size(), 0U);
  if (sub->actions().size() >= 2) {
    EXPECT_EQ(sub->actions()[0], "UPDATED");
    EXPECT_EQ(sub->actions()[1], "UPDATED");
  }
  StopEventLoop();
}
Beispiel #23
0
TEST_F(INotifyTests, test_inotify_event_action) {
  // Assume event type is registered.
  StartEventLoop();
  auto sub = std::make_shared<TestINotifyEventSubscriber>();
  sub->init();

  auto sc = sub->GetSubscription(kRealTestPath, 0);
  sub->subscribe(&TestINotifyEventSubscriber::Callback, sc, nullptr);

  TriggerEvent(kRealTestPath);
  sub->WaitForEvents(kMaxEventLatency, 4);

  // Make sure the inotify action was expected.
  EXPECT_EQ(sub->actions().size(), 4);
  EXPECT_EQ(sub->actions()[0], "UPDATED");
  EXPECT_EQ(sub->actions()[1], "OPENED");
  EXPECT_EQ(sub->actions()[2], "UPDATED");
  EXPECT_EQ(sub->actions()[3], "UPDATED");
  StopEventLoop();
}
void EventManager::ProcessEvents()
{
    assert (m_nActiveQueue < 2);

    unsigned int nLastActiveQueue = m_nActiveQueue;

    // swap active queue
    m_nActiveQueue = (m_nActiveQueue==1) ? 0 : 1;

    assert (m_nActiveQueue != nLastActiveQueue);
    assert (m_nActiveQueue < 2);

    for (auto iter=m_lEventQueue[nLastActiveQueue].begin(); iter != m_lEventQueue[nLastActiveQueue].end(); iter++)
    {
	std::shared_ptr<IEvent> *pspCurrentEvent = &(*iter);

	TriggerEvent(*pspCurrentEvent);
    }

    // clear processed queue
    m_lEventQueue[nLastActiveQueue].clear();
}
Beispiel #25
0
TEST_F(INotifyTests, test_inotify_directory_watch) {
  StartEventLoop();

  auto sub = std::make_shared<TestINotifyEventSubscriber>();
  EventFactory::registerEventSubscriber(sub);

  fs::create_directory(real_test_dir);
  fs::create_directory(real_test_sub_dir);

  // Subscribe to the directory inode
  auto mc = sub->createSubscriptionContext();
  mc->path = real_test_dir;
  mc->recursive = true;
  sub->subscribe(&TestINotifyEventSubscriber::Callback, mc, nullptr);

  // Trigger on a subdirectory's file.
  TriggerEvent(real_test_sub_dir_path);

  sub->WaitForEvents(kMaxEventLatency, 1);
  EXPECT_TRUE(sub->count() > 0);
  StopEventLoop();
}
Beispiel #26
0
TEST_F(INotifyTests, test_inotify_recursion) {
  StartEventLoop();

  auto sub = std::make_shared<TestINotifyEventSubscriber>();
  sub->init();

  boost::filesystem::create_directory(kRealTestDir);
  boost::filesystem::create_directory(kRealTestSubDir);

  // Subscribe to the directory inode
  auto mc = sub->createSubscriptionContext();
  mc->path = kRealTestDir;
  mc->recursive = true;
  sub->subscribe(&TestINotifyEventSubscriber::Callback, mc, nullptr);

  // Trigger on a subdirectory's file.
  TriggerEvent(kRealTestSubDirPath);

  sub->WaitForEvents(kMaxEventLatency, 1);
  EXPECT_TRUE(sub->count() > 0);
  StopEventLoop();
}
Beispiel #27
0
bool CMPTutorial::CheckNearbyEntities(const CPlayer *pPlayer)
{
	FUNCTION_PROFILER(GetISystem(), PROFILE_GAME);

	// checks for:
	//	eTE_NeutralFactory
	//	eTE_CaptureFactory
	//	eTE_EnterHostileFactory
	//	eTE_EnterPrototypeFactory
	//	eTE_ApproachEnemyBase
	//	eTE_ApproachEnemyHQ
	//	eTE_DestroyEnemyHQ
	//	eTE_CaptureAlienSite
	//	If none of these need checking, don't bother.
	if(! ( m_events[eTE_NeutralFactory].m_status == eMS_Checking
			|| m_events[eTE_CaptureFactory].m_status == eMS_Checking
		  || m_events[eTE_EnterHostileFactory].m_status == eMS_Checking
			|| m_events[eTE_EnterPrototypeFactory].m_status == eMS_Checking
			|| m_events[eTE_ApproachEnemyBase].m_status == eMS_Checking
			|| m_events[eTE_ApproachEnemyHq].m_status == eMS_Checking
			|| m_events[eTE_CaptureAlienSite].m_status == eMS_Checking
			|| m_events[eTE_AllAliensNoPrototype].m_status == eMS_Checking
			|| m_events[eTE_AlienNoPrototype].m_status == eMS_Checking ))
	{
		return false;
	}

	bool showPrompt = false;
	if(!pPlayer)
		return showPrompt;

	Vec3 playerPos = pPlayer->GetEntity()->GetWorldPos();
	int playerTeam = g_pGame->GetGameRules()->GetTeam(pPlayer->GetEntityId());

	// rewritten to avoid iterating through the entity list: cached lists of HQ / energy point / spawn groups
	bool allCrashSites = true;	// does the player's team own all crash sites
	bool PTFactory = false;			// does the player's team own the PT factory
	bool nearCrashSite = false;	// is the player near a crash site
	for(std::list<EntityId>::iterator it = m_alienEnergyPointList.begin(); it != m_alienEnergyPointList.end(); ++it)
	{
		EntityId eid = *it;

		// check team 
		if(playerTeam != g_pGame->GetGameRules()->GetTeam(eid))
			allCrashSites = false;

		IEntity* pEnt = gEnv->pEntitySystem->GetEntity(eid);
		if(pEnt)
		{
			Vec3 vec = pEnt->GetWorldPos() - playerPos;
			float distanceSq = vec.GetLengthSquared();
			if(distanceSq < 500.0f && g_pGame->GetGameRules()->GetTeam(pEnt->GetId()) == playerTeam)
			{
				showPrompt = TriggerEvent(eTE_CaptureAlienSite);
				nearCrashSite = true;
			}
		}
	}

	if(m_events[eTE_AllAliensNoPrototype].m_status == eMS_Checking
		|| m_events[eTE_AlienNoPrototype].m_status == eMS_Checking)
	{
		// if player's team doesn't own the PT factory, they get an additional message...
		for(std::list<EntityId>::iterator factIt = m_factoryList.begin(); factIt != m_factoryList.end(); ++factIt)
		{
			EntityId factoryId = *factIt;
			if(g_pGame->GetHUD())
			{
				if(g_pGame->GetHUD()->GetPowerStruggleHUD()->IsFactoryType(factoryId, CHUDPowerStruggle::E_PROTOTYPES))
				{
					if(g_pGame->GetGameRules()->GetTeam(factoryId) == playerTeam)
					{
						PTFactory = true;
					}
				}
			}
		}

		if(!PTFactory)
		{
			if(allCrashSites)
			{
				// player's team owns all aliens but not the factory
				TriggerEvent(eTE_AllAliensNoPrototype);
			}
			else if(nearCrashSite)
			{
				// player has captured an alien but not yet the prototype factory.
				TriggerEvent(eTE_AlienNoPrototype);
			}
		}
	}

	if(!showPrompt && m_events[eTE_ApproachEnemyBase].m_status == eMS_Checking)
	{
		std::list<EntityId>::iterator it = m_baseList.begin();
		for(; it != m_baseList.end(); ++it)
		{
			IEntity* pEnt = gEnv->pEntitySystem->GetEntity(*it);
			if(pEnt)
			{
				Vec3 vec = pEnt->GetWorldPos() - playerPos;
				float distanceSq = vec.GetLengthSquared();
				int team = g_pGame->GetGameRules()->GetTeam(pEnt->GetId());
				if(team != playerTeam)
				{
					if(distanceSq < 10000.0f)
						showPrompt = TriggerEvent(eTE_ApproachEnemyBase);
				}
			}
		}
	}

	if(!showPrompt && m_events[eTE_SpawnBunker].m_status == eMS_Checking)
	{
		std::list<EntityId>::iterator it = m_spawnGroupList.begin();
		for(; it != m_spawnGroupList.end(); ++it)
		{
			IEntity* pEnt = gEnv->pEntitySystem->GetEntity(*it);
			if(pEnt)
			{
				Vec3 vec = pEnt->GetWorldPos() - playerPos;
				float distanceSq = vec.GetLengthSquared();
				if(distanceSq <= 80.0f)
				{
					if(g_pGame->GetGameRules()->GetTeam(pEnt->GetId()) == 0)
						showPrompt = TriggerEvent(eTE_SpawnBunker);
				}
			}
		}
	}

	if(!showPrompt)
	{
		std::list<EntityId>::iterator it = m_factoryList.begin();
		for(; it != m_factoryList.end(); ++it)
		{
			IEntity* pEnt = gEnv->pEntitySystem->GetEntity(*it);
			if(pEnt)
			{
				Vec3 vec = pEnt->GetWorldPos() - playerPos;
				float distanceSq = vec.GetLengthSquared();
				if(distanceSq < 500.0f)
				{
					// prompt depends on team and factory type
					bool inPrototypeFactory = g_pGame->GetHUD()->GetPowerStruggleHUD()->IsFactoryType(pEnt->GetId(), CHUDPowerStruggle::E_PROTOTYPES);
					int team = g_pGame->GetGameRules()->GetTeam(pEnt->GetId());
					if(team == 0)
					{
						showPrompt = TriggerEvent(eTE_NeutralFactory);
					}
					else if(team != playerTeam)
					{
						showPrompt = TriggerEvent(eTE_EnterHostileFactory);
					}
					else // team == playerTeam
					{
						showPrompt = TriggerEvent(eTE_CaptureFactory);

						if(inPrototypeFactory)
						{
							showPrompt |= TriggerEvent(eTE_EnterPrototypeFactory);
						}
					}
				}
			}
		}
	}

	return showPrompt;
}
Beispiel #28
0
bool CMPTutorial::CheckBriefingEvents(const CPlayer* pPlayer)
{
	bool showPrompt = false;

	if(m_currentBriefingEvent < eTE_FIRST_BRIEFING 
		|| m_currentBriefingEvent > eTE_LAST_BRIEFING
		|| m_events[m_currentBriefingEvent].m_status != eMS_Checking)
		return showPrompt;

	switch(m_currentBriefingEvent)
	{
	case eTE_StartGame:
		// trigger as soon as player spawns for the first time. Must be a better way than the state id?
		if(pPlayer->GetSpectatorMode() == 0 && g_pGame->GetGameRules()->GetCurrentStateId() == 3)
		{
			showPrompt = TriggerEvent(m_currentBriefingEvent);
			m_currentBriefingEvent = eTE_ContinueTutorial;
		}
		break;

	case eTE_ContinueTutorial:
		// trigger right after previous, so long as 'end tutorial' hasn't been pressed. (if it has, tutorial will be disabled)
		if(m_events[eTE_StartGame].m_status != eMS_Checking)
		{
			showPrompt = TriggerEvent(m_currentBriefingEvent);
			m_currentBriefingEvent = eTE_Barracks;
		}
		break;

	case eTE_Barracks:
		// trigger 3s after previous ones dismissed
		if(m_events[eTE_ContinueTutorial].m_status != eMS_Checking)
		{
			showPrompt = TriggerEvent(m_currentBriefingEvent);
			m_currentBriefingEvent = eTE_CloseBarracksBuyMenu;
		}
		break;

	case eTE_CloseBarracksBuyMenu:
		// trigger when player closes buy menu in barracks. This is triggered by the HUD so doesn't need checking here.
		m_currentBriefingEvent = eTE_OpenMap;
		break;

	case eTE_OpenMap:
		// trigger when player opens map for first time. This is triggered by the HUD so doesn't need checking here.
		m_currentBriefingEvent = eTE_CloseMap;
		break;

	case eTE_CloseMap:
		// trigger when player closes map. This is triggered by the HUD so doesn't need checking here.
		m_currentBriefingEvent = eTE_Swingometer;
		break;

	case eTE_Swingometer:
		// triggered after close map message
		if(m_events[eTE_CloseMap].m_status != eMS_Checking)
		{
			showPrompt = TriggerEvent(m_currentBriefingEvent);
			m_currentBriefingEvent = eTE_NullEvent;
		}
		break;
	};

	return showPrompt;
}
Beispiel #29
0
void CMPTutorial::Update()
{
	FUNCTION_PROFILER(GetISystem(), PROFILE_GAME);

	if(!m_enabled && g_pGameCVars->g_PSTutorial_Enabled)
		EnableTutorialMode(true);
	else if(m_enabled && !g_pGameCVars->g_PSTutorial_Enabled)
		EnableTutorialMode(false);

	m_currentEvent.m_msgDisplayTime -= gEnv->pTimer->GetFrameTime();
	if(!m_enabled)
	{	
		if(m_currentEvent.m_msgDisplayTime < 0.0f && m_currentEvent.m_msgRemovalCondition != eMRC_None)
		{
			m_currentEvent.m_msgRemovalCondition = eMRC_None;
			SAFE_HUD_FUNC(ShowTutorialText(NULL,1));
		}
	}

	// update the text... must be done even if not enabled, to ensure the 'you may reenable...' 
	//	message is shown correctly.
	if(m_currentEvent.m_numChunks > 0)
	{
		// calculate how far through the current sound we are
		CTimeValue now = gEnv->pTimer->GetFrameStartTime();
		float soundTimer = now.GetMilliSeconds() - m_currentEvent.m_soundStartTime;
		assert(soundTimer >= 0);
		float soundPercent = 1.0f;
		if(m_currentEvent.m_soundLength == 0.0f && m_currentEvent.m_pCurrentSound.get())
		{
			m_currentEvent.m_soundLength = m_currentEvent.m_pCurrentSound->GetLengthMs();
		}
		if(m_currentEvent.m_soundLength > 0.0f)
		{
			soundPercent = soundTimer / m_currentEvent.m_soundLength;
		}
		for(int i=m_currentEvent.m_numChunks-1; i > m_currentEvent.m_currentChunk; --i)
		{
			if(m_currentEvent.m_chunks[i].m_startPercent <= soundPercent)
			{
				m_currentEvent.m_currentChunk = i;

				int pos = 2; // 2=bottom, 1=middle
				IActor *pClientActor = g_pGame->GetIGameFramework()->GetClientActor();	
				if(pClientActor && pClientActor->GetLinkedVehicle())
				{
					pos = 1;
				}

				SAFE_HUD_FUNC(ShowTutorialText(m_currentEvent.m_chunks[i].m_text, pos));
				break;
			}
		}
	}

	if(!m_enabled)
		return;

	CPlayer* pPlayer = static_cast<CPlayer*>(g_pGame->GetIGameFramework()->GetClientActor());
	if(!pPlayer)
		return;

	// don't start until game begins
	if(pPlayer->GetSpectatorMode() != 0 || g_pGame->GetGameRules()->GetCurrentStateId() != 3)
		return;

	if(!m_initialised)
	{
		m_initialised = true;

		if(g_pGame->GetHUD())
		{
			// register as a HUD listener
			g_pGame->GetHUD()->RegisterListener(this);
		}

		// go through entity list and pull out the factories.
		IEntityItPtr pIt = gEnv->pEntitySystem->GetEntityIterator();
		while (!pIt->IsEnd())
		{
			if (IEntity * pEnt = pIt->Next())
			{
				if(pEnt->GetClass() == m_pHQClass)
				{
					m_baseList.push_back(pEnt->GetId());
					//CryLog("Adding HQ %d to list: %d", pEnt->GetId(), m_baseList.size());
				}
				else if(pEnt->GetClass() == m_pAlienEnergyPointClass)
				{
					m_alienEnergyPointList.push_back(pEnt->GetId());
					//CryLog("Adding AEP %d to list: %d", pEnt->GetId(), m_alienEnergyPointList.size());
				}
				else if(pEnt->GetClass() == m_pSpawnGroupClass)
				{
					m_spawnGroupList.push_back(pEnt->GetId());
					//CryLog("Adding spawngroup %d to list: %d", pEnt->GetId(), m_spawnGroupList.size());
				}
				else if(pEnt->GetClass() == m_pFactoryClass)
				{
					m_factoryList.push_back(pEnt->GetId());
					//CryLog("Adding Factory %d to list: %d", pEnt->GetId(), m_factoryList.size());
				}
			}
		}
	}

	// first the briefing events. These are shown in order.
	bool showPrompt = CheckBriefingEvents(pPlayer);

	// player has been killed
	if(pPlayer->GetHealth() <= 0)
	{
		showPrompt = TriggerEvent(eTE_Killed);
	}
	else if(!showPrompt)
	{
		// check each event type here. Which might take a while.

		// entering a neutral factory
		// enter prototype factory
		// enter hostile factory
		// find alien crash
		m_entityCheckTimer -= gEnv->pTimer->GetFrameTime();
		if(m_entityCheckTimer < 0.0f)
		{
			CheckNearbyEntities(pPlayer);
			m_entityCheckTimer = ENTITY_CHECK_TIME;
		}

		// board vehicle and vehicle tutorials
		CheckVehicles(pPlayer);

		// player has been wounded
		if(pPlayer->GetHealth() < pPlayer->GetMaxHealth())
			TriggerEvent(eTE_Wounded);

		// bases
		m_baseCheckTimer -= gEnv->pTimer->GetFrameTime();
		if(m_baseCheckTimer < 0.0f)
		{
			CheckBases(pPlayer);
			m_baseCheckTimer = ENTITY_CHECK_TIME;
		}
	}

	bool promptShown = false;
	for(int i=0; i<eTE_NumEvents; ++i)
	{
		if(m_events[i].m_status == eMS_Waiting)
		{
			if(m_currentEvent.m_msgDisplayTime < -MESSAGE_GAP_TIME)
			{
				ShowMessage(m_events[i]);
			}
			promptShown = true;
			break;
		}
	}

	if(!promptShown	&& (m_currentEvent.m_msgRemovalCondition == eMRC_Time) && (m_currentEvent.m_msgDisplayTime < 0.0f))
	{
		HideMessage();
	}
}
Beispiel #30
0
void CMPTutorial::OnShowScoreBoard()
{
	TriggerEvent(eTE_ScoreBoard);
}