void CMomentumPlayer::Spawn() { SetModel(ENTITY_MODEL); BaseClass::Spawn(); AddFlag(FL_GODMODE); // do this here because we can't get a local player in the timer class ConVarRef gm("mom_gamemode"); switch (gm.GetInt()) { case MOMGM_BHOP: case MOMGM_SURF: case MOMGM_UNKNOWN: default: EnableAutoBhop(); break; case MOMGM_SCROLL: DisableAutoBhop(); break; } // Reset all bool gameevents IGameEvent *mapZoneEvent = gameeventmanager->CreateEvent("player_inside_mapzone"); IGameEvent *runSaveEvent = gameeventmanager->CreateEvent("run_save"); IGameEvent *timerStartEvent = gameeventmanager->CreateEvent("timer_started"); IGameEvent *practiceModeEvent = gameeventmanager->CreateEvent("practice_mode"); if (mapZoneEvent) { mapZoneEvent->SetBool("inside_startzone", false); mapZoneEvent->SetBool("inside_endzone", false); mapZoneEvent->SetBool("map_finished", false); mapZoneEvent->SetInt("current_stage", 0); mapZoneEvent->SetInt("stage_ticks", 0); gameeventmanager->FireEvent(mapZoneEvent); } if (runSaveEvent) { runSaveEvent->SetBool("run_saved", false); runSaveEvent->SetBool("run_posted", false); gameeventmanager->FireEvent(runSaveEvent); } if (timerStartEvent) { timerStartEvent->SetBool("timer_isrunning", false); gameeventmanager->FireEvent(timerStartEvent); } if (practiceModeEvent) { practiceModeEvent->SetBool("has_practicemode", false); gameeventmanager->FireEvent(practiceModeEvent); } RegisterThinkContext("THINK_EVERY_TICK"); RegisterThinkContext("CURTIME"); RegisterThinkContext("THINK_AVERAGE_STATS"); RegisterThinkContext("CURTIME_FOR_START"); SetContextThink(&CMomentumPlayer::UpdateRunStats, gpGlobals->curtime + gpGlobals->interval_per_tick, "THINK_EVERY_TICK"); SetContextThink(&CMomentumPlayer::CheckForBhop, gpGlobals->curtime, "CURTIME"); SetContextThink(&CMomentumPlayer::CalculateAverageStats, gpGlobals->curtime + AVERAGE_STATS_INTERVAL, "THINK_AVERAGE_STATS"); SetContextThink(&CMomentumPlayer::LimitSpeedInStartZone, gpGlobals->curtime, "CURTIME_FOR_START"); SetNextThink(gpGlobals->curtime); }
inline void FireMapFinishedClosedEvent(bool restart) { IGameEvent *pClosePanel = gameeventmanager->CreateEvent("mapfinished_panel_closed"); if (pClosePanel) { pClosePanel->SetBool("restart", restart); // Fire this event so other classes can get at this gameeventmanager->FireEvent(pClosePanel); } }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CTFStatPanel::UpdateStats( int iMsgType ) { C_TFPlayer *pPlayer = C_TFPlayer::GetLocalTFPlayer(); if ( !pPlayer ) return; // don't count stats if cheats on, commentary mode, etc if ( !g_AchievementMgrTF.CheckAchievementsEnabled() ) return; ClassStats_t &classStats = GetClassStats( m_iClassCurrentLife ); if ( iMsgType == STATMSG_PLAYERDEATH || iMsgType == STATMSG_PLAYERRESPAWN ) { // if the player just died, accumulate current life into total and check for maxs and records classStats.AccumulateRound( m_RoundStatsCurrentLife ); classStats.accumulated.m_iStat[TFSTAT_MAXSENTRYKILLS] = 0; // sentry kills is a max value rather than a count, meaningless to accumulate CalcMaxsAndRecords(); // reset current life stats m_iClassCurrentLife = TF_CLASS_UNDEFINED; m_iTeamCurrentLife = TEAM_UNASSIGNED; m_RoundStatsCurrentLife.Reset(); } m_bStatsChanged = true; if ( m_statRecord > TFSTAT_UNDEFINED ) { bool bAlive = ( iMsgType != STATMSG_PLAYERDEATH ); if ( !bAlive || ( gpGlobals->curtime - m_flTimeLastSpawn < 3.0 ) ) { // show the panel now if dead or very recently spawned vgui::ivgui()->AddTickSignal( GetVPanel(), 1000 ); ShowStatPanel( m_iCurStatClass, m_iCurStatTeam, m_iCurStatValue, m_statRecord, m_recordBreakType, bAlive ); m_flTimeHide = gpGlobals->curtime + ( bAlive ? 12.0f : 20.0f ); m_statRecord = TFSTAT_UNDEFINED; } } IGameEvent * event = gameeventmanager->CreateEvent( "player_stats_updated" ); if ( event ) { event->SetBool( "forceupload", false ); gameeventmanager->FireEventClientSide( event ); } UpdateStatSummaryPanel(); }
bool CASW_Button_Area::WaitingForInputVismonCallback( CBaseEntity *pVisibleEntity, CBasePlayer *pViewingPlayer ) { CASW_Button_Area *pButtonArea = static_cast< CASW_Button_Area* >( pVisibleEntity ); IGameEvent * event = gameeventmanager->CreateEvent( "button_area_active" ); if ( event ) { event->SetInt( "userid", pViewingPlayer->GetUserID() ); event->SetInt( "entindex", pButtonArea->entindex() ); event->SetInt( "prop", pButtonArea->m_hPanelProp.Get() ? pButtonArea->m_hPanelProp.Get()->entindex() : pButtonArea->entindex() ); event->SetBool( "locked", pButtonArea->IsLocked() ); gameeventmanager->FireEvent( event ); } return false; }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void C_TeamTrainWatcher::OnDataChanged( DataUpdateType_t updateType ) { if ( m_iOldTrainSpeedLevel != m_iTrainSpeedLevel || m_nOldNumCappers != m_nNumCappers ) { IGameEvent *event = gameeventmanager->CreateEvent( "escort_speed" ); if ( event ) { event->SetInt( "speed", m_iTrainSpeedLevel ); event->SetInt( "players", m_nNumCappers ); gameeventmanager->FireEventClientSide( event ); } } if ( m_flOldProgress != m_flTotalProgress ) { IGameEvent *event = gameeventmanager->CreateEvent( "escort_progress" ); if ( event ) { event->SetFloat( "progress", m_flTotalProgress ); if ( m_flOldProgress <= -1 ) { event->SetBool( "reset", true ); } gameeventmanager->FireEventClientSide( event ); } } if ( m_flOldRecedeTime != m_flRecedeTime ) { IGameEvent *event = gameeventmanager->CreateEvent( "escort_recede" ); if ( event ) { event->SetFloat( "recedetime", m_flRecedeTime ); gameeventmanager->FireEventClientSide( event ); } } }
//----------------------------------------------------------------------------- // Purpose: Input handler for showing the message and/or playing the sound. //----------------------------------------------------------------------------- void CEnvInstructorHint::InputShowHint( inputdata_t &inputdata ) { static int s_InstructorServerHintEventCreate = 0; IGameEvent * event = gameeventmanager->CreateEvent( "instructor_server_hint_create", false, &s_InstructorServerHintEventCreate ); if ( event ) { CBaseEntity *pTargetEntity = gEntList.FindEntityByName( NULL, m_iszHintTargetEntity ); if( pTargetEntity == NULL && !m_bStatic ) pTargetEntity = inputdata.pActivator; if( pTargetEntity == NULL ) pTargetEntity = GetWorldEntity(); char szColorString[128]; Q_snprintf( szColorString, sizeof( szColorString ), "%.3d,%.3d,%.3d", m_Color.r, m_Color.g, m_Color.b ); int iFlags = 0; iFlags |= (m_iPulseOption == 0) ? 0 : (LOCATOR_ICON_FX_PULSE_SLOW << (m_iPulseOption - 1)); iFlags |= (m_iAlphaOption == 0) ? 0 : (LOCATOR_ICON_FX_ALPHA_SLOW << (m_iAlphaOption - 1)); iFlags |= (m_iShakeOption == 0) ? 0 : (LOCATOR_ICON_FX_SHAKE_NARROW << (m_iShakeOption - 1)); iFlags |= m_bStatic ? LOCATOR_ICON_FX_STATIC : 0; CBasePlayer *pActivator = NULL; bool bFilterByActivator = m_bLocalPlayerOnly; #ifdef INFESTED_DLL CASW_Marine *pMarine = dynamic_cast<CASW_Marine*>( inputdata.pActivator ); if ( pMarine ) { pActivator = pMarine->GetCommander(); } #else if ( inputdata.value.StringID() != NULL_STRING ) { CBaseEntity *pTarget = gEntList.FindEntityByName( NULL, inputdata.value.String() ); pActivator = dynamic_cast<CBasePlayer*>( pTarget ); if ( pActivator ) { bFilterByActivator = true; } } else { if ( GameRules()->IsMultiplayer() == false ) { pActivator = UTIL_GetLocalPlayer(); } else { Warning( "Failed to play server side instructor hint: no player specified for hint\n" ); Assert( 0 ); } } #endif const char *pActivatorCaption = m_iszActivatorCaption.ToCStr(); if ( !pActivatorCaption || pActivatorCaption[ 0 ] == '\0' ) { pActivatorCaption = m_iszCaption.ToCStr(); } event->SetString( "hint_name", GetEntityName().ToCStr() ); event->SetString( "hint_replace_key", m_iszReplace_Key.ToCStr() ); event->SetInt( "hint_target", pTargetEntity->entindex() ); event->SetInt( "hint_activator_userid", ( pActivator ? pActivator->GetUserID() : 0 ) ); event->SetInt( "hint_timeout", m_iTimeout ); event->SetString( "hint_icon_onscreen", m_iszIcon_Onscreen.ToCStr() ); event->SetString( "hint_icon_offscreen", m_iszIcon_Offscreen.ToCStr() ); event->SetString( "hint_caption", m_iszCaption.ToCStr() ); event->SetString( "hint_activator_caption", pActivatorCaption ); event->SetString( "hint_color", szColorString ); event->SetFloat( "hint_icon_offset", m_fIconOffset ); event->SetFloat( "hint_range", m_fRange ); event->SetInt( "hint_flags", iFlags ); event->SetString( "hint_binding", m_iszBinding.ToCStr() ); event->SetBool( "hint_allow_nodraw_target", m_bAllowNoDrawTarget ); event->SetBool( "hint_nooffscreen", m_bNoOffscreen ); event->SetBool( "hint_forcecaption", m_bForceCaption ); event->SetBool( "hint_local_player_only", bFilterByActivator ); gameeventmanager->FireEvent( event ); } }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void C_TeamTrainWatcher::OnDataChanged( DataUpdateType_t updateType ) { BaseClass::OnDataChanged( updateType ); if ( updateType == DATA_UPDATE_CREATED ) { SetNextClientThink( CLIENT_THINK_ALWAYS ); } if ( m_iOldTrainSpeedLevel != m_iTrainSpeedLevel || m_nOldNumCappers != m_nNumCappers ) { IGameEvent *event = gameeventmanager->CreateEvent( "escort_speed" ); if ( event ) { event->SetInt( "team", GetTeamNumber() ); event->SetInt( "speed", m_iTrainSpeedLevel ); event->SetInt( "players", m_nNumCappers ); gameeventmanager->FireEventClientSide( event ); } } if ( m_flOldProgress != m_flTotalProgress ) { IGameEvent *event = gameeventmanager->CreateEvent( "escort_progress" ); if ( event ) { event->SetInt( "team", GetTeamNumber() ); event->SetFloat( "progress", m_flTotalProgress ); if ( m_flOldProgress <= -1 ) { event->SetBool( "reset", true ); } gameeventmanager->FireEventClientSide( event ); } // check to see if the train is now on a hill if ( ObjectiveResource() ) { int nNumHills = ObjectiveResource()->GetNumNodeHillData( GetTeamNumber() ); if ( nNumHills > 0 ) { float flStart = 0, flEnd = 0; for ( int i = 0 ; i < nNumHills ; i++ ) { ObjectiveResource()->GetHillData( GetTeamNumber(), i, flStart, flEnd ); bool state = ( m_flTotalProgress >= flStart && m_flTotalProgress <= flEnd ); ObjectiveResource()->SetTrainOnHill( GetTeamNumber(), i, state ); } } } } if ( m_flOldRecedeTime != m_flRecedeTime ) { IGameEvent *event = gameeventmanager->CreateEvent( "escort_recede" ); if ( event ) { event->SetInt( "team", GetTeamNumber() ); event->SetFloat( "recedetime", m_flRecedeTime ); gameeventmanager->FireEventClientSide( event ); } } #ifdef GLOWS_ENABLE if ( m_hOldGlowEnt != m_hGlowEnt ) { UpdateGlowEffect(); } #endif // GLOWS_ENABLE }
void CMomentumPlayer::Spawn() { SetModel(ENTITY_MODEL); SetBodygroup(1, 11);//BODY_PROLATE_ELLIPSE // BASECLASS SPAWN MUST BE AFTER SETTING THE MODEL, OTHERWISE A NULL HAPPENS! BaseClass::Spawn(); AddFlag(FL_GODMODE); RemoveSolidFlags(FSOLID_NOT_SOLID); // this removes the flag that was added while switching to spectator mode which // prevented the player from activating triggers // do this here because we can't get a local player in the timer class ConVarRef gm("mom_gamemode"); switch (gm.GetInt()) { case MOMGM_BHOP: case MOMGM_SURF: case MOMGM_UNKNOWN: default: EnableAutoBhop(); break; case MOMGM_SCROLL: DisableAutoBhop(); break; } // Reset all bool gameevents IGameEvent *runSaveEvent = gameeventmanager->CreateEvent("run_save"); IGameEvent *runUploadEvent = gameeventmanager->CreateEvent("run_upload"); IGameEvent *timerStartEvent = gameeventmanager->CreateEvent("timer_state"); m_RunData.m_bIsInZone = false; m_RunData.m_bMapFinished = false; m_RunData.m_iCurrentZone = 0; m_bHasPracticeMode = false; ResetRunStats(); if (runSaveEvent) { runSaveEvent->SetBool("run_saved", false); gameeventmanager->FireEvent(runSaveEvent); } if (runUploadEvent) { runUploadEvent->SetBool("run_posted", false); runUploadEvent->SetString("web_msg", ""); gameeventmanager->FireEvent(runUploadEvent); } if (timerStartEvent) { timerStartEvent->SetInt("ent", entindex()); timerStartEvent->SetBool("is_running", false); gameeventmanager->FireEvent(timerStartEvent); } // Linear/etc map g_Timer->DispatchMapInfo(); RegisterThinkContext("THINK_EVERY_TICK"); RegisterThinkContext("CURTIME"); RegisterThinkContext("THINK_AVERAGE_STATS"); RegisterThinkContext("CURTIME_FOR_START"); RegisterThinkContext("TWEEN"); SetContextThink(&CMomentumPlayer::UpdateRunStats, gpGlobals->curtime + gpGlobals->interval_per_tick, "THINK_EVERY_TICK"); SetContextThink(&CMomentumPlayer::CheckForBhop, gpGlobals->curtime, "CURTIME"); SetContextThink(&CMomentumPlayer::CalculateAverageStats, gpGlobals->curtime + AVERAGE_STATS_INTERVAL, "THINK_AVERAGE_STATS"); SetContextThink(&CMomentumPlayer::LimitSpeedInStartZone, gpGlobals->curtime, "CURTIME_FOR_START"); SetContextThink(&CMomentumPlayer::TweenSlowdownPlayer, gpGlobals->curtime, "TWEEN"); SetNextThink(gpGlobals->curtime); DevLog("Finished spawn!\n"); }
void CTriggerTimerStop::StartTouch(CBaseEntity *pOther) { CMomentumPlayer *pPlayer = ToCMOMPlayer(pOther); IGameEvent *stageEvent = nullptr; // If timer is already stopped, there's nothing to stop (No run state effect to play) if (pPlayer) { g_Timer->SetEndTrigger(this); if (g_Timer->IsRunning() && !pPlayer->IsWatchingReplay()) { int zoneNum = pPlayer->m_RunData.m_iCurrentZone; // This is needed so we have an ending velocity. pPlayer->m_RunStats.SetZoneExitSpeed(zoneNum, pPlayer->GetLocalVelocity().Length(), pPlayer->GetLocalVelocity().Length2D()); //Check to see if we should calculate the timer offset fix if (ContainsPosition(pPlayer->GetPrevOrigin())) DevLog("PrevOrigin inside of end trigger, not calculating offset!\n"); else { DevLog("Previous origin is NOT inside the trigger, calculating offset...\n"); g_Timer->CalculateTickIntervalOffset(pPlayer, g_Timer->ZONETYPE_END); } //This is needed for the final stage pPlayer->m_RunStats.SetZoneTime(zoneNum, g_Timer->GetCurrentTime() - pPlayer->m_RunStats.GetZoneEnterTime(zoneNum)); //Ending velocity checks float endvel = pPlayer->GetLocalVelocity().Length(); float endvel2D = pPlayer->GetLocalVelocity().Length2D(); float finalVel = endvel; float finalVel2D = endvel2D; if (endvel <= pPlayer->m_RunStats.GetZoneVelocityMax(0, false)) finalVel = pPlayer->m_RunStats.GetZoneVelocityMax(0, false); if (endvel2D <= pPlayer->m_RunStats.GetZoneVelocityMax(0, true)) finalVel2D = pPlayer->m_RunStats.GetZoneVelocityMax(0, true); pPlayer->m_RunStats.SetZoneVelocityMax(0, finalVel, finalVel2D); pPlayer->m_RunStats.SetZoneExitSpeed(0, endvel, endvel2D); //Stop the timer g_Timer->Stop(true); pPlayer->m_RunData.m_flRunTime = g_Timer->GetLastRunTime(); //The map is now finished, show the mapfinished panel pPlayer->m_RunData.m_bMapFinished = true; pPlayer->m_RunData.m_bTimerRunning = false; } stageEvent = gameeventmanager->CreateEvent("zone_enter"); pPlayer->m_RunData.m_bIsInZone = true; } else { CMomentumReplayGhostEntity *pGhost = dynamic_cast<CMomentumReplayGhostEntity*>(pOther); if (pGhost) { stageEvent = gameeventmanager->CreateEvent("zone_enter"); pGhost->m_RunData.m_bMapFinished = true; pGhost->m_RunData.m_bTimerRunning = false; pGhost->m_RunData.m_bIsInZone = true; //Needed for hud_comparisons IGameEvent *timerStateEvent = gameeventmanager->CreateEvent("timer_state"); if (timerStateEvent) { timerStateEvent->SetInt("ent", pGhost->entindex()); timerStateEvent->SetBool("is_running", false); gameeventmanager->FireEvent(timerStateEvent); } pGhost->StopTimer(); //MOM_TODO: Maybe play effects if the player is racing against us and lost? } } //Used by speedometer if (stageEvent) { gameeventmanager->FireEvent(stageEvent); } BaseClass::StartTouch(pOther); }
void CTriggerTimerStart::EndTouch(CBaseEntity *pOther) { if (pOther->IsPlayer()) { CMomentumPlayer *pPlayer = ToCMOMPlayer(pOther); //surf or other gamemodes has timer start on exiting zone, bhop timer starts when the player jumps if (!pPlayer->m_bHasPracticeMode && !g_Timer->IsRunning()) // do not start timer if player is in practice mode or it's already running. { if (IsLimitingSpeed()) { Vector velocity = pOther->GetAbsVelocity(); // Isn't it nice how Vector2D.h doesn't have Normalize() on it? // It only has a NormalizeInPlace... Not simple enough for me Vector2D vel2D = velocity.AsVector2D(); if (pPlayer->DidPlayerBhop()) { if (velocity.AsVector2D().IsLengthGreaterThan(m_fBhopLeaveSpeed)) { vel2D = ((vel2D / vel2D.Length()) * (m_fBhopLeaveSpeed)); pOther->SetAbsVelocity(Vector(vel2D.x, vel2D.y, velocity.z)); } } } g_Timer->Start(gpGlobals->tickcount); if (g_Timer->IsRunning()) { //Used for trimming later on if (g_ReplaySystem->GetReplayManager()->Recording()) { g_ReplaySystem->SetTimerStartTick(gpGlobals->tickcount); } pPlayer->m_RunData.m_bTimerRunning = g_Timer->IsRunning(); //Used for spectating later on pPlayer->m_RunData.m_iStartTick = gpGlobals->tickcount; } } pPlayer->m_RunData.m_bIsInZone = false; pPlayer->m_RunData.m_bMapFinished = false; } else { CMomentumReplayGhostEntity *pGhost = dynamic_cast<CMomentumReplayGhostEntity*>(pOther); if (pGhost) { pGhost->m_RunData.m_bIsInZone = false; pGhost->m_RunData.m_bMapFinished = false; pGhost->m_RunData.m_bTimerRunning = true; pGhost->m_RunData.m_iStartTick = gpGlobals->tickcount; pGhost->StartTimer(gpGlobals->tickcount); //Needed for hud_comparisons IGameEvent *timerStateEvent = gameeventmanager->CreateEvent("timer_state"); if (timerStateEvent) { timerStateEvent->SetInt("ent", pGhost->entindex()); timerStateEvent->SetBool("is_running", true); gameeventmanager->FireEvent(timerStateEvent); } } } // stop thinking on end touch SetNextThink(-1); BaseClass::EndTouch(pOther); }