Ejemplo n.º 1
0
void CASW_Button_Area::UpdateWaitingForInput()
{
	bool bOldWaitingForInput = m_bWaitingForInput;

	bool bSet = false;

	if ( m_bIsDoorButton )
	{
		CASW_Door *pDoor = GetDoor();
		if ( pDoor && pDoor->IsAutoOpen() )
		{
			m_bWaitingForInput = false;
			bSet = true;
		}
	}

	if ( !bSet )
	{
		m_bWaitingForInput = ASWGameRules()->GetGameState() == ASW_GS_INGAME && 
							 ( !m_bNoPower && !m_bIsInUse && ( m_bIsLocked || ( !m_bWasLocked && m_fLastButtonUseTime == 0 ) ) );
	}

	if ( !bOldWaitingForInput && m_bWaitingForInput )
	{
		VisibilityMonitor_AddEntity( this, asw_visrange_generic.GetFloat() * 0.9f, &CASW_Button_Area::WaitingForInputVismonCallback, &CASW_Button_Area::WaitingForInputVismonEvaluator );
	}
	else if ( bOldWaitingForInput && !m_bWaitingForInput )
	{
		VisibilityMonitor_RemoveEntity( this );

		IGameEvent * event = gameeventmanager->CreateEvent( "button_area_inactive" );
		if ( event )
		{
			event->SetInt( "entindex", entindex() );
			gameeventmanager->FireEvent( event );
		}
	}
}
void ASW_DropTest_f()
{
	CASW_Player *pPlayer = ToASW_Player(UTIL_GetCommandClient());;
	
	if (pPlayer && pPlayer->GetMarine())
	{
		CASW_Marine *pMarine = pPlayer->GetMarine();
		if (pMarine->GetFlags() & FL_FROZEN)	// don't allow this if the marine is frozen
			return;
		if (pPlayer->GetFlags() & FL_FROZEN)
			return;
		int c = pMarine->WeaponCount();
		int current = -1;
		//int target = 0;
		for (int i=0;i<c;i++)
		{
			CBaseCombatWeapon *pWeapon = pMarine->GetWeapon(i);
			if (pWeapon == pMarine->GetActiveWeapon())
			{
				current = i;
				break;
			}
		}
		if (current == -1)
			return;
		
		pMarine->DropWeapon(current);

		IGameEvent * event = gameeventmanager->CreateEvent( "player_dropped_weapon" );
		if ( event )
		{
			event->SetInt( "userid", pPlayer->GetUserID() );

			gameeventmanager->FireEvent( event );
		}
	}
}
Ejemplo n.º 3
0
// Ability to alter the objective:
//   DOBJ_ACTION_OPEN: Opens the objective door and starts spawning creeps (if round has started)
//   DOBJ_ACTION_CLOSE: Closes the objective door and stops spawning creeps (if this is the last door, the round will end)
int DotaObjective::TakeAction( int dobjAction ) { // Issue #24: AMP - 2013-10-04 - Lane manipulation
	if (dobjAction & DOBJ_ACTION_CLOSE) {
		PropSetAnim( "Close" );

		// Issue #35: JMS - 2013-10-27 - fire event to clients
		IGameEvent *pEvent = gameeventmanager->CreateEvent( "objectivegate_close" );
		if ( pEvent )
		{
			pEvent->SetString( "lane", GetLane() );
			pEvent->SetInt( "team", this->GetTeamNumber() );
			gameeventmanager->FireEvent( pEvent );
		}

		m_bMet = true;			
				
		//turn off the maker
		CreepMaker * maker = (CreepMaker*)gEntList.FindEntityByName( NULL, m_creepMakerName );
		if( maker )
			maker->m_enabled = false;

		//see if I'm the last one, if so, game over
		bool foundOne = false;
		for ( CBaseEntity *pEntity = gEntList.FirstEnt(); pEntity != NULL; pEntity = gEntList.NextEnt(pEntity) )
		{
			DotaObjective * obj = dynamic_cast<DotaObjective*>( pEntity );
			if ( obj && obj->GetTeamNumber() == this->GetTeamNumber() && !obj->m_bMet )
				foundOne = true;
		}
		if ( !foundOne )
		{
			CHL2MPRules *rules = (CHL2MPRules*)g_pGameRules;
			if ( rules && !rules->IsIntermission() )
			{
				rules->EndMultiplayerGame();
			}
		}
		return true;
	} else if (dobjAction & DOBJ_ACTION_OPEN) {

		// Issue #35: JMS - 2013-10-27 - fire event to clients
		IGameEvent *pEvent = gameeventmanager->CreateEvent( "objectivegate_open" );
		if ( pEvent )
		{
			pEvent->SetString( "lane", GetLane() );
			pEvent->SetInt( "team", this->GetTeamNumber() );
			gameeventmanager->FireEvent( pEvent );
		}

		m_timesHit = 0;
		m_bMet = false;
		CreepMaker * maker = (CreepMaker*)gEntList.FindEntityByName( NULL, m_creepMakerName );
		maker->m_enabled = true;
		PropSetAnim( "Open" );
		return true;
	}
	return false;
}
Ejemplo n.º 4
0
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CTeamControlPoint::CaptureStart( int iCapTeam, int iNumCappingPlayers, int *pCappingPlayers )
{
	int iNumCappers = iNumCappingPlayers;

	float flLastOwnershipChangeTime = -1.f;
	CBaseEntity *pEnt =	gEntList.FindEntityByClassname( NULL, GetControlPointMasterName() );
	while( pEnt )
	{
		CTeamControlPointMaster *pMaster = dynamic_cast<CTeamControlPointMaster *>( pEnt );
		if ( pMaster && pMaster->IsActive() )
		{
			flLastOwnershipChangeTime = pMaster->GetLastOwnershipChangeTime();
		}
		pEnt = gEntList.FindEntityByClassname( pEnt, GetControlPointMasterName() );
	}

	IGameEvent *event = gameeventmanager->CreateEvent( "teamplay_point_startcapture" );
	if ( event )
	{
		event->SetInt( "cp", m_iPointIndex );
		event->SetString( "cpname", STRING( m_iszPrintName ) );
		event->SetInt( "team", m_iTeam );
		event->SetInt( "capteam", iCapTeam );
		event->SetFloat( "captime", gpGlobals->curtime - flLastOwnershipChangeTime );

		// safety check
		if ( iNumCappers > 8 )
		{
			iNumCappers = 8;
		}

		char cappers[9];	// pCappingPlayers should be max length 8
		int i;
		for( i = 0 ; i < iNumCappers ; i++ )
		{
			cappers[i] = (char)pCappingPlayers[i];
		}

		cappers[i] = '\0';

		// pCappingPlayers is a null terminated list of player indices
		event->SetString( "cappers", cappers );
		event->SetInt( "priority", 7 );

		gameeventmanager->FireEvent( event );
	}
}
Ejemplo n.º 5
0
void CGameFortsInfoZone::HandleSameTeam(CBasePlayer *pPlayer)
{
	if(pPlayer == NULL)
		return;

	if(IsPlayerCarryingInfos(pPlayer))
	{
		g_Teams[pPlayer->GetTeamNumber()]->AddScore(1);
		pPlayer->IncrementFragCount(3);
		IGameEvent *event = gameeventmanager->CreateEvent( "player_death" );
		if( event )
		{
			event->SetInt("userid", 0 );
			event->SetInt("attacker", pPlayer->GetUserID() );
			event->SetString("weapon", "fortsscore" );
			gameeventmanager->FireEvent( event );
		}

		ResetAllInfos(true);

		if(pPlayer->GetTeamNumber() == TEAM_PINK)
			m_OnPinkScore.FireOutput(pPlayer, this);
		else
			m_OnGreenScore.FireOutput(pPlayer, this);

		CRecipientFilter allyFilter, ennemyFilter;
		allyFilter.AddRecipientsByTeam(pPlayer->GetTeam());
		ennemyFilter.AddRecipientsByTeam(g_Teams[pPlayer->GetTeamNumber()==TEAM_PINK?TEAM_GREEN:TEAM_PINK]);

		allyFilter.MakeReliable();
		ennemyFilter.MakeReliable();

		CBaseEntity::EmitSound(allyFilter, NULL, "Gameplay.Score.Friend");
		CBaseEntity::EmitSound(ennemyFilter, NULL, "Gameplay.Score.Ennemy");

	}
}
Ejemplo n.º 6
0
void GraphicsProperty::Response(IGameEvent &rEvent)
{
    if (rEvent.ID() == GameEventSetPosition::Id())
    {
        GameEventSetPosition &rEventSP = (GameEventSetPosition &)rEvent;

    }
    else if (rEvent.ID() == GameEventOnAttach::Id())
    {
        GameEventOnAttach &rEventOA = (GameEventOnAttach &)rEvent;
        try
        {
            GA_FileName &rFileName = (GA_FileName &)rEventOA.m_rEntity.Attribute(GA_FileName::s_id);
        }
        catch(gameexception::bad_index &)
        {
            assert(0 && "Attribute 'GA_FileName' not attached ?");
        }
        catch(...)
        {
            assert(0);
        }
    }
}
void BonusMapChallengeUpdate( const char *pchFileName, const char *pchMapName, const char *pchChallengeName, int iBest )
{
	CreateInterfaceFn gameUIFactory = g_GameUI.GetFactory();
	if ( gameUIFactory )
	{
		IGameUI *pGameUI = (IGameUI *) gameUIFactory(GAMEUI_INTERFACE_VERSION, NULL );
		if ( pGameUI )
		{
			pGameUI->BonusMapChallengeUpdate( pchFileName, pchMapName, pchChallengeName, iBest );

			int piNumMedals[ 3 ];
			pGameUI->BonusMapNumMedals( piNumMedals );

			IGameEvent *event = gameeventmanager->CreateEvent( "challenge_map_complete" );
			if ( event )
			{
				event->SetInt( "numbronze", piNumMedals[ 0 ] );
				event->SetInt( "numsilver", piNumMedals[ 1 ] );
				event->SetInt( "numgold", piNumMedals[ 2 ] );
				gameeventmanager->FireEvent( event );
			}
		}	
	}
}
Ejemplo n.º 8
0
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CTeamControlPoint::InternalSetLocked( bool bLocked )
{
	if ( !bLocked && m_bLocked )
	{
		// unlocked this point
		IGameEvent *event = gameeventmanager->CreateEvent( "teamplay_point_unlocked" );
		if ( event )
		{
			event->SetInt( "cp", m_iPointIndex );
			event->SetString( "cpname", STRING( m_iszPrintName ) );
			event->SetInt( "team", m_iTeam );
			gameeventmanager->FireEvent( event );
		}
	}
	else if ( bLocked && !m_bLocked )
	{
		// locked this point
		IGameEvent *event = gameeventmanager->CreateEvent( "teamplay_point_locked" );
		if ( event )
		{
			event->SetInt( "cp", m_iPointIndex );
			event->SetString( "cpname", STRING( m_iszPrintName ) );
			event->SetInt( "team", m_iTeam );
			gameeventmanager->FireEvent( event );
		}
	}

	m_bLocked = bLocked;

	if ( ObjectiveResource() && GetPointIndex() < ObjectiveResource()->GetNumControlPoints() )
	{
		ObjectiveResource()->SetCPLocked( GetPointIndex(), m_bLocked );
		ObjectiveResource()->SetCPUnlockTime( GetPointIndex(), 0.0f );
	}

	if ( !m_bLocked )
	{
		m_flUnlockTime = -1;
		m_OnUnlocked.FireOutput( this, this );
		SetContextThink( NULL, 0, CONTROL_POINT_UNLOCK_THINK );
	}
}
Ejemplo n.º 9
0
//-----------------------------------------------------------------------------
// 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 );
		}
	}
}
Ejemplo n.º 10
0
void CGameClient::Connect(const char * szName, int nUserID, INetChannel *pNetChannel, bool bFakePlayer)
{
	CBaseClient::Connect( szName, nUserID, pNetChannel, bFakePlayer );

	edict = EDICT_NUM( m_nEntityIndex );
	
	// init PackInfo
	m_PackInfo.m_pClientEnt = edict;
	m_PackInfo.m_nPVSSize = sizeof( m_PackInfo.m_PVS );
				
	// fire global game event
	IGameEvent *event = g_GameEventManager.CreateEvent( "player_connect" );
	{
		event->SetInt( "userid", m_UserID );
		event->SetInt( "index", m_nClientSlot );
		event->SetString( "name", m_Name );
		event->SetString("networkid", GetNetworkIDString() ); 	
		event->SetString( "address", m_NetChannel?m_NetChannel->GetAddress():"none" );
		event->SetInt( "bot", m_bFakePlayer?1:0 );
		g_GameEventManager.FireEvent( event );
	}
}
Ejemplo n.º 11
0
void CHLTVDirector::StartChaseCameraShot(int iTarget1, int iTarget2, int distance, int phi, int theta, bool bInEye)
{
	IGameEvent *shot = gameeventmanager->CreateEvent( "hltv_chase", true );

	if ( !shot )
		return;
	
	shot->SetInt("target1", iTarget1 );
	shot->SetInt("target2", iTarget2 );
	shot->SetInt("distance", distance );
	shot->SetInt("phi", phi ); // hi/low
	shot->SetInt( "theta", theta ); // left/right
	shot->SetInt( "ineye", bInEye?1:0 );
		
	m_iPVSEntity = iTarget1;

	// send spectators the HLTV director command as a game event
	m_pHLTVServer->BroadcastEvent( shot );
	gameeventmanager->FreeEvent( shot );
}
Ejemplo n.º 12
0
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CTeamControlPoint::CaptureStart( void )
{
	IGameEvent *event = gameeventmanager->CreateEvent( "teamplay_point_startcapture" );
	if ( event )
	{
		event->SetInt( "cp", m_iPointIndex );
		event->SetString( "cpname", STRING(m_iszPrintName) );
		event->SetInt( "team", m_iTeam );

		// pCappingPlayers is a null terminated list of player indices

		char capper[8];

		Q_snprintf( capper, sizeof( capper ), "%d", entindex() );

		event->SetString( "cappers", capper );
		event->SetInt( "priority", 7 );

		gameeventmanager->FireEvent( event );
	}
}
Ejemplo n.º 13
0
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CTeamControlPoint::CaptureBlocked( CBaseMultiplayerPlayer *pPlayer, CBaseMultiplayerPlayer *pVictim )
{
	if( strlen( STRING(m_iszPrintName) ) <= 0 )
		return;

	IGameEvent *event = gameeventmanager->CreateEvent( "teamplay_capture_blocked" );

	if ( event )
	{
		event->SetInt( "cp", m_iPointIndex );
		event->SetString( "cpname", STRING(m_iszPrintName) );
		event->SetInt( "blocker", pPlayer->entindex() );
		event->SetInt( "priority", 9 );
		if ( pVictim )
		{
			event->SetInt( "victim", pVictim->entindex() );
		}

		gameeventmanager->FireEvent( event );
	}

	PlayerBlocked( pPlayer );
}
Ejemplo n.º 14
0
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CTeamControlPoint::SendCapString( int iCapTeam, int iNumCappingPlayers, int *pCappingPlayers )
{
	if ( strlen( STRING(m_iszPrintName) ) <= 0 )
		return;

	int iNumCappers = iNumCappingPlayers;

	IGameEvent *event = gameeventmanager->CreateEvent( "teamplay_point_captured" );
	if ( event )
	{
		event->SetInt( "cp", m_iPointIndex );
		event->SetString( "cpname", STRING( m_iszPrintName ) );
		event->SetInt( "team", iCapTeam );

		// safety check
		if ( iNumCappers > 8 )
		{
			iNumCappers = 8;
		}

		char cappers[9];	// pCappingPlayers should be max length 8
		int i;
		for( i = 0 ; i < iNumCappers ; i++ )
		{
			cappers[i] = (char)pCappingPlayers[i];
		}

		cappers[i] = '\0';

		// pCappingPlayers is a null terminated list of player indices
		event->SetString( "cappers", cappers );
		event->SetInt( "priority", 9 );

		gameeventmanager->FireEvent( event );
	}
}
Ejemplo n.º 15
0
//-----------------------------------------------------------------------------
// 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
}
Ejemplo n.º 17
0
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CTriggerAreaCapture::BreakCapture( bool bNotEnoughPlayers )
{
	if( m_bCapturing )
	{
		// Remap team to get first game team = 1
		switch ( m_nCapturingTeam - FIRST_GAME_TEAM+1 )
		{
		case 1: 
			m_OnBreakTeam1.FireOutput( this, this );
			break;
		case 2: 
			m_OnBreakTeam2.FireOutput( this, this );
			break;
		default:
			Assert(0);
			break;
		}

		m_BreakOutput.FireOutput(this,this);

		m_bCapturing = false;
		m_nCapturingTeam = TEAM_UNASSIGNED;

		UpdateCappingTeam( TEAM_UNASSIGNED );

		if ( bNotEnoughPlayers )
		{
			IncrementCapAttemptNumber();
		}

		SetCapTimeRemaining( 0 );

		if( m_hPoint )
		{
			m_hPoint->CaptureEnd();

			// The point reverted to it's previous owner.
			IGameEvent *event = gameeventmanager->CreateEvent( "teamplay_capture_broken" );
			if ( event )
			{
				event->SetInt( "cp", m_hPoint->GetPointIndex() );
				event->SetString( "cpname", m_hPoint->GetName() );
				event->SetFloat( "time_remaining", m_fTimeRemaining );
				gameeventmanager->FireEvent( event );
			}
		}

		SetNumCappers( 0 );

		// tell all touching players to stop racking up capture points
		CTeam *pTeam = GetGlobalTeam( m_nCapturingTeam );
		if ( pTeam )
		{
			for ( int i=0;i<pTeam->GetNumPlayers();i++ )
			{
				CBaseMultiplayerPlayer *pPlayer = ToBaseMultiplayerPlayer( pTeam->GetPlayer(i) );
				if ( pPlayer && IsTouching( pPlayer ) )
				{
					pPlayer->StopScoringEscortPoints();					
				}
			}
		}
	}
}
Ejemplo n.º 18
0
//// HOST_SAY
// String comes in as
// say blah blah blah
// or as
// blah blah blah
//
void Host_Say( edict_t *pEdict, const CCommand &args, bool teamonly )
{
	CBasePlayer *client;
	int		j;
	char	*p;
	char	text[256];
	char    szTemp[256];
	const char *cpSay = "say";
	const char *cpSayTeam = "say_team";
	const char *pcmd = args[0];
	bool bSenderDead = false;

	// We can get a raw string now, without the "say " prepended
	if ( args.ArgC() == 0 )
		return;

	if ( !stricmp( pcmd, cpSay) || !stricmp( pcmd, cpSayTeam ) )
	{
		if ( args.ArgC() >= 2 )
		{
			p = (char *)args.ArgS();
		}
		else
		{
			// say with a blank message, nothing to do
			return;
		}
	}
	else  // Raw text, need to prepend argv[0]
	{
		if ( args.ArgC() >= 2 )
		{
			Q_snprintf( szTemp,sizeof(szTemp), "%s %s", ( char * )pcmd, (char *)args.ArgS() );
		}
		else
		{
			// Just a one word command, use the first word...sigh
			Q_snprintf( szTemp,sizeof(szTemp), "%s", ( char * )pcmd );
		}
		p = szTemp;
	}

	CBasePlayer *pPlayer = NULL;
	if ( pEdict )
	{
		pPlayer = ((CBasePlayer *)CBaseEntity::Instance( pEdict ));
		Assert( pPlayer );

		// make sure the text has valid content
		p = CheckChatText( pPlayer, p );
	}

	if ( !p )
		return;

	if ( pEdict )
	{
		if ( !pPlayer->CanSpeak() )
			return;

		// See if the player wants to modify of check the text
		pPlayer->CheckChatText( p, 127 );	// though the buffer szTemp that p points to is 256, 
											// chat text is capped to 127 in CheckChatText above

		Assert( strlen( pPlayer->GetPlayerName() ) > 0 );

		bSenderDead = ( pPlayer->m_lifeState != LIFE_ALIVE );
	}
	else
	{
		bSenderDead = false;
	}

	const char *pszFormat = NULL;
	const char *pszPrefix = NULL;
	const char *pszLocation = NULL;
	if ( g_pGameRules )
	{
		pszFormat = g_pGameRules->GetChatFormat( teamonly, pPlayer );
		pszPrefix = g_pGameRules->GetChatPrefix( teamonly, pPlayer );	
		pszLocation = g_pGameRules->GetChatLocation( teamonly, pPlayer );
	}

	const char *pszPlayerName = pPlayer ? pPlayer->GetPlayerName():"Console";

	if ( pszPrefix && strlen( pszPrefix ) > 0 )
	{
		if ( pszLocation && strlen( pszLocation ) )
		{
			Q_snprintf( text, sizeof(text), "%s %s @ %s: ", pszPrefix, pszPlayerName, pszLocation );
		}
		else
		{
			Q_snprintf( text, sizeof(text), "%s %s: ", pszPrefix, pszPlayerName );
		}
	}
	else
	{
		Q_snprintf( text, sizeof(text), "%s: ", pszPlayerName );
	}

	j = sizeof(text) - 2 - strlen(text);  // -2 for /n and null terminator
	if ( (int)strlen(p) > j )
		p[j] = 0;

	Q_strncat( text, p, sizeof( text ), COPY_ALL_CHARACTERS );
	Q_strncat( text, "\n", sizeof( text ), COPY_ALL_CHARACTERS );
 
	// loop through all players
	// Start with the first player.
	// This may return the world in single player if the client types something between levels or during spawn
	// so check it, or it will infinite loop

	client = NULL;
	for ( int i = 1; i <= gpGlobals->maxClients; i++ )
	{
		client = ToBaseMultiplayerPlayer( UTIL_PlayerByIndex( i ) );
		if ( !client || !client->edict() )
			continue;
		
		if ( client->edict() == pEdict )
			continue;

		if ( !(client->IsNetClient()) )	// Not a client ? (should never be true)
			continue;

		if ( teamonly && g_pGameRules->PlayerCanHearChat( client, pPlayer ) != GR_TEAMMATE )
			continue;

		if ( pPlayer && !client->CanHearAndReadChatFrom( pPlayer ) )
			continue;

		if ( pPlayer && GetVoiceGameMgr() && GetVoiceGameMgr()->IsPlayerIgnoringPlayer( pPlayer->entindex(), i ) )
			continue;

		CSingleUserRecipientFilter user( client );
		user.MakeReliable();

		if ( pszFormat )
		{
			UTIL_SayText2Filter( user, pPlayer, true, pszFormat, pszPlayerName, p, pszLocation );
		}
		else
		{
			UTIL_SayTextFilter( user, text, pPlayer, true );
		}
	}

	if ( pPlayer )
	{
		// print to the sending client
		CSingleUserRecipientFilter user( pPlayer );
		user.MakeReliable();

		if ( pszFormat )
		{
			UTIL_SayText2Filter( user, pPlayer, true, pszFormat, pszPlayerName, p, pszLocation );
		}
		else
		{
			UTIL_SayTextFilter( user, text, pPlayer, true );
		}
	}

	// echo to server console
	// Adrian: Only do this if we're running a dedicated server since we already print to console on the client.
	if ( engine->IsDedicatedServer() )
		 Msg( "%s", text );

	Assert( p );

	int userid = 0;
	const char *networkID = "Console";
	const char *playerName = "Console";
	const char *playerTeam = "Console";
	if ( pPlayer )
	{
		userid = pPlayer->GetUserID();
		networkID = pPlayer->GetNetworkIDString();
		playerName = pPlayer->GetPlayerName();
		CTeam *team = pPlayer->GetTeam();
		if ( team )
		{
			playerTeam = team->GetName();
		}
	}
		
	if ( teamonly )
		UTIL_LogPrintf( "\"%s<%i><%s><%s>\" say_team \"%s\"\n", playerName, userid, networkID, playerTeam, p );
	else
		UTIL_LogPrintf( "\"%s<%i><%s><%s>\" say \"%s\"\n", playerName, userid, networkID, playerTeam, p );

	IGameEvent * event = gameeventmanager->CreateEvent( "player_say" );

	if ( event )	// will be null if there are no listeners!
	{
		event->SetInt("userid", userid );
		event->SetString("text", p );
		event->SetInt("priority", 1 );	// HLTV event priority, not transmitted
		gameeventmanager->FireEvent( event );
	}
}
void CHL2MPRules::RestartGame()
{
	// bounds check
	if ( mp_timelimit.GetInt() < 0 )
	{
		mp_timelimit.SetValue( 0 );
	}
	m_flGameStartTime = gpGlobals->curtime;
	if ( !IsFinite( m_flGameStartTime.Get() ) )
	{
		Warning( "Trying to set a NaN game start time\n" );
		m_flGameStartTime.GetForModify() = 0.0f;
	}

	// Pre Map Cleanup
	for (int i = 1; i <= gpGlobals->maxClients; i++ )
	{
		CHL2MP_Player *pPlayer = (CHL2MP_Player*) UTIL_PlayerByIndex( i );

		if ( !pPlayer )
			continue;

		//Tony; if they aren't a spectator, make sure they get cleaned up before entities are removed!
		if ( pPlayer->GetTeamNumber() != TEAM_SPECTATOR )
		{
				// If they're in a vehicle, make sure they get out!
				if ( pPlayer->IsInAVehicle() )
					pPlayer->LeaveVehicle();

				QAngle angles = pPlayer->GetLocalAngles();

				angles.x = 0;
				angles.z = 0;

				pPlayer->SetLocalAngles( angles );
				CBaseCombatWeapon *pWeapon = (CBaseCombatWeapon*)pPlayer->GetActiveWeapon();
				if (pWeapon)
				{
					pPlayer->Weapon_Detach( pWeapon );
					UTIL_Remove( pWeapon );
				}
		}
		pPlayer->RemoveAllItems(true);
		pPlayer->ClearActiveWeapon();
		pPlayer->Reset();
	}

	CleanUpMap();
	
	// now that everything is cleaned up, respawn everyone.
	for (int i = 1; i <= gpGlobals->maxClients; i++ )
	{
		CHL2MP_Player *pPlayer = (CHL2MP_Player*) UTIL_PlayerByIndex( i );

		if ( !pPlayer )
			continue;

		//Tony; if they aren't a spectator, respawn them.
		if ( pPlayer->GetTeamNumber() != TEAM_SPECTATOR )
			pPlayer->Spawn();
	}

	CTeam *pRebels = GetGlobalTeam( TEAM_REBELS );
	CTeam *pCombine = GetGlobalTeam( TEAM_COMBINE );

	if ( pRebels )
	{
		pRebels->SetRoundScore( 0 );
	}

	if ( pCombine )
	{
		pCombine->SetRoundScore( 0 );
	}

	m_flIntermissionEndTime = 0;
	m_flRestartGameTime = 0.0;		
	m_bCompleteReset = false;

	IGameEvent * event = gameeventmanager->CreateEvent( "round_start" );
	if ( event )
	{
		event->SetInt("fraglimit", 0 );
		event->SetInt( "priority", 6 ); // HLTV event priority, not transmitted

		event->SetString("objective","DEATHMATCH");

		gameeventmanager->FireEvent( event );
	}
}
Ejemplo n.º 20
0
void CASW_Alien::TraceAttack( const CTakeDamageInfo &info, const Vector &vecDir, trace_t *ptr )
{
#ifdef GAME_DLL
    m_fNoDamageDecal = false;
    if ( m_takedamage == DAMAGE_NO )
        return;
#endif

    CTakeDamageInfo subInfo = info;

#ifdef GAME_DLL
    SetLastHitGroup( ptr->hitgroup );
    m_nForceBone = ptr->physicsbone;		// save this bone for physics forces
#endif

    Assert( m_nForceBone > -255 && m_nForceBone < 256 );

    // mining laser does reduced damage
    if ( info.GetDamageType() & DMG_ENERGYBEAM )
    {
        subInfo.ScaleDamage( asw_alien_mining_laser_damage_scale.GetFloat() );
    }

    if ( subInfo.GetDamage() >= 1.0 && !(subInfo.GetDamageType() & DMG_SHOCK )
            && !( subInfo.GetDamageType() & DMG_BURN ) )
    {
#ifdef GAME_DLL
        Bleed( subInfo, ptr->endpos + m_LagCompensation.GetLagCompensationOffset(), vecDir, ptr );
        if ( ptr->hitgroup == HITGROUP_HEAD && m_iHealth - subInfo.GetDamage() > 0 )
        {
            m_fNoDamageDecal = true;
        }
#else
        Bleed( subInfo, ptr->endpos, vecDir, ptr );
        //OnHurt();
#endif
    }

    if( !info.GetInflictor() )
    {
        subInfo.SetInflictor( info.GetAttacker() );
    }


    AddMultiDamage( subInfo, this );
#ifdef GAME_DLL
#else
    CASW_Marine *pMarine = dynamic_cast<CASW_Marine*>( subInfo.GetAttacker() );
    CASW_Player *pPlayerAttacker = NULL;

    if ( pMarine )
    {
        pPlayerAttacker = pMarine->GetCommander();
    }

    IGameEvent * event = gameeventmanager->CreateEvent( "alien_hurt" );
    if ( event )
    {
        event->SetInt( "attacker", ( pPlayerAttacker ? pPlayerAttacker->GetUserID() : 0 ) );
        event->SetInt( "entindex", entindex() );
        event->SetInt( "amount", subInfo.GetDamage() );
        gameeventmanager->FireEventClientSide( event );
    }

    UTIL_ASW_ClientFloatingDamageNumber( subInfo );
#endif
}
Ejemplo n.º 21
0
//-----------------------------------------------------------------------------
// Purpose: Add seconds to the timer while it is running or paused
//-----------------------------------------------------------------------------
void CTeamRoundTimer::AddTimerSeconds( int iSecondsToAdd, int iTeamResponsible /* = TEAM_UNASSIGNED*/ )
{
	if ( IsDisabled() )
		return;

	if ( TeamplayRoundBasedRules()->InStalemate() )
		return;

	// we only want to add time if we're round_running or team_win so the control points 
	// don't add time when they try to set their default owner when the map is first loading
	if ( TeamplayRoundBasedRules()->State_Get() != GR_STATE_RND_RUNNING && TeamplayRoundBasedRules()->State_Get() != GR_STATE_TEAM_WIN )
		return;

	if ( m_nTimerMaxLength > 0 )
	{
		// will adding this many seconds push us over our max length?
		if ( GetTimeRemaining() + iSecondsToAdd > m_nTimerMaxLength )
		{
			// adjust to only add up to our max length
			iSecondsToAdd = m_nTimerMaxLength - GetTimeRemaining();
		}
	}

	if ( m_bTimerPaused )
	{
		m_flTimeRemaining += (float)iSecondsToAdd;
	}
	else
	{
		m_flTimerEndTime += (float)iSecondsToAdd;
	}

	m_nTimerLength += iSecondsToAdd;
	CalculateOutputMessages();

	if ( ObjectiveResource() && ObjectiveResource()->GetTimerInHUD() == entindex() )
	{
		if ( !TeamplayRoundBasedRules()->InStalemate() && !TeamplayRoundBasedRules()->RoundHasBeenWon() )
		{
			if ( iTeamResponsible >= LAST_SHARED_TEAM+1 )
			{
				for ( int iTeam = LAST_SHARED_TEAM+1 ; iTeam < GetNumberOfTeams(); iTeam++ )
				{
					if ( iTeam == iTeamResponsible )
					{
						CTeamRecipientFilter filter( iTeam, true );
						EmitSound( filter, entindex(), ROUND_TIMER_TIME_ADDED_WINNER );
					}
					else
					{
						CTeamRecipientFilter filter( iTeam, true );
						EmitSound( filter, entindex(), ROUND_TIMER_TIME_ADDED_LOSER );
					}
				}
			}
			else
			{
				CReliableBroadcastRecipientFilter filter;
				EmitSound( filter, entindex(), ROUND_TIMER_TIME_ADDED );
			}
		}

		// is this the timer we're showing in the HUD?
		if ( m_bShowInHUD )
		{
			IGameEvent *event = gameeventmanager->CreateEvent( "teamplay_timer_time_added" );
			if ( event )
			{
				event->SetInt( "timer", entindex() );
				event->SetInt( "seconds_added", iSecondsToAdd );
				gameeventmanager->FireEvent( event );
			}
		}
	}
}
void CASW_HealGrenade_Projectile::DoAOE( CBaseEntity *pEntity )
{
	CASW_Marine *pTargetMarine = static_cast< CASW_Marine* >( pEntity );
	if ( !pTargetMarine )
		return;

	CASW_Marine *pMarine = dynamic_cast< CASW_Marine* >( GetOwnerEntity() ); // Carful! This might be null

	float flBaseHealAmount = m_flHealPerSecond * ( gpGlobals->curtime - m_flLastDoAOE );

	// At full health... multiplier is 1 + 0. At empty health multiplier is 1 + 3.0.
	float fHealthPercent = pTargetMarine->IsInfested() ? 0.0f : static_cast< float >( pTargetMarine->GetHealth() ) / pTargetMarine->GetMaxHealth();
	float flLowHealthMultiplier = ( 1.0f + 3.0f * ( 1.0f - fHealthPercent ) );
	float flHealAmount = MIN( flBaseHealAmount * flLowHealthMultiplier, pTargetMarine->GetMaxHealth() - ( pTargetMarine->GetHealth() + pTargetMarine->m_iSlowHealAmount ) );

	float flHealUsed = flHealAmount;

	if ( flHealAmount > 0.0f )
	{
		bool bHealedBefore = false;

		for ( int i = 0; i < m_hHealedEntities.Count(); ++i )
		{
			if ( m_hHealedEntities[ i ].Get() == pEntity )
			{
				bHealedBefore = true;
				break;
			}
		}

		if ( !bHealedBefore )
		{
			// Add it to the list of things we've healed at least once
			m_hHealedEntities.AddToTail( pEntity );

			// Fire event
			IGameEvent * event = gameeventmanager->CreateEvent( "player_heal" );
			if ( event )
			{
				CASW_Player *pPlayer = NULL;
				if ( pMarine )
				{
					pPlayer = pMarine->GetCommander();
				}
				event->SetInt( "userid", ( pPlayer ? pPlayer->GetUserID() : 0 ) );
				event->SetInt( "entindex", pTargetMarine->entindex() );
				gameeventmanager->FireEvent( event );
			}

			if ( pMarine )
			{
				CASW_Marine_Resource *pMR = pMarine->GetMarineResource();
				if ( pMR && !pMR->m_bAwardedHealBeaconAchievement && m_hHealedEntities.Count() >= 4 && pMarine->IsInhabited() && pMarine->GetCommander() )
				{
					pMR->m_bAwardedHealBeaconAchievement = true;
					pMarine->GetCommander()->AwardAchievement( ACHIEVEMENT_ASW_GROUP_HEAL );
				}
			}
		}

		pTargetMarine->AddSlowHeal( flHealAmount, 1, pMarine, this );

		float flHalfHealTotal = m_flHealAmountTotal / 2.0f;

		if ( m_flHealAmountLeft > flHalfHealTotal && ( m_flHealAmountLeft - flHealAmount ) <= flHalfHealTotal )
		{
			ASWFailAdvice()->OnHealGrenadeUsedWell();
		}

		m_flHealAmountLeft -= flHealUsed;

		if ( m_flHealAmountLeft <= 0.0f )
		{
			m_flTimeBurnOut = gpGlobals->curtime;
		}
	
		if ( ASWGameRules()->GetInfoHeal() && pMarine )
		{
			ASWGameRules()->GetInfoHeal()->OnMarineHealed( pMarine, pTargetMarine, NULL );
		}
	}

	if ( pTargetMarine->IsInfested() )
	{
		float fCurePercent = GetInfestationCureAmount();

		// cure infestation
		if ( fCurePercent > 0.0f )
		{
			// Cure infestation at 1/20th normal rate per second (the full 20 seconds or amount used does the full cure)
			pTargetMarine->CureInfestation( pMarine, 1.0f - ( ( 1.0f - fCurePercent ) * ( flHealUsed / m_flHealAmountTotal ) * ( gpGlobals->curtime - m_flLastDoAOE ) ) );
		}
	}
}
Ejemplo n.º 23
0
void CHL2MPRules::RestartGame()
{
    // bounds check
    if ( mp_timelimit.GetInt() < 0 )
    {
        mp_timelimit.SetValue( 0 );
    }
    m_flGameStartTime = gpGlobals->curtime;
    if ( !IsFinite( m_flGameStartTime.Get() ) )
    {
        Warning( "Trying to set a NaN game start time\n" );
        m_flGameStartTime.GetForModify() = 0.0f;
    }

    CleanUpMap();

    // now respawn all players
    for (int i = 1; i <= gpGlobals->maxClients; i++ )
    {
        CHL2MP_Player *pPlayer = (CHL2MP_Player*) UTIL_PlayerByIndex( i );

        if ( !pPlayer )
            continue;

        if ( pPlayer->GetActiveWeapon() )
        {
            pPlayer->GetActiveWeapon()->Holster();
        }
        pPlayer->RemoveAllItems( true );
        respawn( pPlayer, false );
        pPlayer->Reset();
    }

    // Respawn entities (glass, doors, etc..)

    CTeam *pRebels = GetGlobalTeam( TEAM_REBELS );
    CTeam *pCombine = GetGlobalTeam( TEAM_COMBINE );

    if ( pRebels )
    {
        pRebels->SetScore( 0 );
    }

    if ( pCombine )
    {
        pCombine->SetScore( 0 );
    }

    m_flIntermissionEndTime = 0;
    m_flRestartGameTime = 0.0;
    m_bCompleteReset = false;

    IGameEvent * event = gameeventmanager->CreateEvent( "round_start" );
    if ( event )
    {
        event->SetInt("fraglimit", 0 );
        event->SetInt( "priority", 6 ); // HLTV event priority, not transmitted

        event->SetString("objective","DEATHMATCH");

        gameeventmanager->FireEvent( event );
    }
}
Ejemplo n.º 24
0
//=========================================================
// ClientUserInfoChanged
//=========================================================
void CTeamplayRules::ClientSettingsChanged( CBasePlayer *pPlayer )
{
	/* TODO: handle skin, model & team changes 

  	char text[1024];

	// skin/color/model changes
	int iTeam = Q_atoi( engine->GetClientConVarValue( pPlayer->entindex(), "cl_team" ) );
	int iClass = Q_atoi( engine->GetClientConVarValue( pPlayer->entindex(), "cl_class" ) );

	if ( defaultteam.GetBool() )
	{
		// int clientIndex = pPlayer->entindex();

		// engine->SetClientKeyValue( clientIndex, "model", pPlayer->TeamName() );
		// engine->SetClientKeyValue( clientIndex, "team", pPlayer->TeamName() );
		UTIL_SayText( "Not allowed to change teams in this game!\n", pPlayer );
		return;
	}

	if ( defaultteam.GetFloat() || !IsValidTeam( mdls ) )
	{
		// int clientIndex = pPlayer->entindex();

		// engine->SetClientKeyValue( clientIndex, "model", pPlayer->TeamName() );
		Q_snprintf( text,sizeof(text), "Can't change team to \'%s\'\n", mdls );
		UTIL_SayText( text, pPlayer );
		Q_snprintf( text,sizeof(text), "Server limits teams to \'%s\'\n", m_szTeamList );
		UTIL_SayText( text, pPlayer );
		return;
	}

	ChangePlayerTeam( pPlayer, mdls, true, true );
	// recound stuff
	RecountTeams(); */

	const char *pszName = engine->GetClientConVarValue( pPlayer->entindex(), "name" );

	const char *pszOldName = pPlayer->GetPlayerName();

	// msg everyone if someone changes their name,  and it isn't the first time (changing no name to current name)
	// Note, not using FStrEq so that this is case sensitive
	if ( pszOldName[0] != 0 && Q_strcmp( pszOldName, pszName ) )
	{
		IGameEvent * event = gameeventmanager->CreateEvent( "player_changename" );
		if ( event )
		{
			event->SetInt( "userid", pPlayer->GetUserID() );
			event->SetString( "oldname", pszOldName );
			event->SetString( "newname", pszName );
			gameeventmanager->FireEvent( event );
		}
		
		pPlayer->SetPlayerName( pszName );
	}

	// NVNT see if this user is still or has began using a haptic device
	const char *pszHH = engine->GetClientConVarValue( pPlayer->entindex(), "hap_HasDevice" );
	if(pszHH)
	{
		int iHH = atoi(pszHH);
		pPlayer->SetHaptics(iHH!=0);
	}
}
void CWeaponBaseRifleGrenade::PrimaryAttack( void )
{
	CDODPlayer *pPlayer = ToDODPlayer( GetPlayerOwner() );

	Assert( pPlayer );

	// Out of ammo?
	if ( m_iClip1 <= 0 )
	{
		if (m_bFireOnEmpty)
		{
			PlayEmptySound();
			m_flNextPrimaryAttack = gpGlobals->curtime + 0.2;
		}
		return;
	}

	if( pPlayer->GetWaterLevel() > 2 )
	{
		PlayEmptySound();
		m_flNextPrimaryAttack = gpGlobals->curtime + 1.0;
		return;
	}

	// decrement before calling PlayPrimaryAttackAnim, so we can play the empty anim if necessary
	m_iClip1--;

	SendWeaponAnim( ACT_VM_PRIMARYATTACK );

	// player "shoot" animation
	pPlayer->SetAnimation( PLAYER_ATTACK1 );

#ifdef CLIENT_DLL
	if( pPlayer && !pPlayer->IsDormant() )
		pPlayer->DoAnimationEvent( PLAYERANIMEVENT_FIRE_GUN );
#else
	if( pPlayer )
		pPlayer->DoAnimationEvent( PLAYERANIMEVENT_FIRE_GUN );
#endif	

#ifndef CLIENT_DLL
	ShootGrenade();
#endif

	WeaponSound( SINGLE );

	DoFireEffects();

#ifdef CLIENT_DLL
	CDODPlayer *p = ToDODPlayer( GetPlayerOwner() );

	if( !p->m_Shared.IsInMGDeploy() )
	{
		if ( prediction->IsFirstTimePredicted() )
			p->DoRecoil( GetWeaponID(), m_pWeaponInfo->m_flRecoil );
	}
#endif

	m_flNextPrimaryAttack = m_flNextSecondaryAttack = gpGlobals->curtime + GetFireDelay();
	m_flTimeWeaponIdle = gpGlobals->curtime + m_pWeaponInfo->m_flTimeToIdleAfterFire;

#ifndef CLIENT_DLL
	IGameEvent * event = gameeventmanager->CreateEvent( "dod_stats_weapon_attack" );
	if ( event )
	{
		event->SetInt( "attacker", pPlayer->GetUserID() );
		event->SetInt( "weapon", GetStatsWeaponID() );

		gameeventmanager->FireEvent( event );
	}
#endif	//CLIENT_DLL
}
Ejemplo n.º 26
0
bool CASW_Weapon::ASWReload( int iClipSize1, int iClipSize2, int iActivity )
{
	if ( m_bInReload )	// we're already reloading!
	{
		Msg("ASWReload already reloading\n");
		Assert(false);
		return true;
	}

	CASW_Marine *pMarine = GetMarine();
	if ( !pMarine || !ASWGameRules() )
		return false;

	bool bReload = false;
	if ( m_bIsFiring )
	{
		OnStoppedFiring();
	}

	// If you don't have clips, then don't try to reload them.
	if ( UsesClipsForAmmo1() )
	{
		// need to reload primary clip?
		int primary	= MIN( iClipSize1 - m_iClip1, pMarine->GetAmmoCount( m_iPrimaryAmmoType ) );
		if ( primary != 0 )
		{
			bReload = true;
		}
		else
		{
			// check if we have an ammo bag we can take a clip from instead
			CASW_Weapon_Ammo_Bag* pAmmoBag = dynamic_cast<CASW_Weapon_Ammo_Bag*>( pMarine->GetASWWeapon( 0 ) );
			if ( !pAmmoBag )
			{
				pAmmoBag = dynamic_cast<CASW_Weapon_Ammo_Bag*>( pMarine->GetASWWeapon( 1 ) );
			}

			if ( pAmmoBag && pAmmoBag->CanGiveAmmoToWeapon( this ) )
			{
#ifdef CLIENT_DLL
				bReload = true;
#else
				pAmmoBag->GiveClipTo(pMarine, m_iPrimaryAmmoType, true);

				// now we've given a clip, check if we can reload
				primary	= MIN(iClipSize1 - m_iClip1, pMarine->GetAmmoCount(m_iPrimaryAmmoType));
				if ( primary != 0 )
				{
					bReload = true;
				}
#endif
			}
		}
	}

	if ( UsesClipsForAmmo2() )
	{
		// need to reload secondary clip?
		int secondary = MIN( iClipSize2 - m_iClip2, pMarine->GetAmmoCount( m_iSecondaryAmmoType ) );
		if ( secondary != 0 )
		{
			bReload = true;
		}
	}

	if ( !bReload )
		return false;

	m_bFastReloadSuccess = false;
	m_bFastReloadFailure = false;

#ifndef CLIENT_DLL
	if ( GetMaxClip1() > 1 )
	{
		// Fire event when a player reloads a weapon with more than a bullet per clip
		IGameEvent * event = gameeventmanager->CreateEvent( "weapon_reload" );
		if ( event )
		{		
			CASW_Player *pPlayer = NULL;
			pPlayer = pMarine->GetCommander();

			int nClipSize = GetMaxClip1();

			int nClips = pMarine->GetAmmoCount( m_iPrimaryAmmoType ) / nClipSize;
			CASW_Weapon_Ammo_Bag *pAmmoBag = dynamic_cast< CASW_Weapon_Ammo_Bag* >( pMarine->GetASWWeapon( 0 ) );
			if ( !pAmmoBag )
			{
				pAmmoBag = dynamic_cast< CASW_Weapon_Ammo_Bag* >( pMarine->GetASWWeapon( 1 ) );
			}
			if ( pAmmoBag && this != pAmmoBag )
			{
				nClips += pAmmoBag->NumClipsForWeapon( this );					
			}

			event->SetInt( "userid", ( pPlayer ? pPlayer->GetUserID() : 0 ) );
			event->SetInt( "marine", pMarine->entindex() );
			event->SetInt( "lost", m_iClip1 );
			event->SetInt( "clipsize", nClipSize );
			event->SetInt( "clipsremaining", nClips - 1 );
			event->SetInt( "clipsmax", GetAmmoDef()->MaxCarry( m_iPrimaryAmmoType, pMarine ) / nClipSize );

			gameeventmanager->FireEvent( event );
		}
	}
#endif

	m_fReloadClearFiringTime = gpGlobals->curtime + GetFireRate();

	float fReloadTime = GetReloadTime();
	float flSequenceEndTime = gpGlobals->curtime + fReloadTime;
	pMarine->SetNextAttack( flSequenceEndTime );
	m_flNextPrimaryAttack = m_flNextSecondaryAttack = flSequenceEndTime;
	//Msg("  Setting nextprimary attack time to %f from aswreload\n", m_flNextPrimaryAttack);

	m_bInReload = true;	

	// set fast reload timings
	//  assuming 2.8 base reload time
	//    ~0.29 
	RandomSeed( CBaseEntity::GetPredictionRandomSeed() & 255 );	

	float flStartFraction = random->RandomFloat( 0.29f, 0.35f );

	// set width by difficulty
	float flFastReloadWidth = 0.12f;
	switch( ASWGameRules()->GetSkillLevel() )
	{
		default:
		case 1: 
		case 2: flFastReloadWidth = random->RandomFloat( 0.10f, 0.1f ); break;		// easy/normal
		case 3: flFastReloadWidth = random->RandomFloat( 0.08f, 0.12f ); break;		// hard
		case 4: flFastReloadWidth = random->RandomFloat( 0.06f, 0.10f ); break;		// insane
		case 5: flFastReloadWidth = random->RandomFloat( 0.055f, 0.09f ); break;		// imba
	}
	// scale by marine skills
	flFastReloadWidth *= MarineSkills()->GetSkillBasedValueByMarine( pMarine, ASW_MARINE_SKILL_RELOADING, ASW_MARINE_SUBSKILL_RELOADING_FAST_WIDTH_SCALE );
	
	m_fReloadStart = gpGlobals->curtime;
	m_fFastReloadStart = gpGlobals->curtime + flStartFraction * fReloadTime;
	m_fFastReloadEnd = m_fFastReloadStart + flFastReloadWidth * fReloadTime;

	SendReloadEvents();

#ifdef GAME_DLL
	pMarine->RemoveWeaponPowerup( this );
#endif

	return true;
}
Ejemplo n.º 27
0
//=========================================================
// Deathnotice.
//=========================================================
void CHL2MPRules::DeathNotice( CBasePlayer *pVictim, const CTakeDamageInfo &info )
{
#ifndef CLIENT_DLL
    // Work out what killed the player, and send a message to all clients about it
    const char *killer_weapon_name = "world";		// by default, the player is killed by the world
    int killer_ID = 0;

    // Find the killer & the scorer
    CBaseEntity *pInflictor = info.GetInflictor();
    CBaseEntity *pKiller = info.GetAttacker();
    CBasePlayer *pScorer = GetDeathScorer( pKiller, pInflictor );

    // Custom kill type?
    if ( info.GetDamageCustom() )
    {
        killer_weapon_name = GetDamageCustomString( info );
        if ( pScorer )
        {
            killer_ID = pScorer->GetUserID();
        }
    }
    else
    {
        // Is the killer a client?
        if ( pScorer )
        {
            killer_ID = pScorer->GetUserID();

            if ( pInflictor )
            {
                if ( pInflictor == pScorer )
                {
                    // If the inflictor is the killer,  then it must be their current weapon doing the damage
                    if ( pScorer->GetActiveWeapon() )
                    {
                        killer_weapon_name = pScorer->GetActiveWeapon()->GetClassname();
                    }
                }
                else
                {
                    killer_weapon_name = pInflictor->GetClassname();  // it's just that easy
                }
            }
        }
        else
        {
            killer_weapon_name = pInflictor->GetClassname();
        }

        // strip the NPC_* or weapon_* from the inflictor's classname
        if ( strncmp( killer_weapon_name, "weapon_", 7 ) == 0 )
        {
            killer_weapon_name += 7;
        }
        else if ( strncmp( killer_weapon_name, "npc_", 4 ) == 0 )
        {
            killer_weapon_name += 4;
        }
        else if ( strncmp( killer_weapon_name, "func_", 5 ) == 0 )
        {
            killer_weapon_name += 5;
        }
        else if ( strstr( killer_weapon_name, "physics" ) )
        {
            killer_weapon_name = "physics";
        }

        if ( strcmp( killer_weapon_name, "prop_combine_ball" ) == 0 )
        {
            killer_weapon_name = "combine_ball";
        }
        else if ( strcmp( killer_weapon_name, "grenade_ar2" ) == 0 )
        {
            killer_weapon_name = "smg1_grenade";
        }
        else if ( strcmp( killer_weapon_name, "satchel" ) == 0 || strcmp( killer_weapon_name, "tripmine" ) == 0)
        {
            killer_weapon_name = "slam";
        }


    }

    IGameEvent *event = gameeventmanager->CreateEvent( "player_death" );
    if( event )
    {
        event->SetInt("userid", pVictim->GetUserID() );
        event->SetInt("attacker", killer_ID );
        event->SetString("weapon", killer_weapon_name );
        event->SetInt( "priority", 7 );
        gameeventmanager->FireEvent( event );
    }
#endif

}
Ejemplo n.º 28
0
void CASW_Weapon_Medkit::SelfHeal()
{
	CASW_Marine *pMarine = GetMarine();

	if (pMarine)		// firing from a marine
	{
		if (pMarine->GetHealth() >= pMarine->GetMaxHealth())		// already on full health
			return;

		if (pMarine->GetHealth() <= 0)		// aleady dead!
			return;

		if (pMarine->m_bSlowHeal)			// already healing
			return;

		if (pMarine->GetFlags() & FL_FROZEN)	// don't allow this if the marine is frozen
			return;

		// MUST call sound before removing a round from the clip of a CMachineGun
		WeaponSound(SINGLE);

		// sets the animation on the weapon model iteself
		SendWeaponAnim( GetPrimaryAttackActivity() );

		// sets the animation on the marine holding this weapon
		//pMarine->SetAnimation( PLAYER_ATTACK1 );
#ifndef CLIENT_DLL
		bool bMedic = (pMarine->GetMarineProfile() && pMarine->GetMarineProfile()->CanUseFirstAid());
		// put a slow heal onto the marine, play a particle effect
		if (!pMarine->m_bSlowHeal && pMarine->GetHealth() < pMarine->GetMaxHealth())
		{
			pMarine->AddSlowHeal( GetHealAmount(), 1, pMarine, this );

			// Fire event
			IGameEvent * event = gameeventmanager->CreateEvent( "player_heal" );
			if ( event )
			{
				CASW_Player *pPlayer = GetCommander();
				event->SetInt( "userid", ( pPlayer ? pPlayer->GetUserID() : 0 ) );
				event->SetInt( "entindex", pMarine->entindex() );
				gameeventmanager->FireEvent( event );
			}

			if ( ASWGameRules()->GetInfoHeal() )
			{
				ASWGameRules()->GetInfoHeal()->OnMarineHealed( pMarine, pMarine, this );

			}
			pMarine->OnWeaponFired( this, 1 );
		}
		
		if (pMarine->IsInfested() && bMedic)
		{
			float fCure = GetInfestationCureAmount();
			// cure infestation
			if (fCure < 100)
				pMarine->CureInfestation(pMarine, fCure);
		}
#endif
		// decrement ammo
		m_iClip1 -= 1;

#ifndef CLIENT_DLL
		DestroyIfEmpty( false );
#endif
	}
}
Ejemplo n.º 29
0
//-----------------------------------------------------------------------------
// Purpose: Breaks the breakable. m_hBreaker is the entity that caused us to break.
//-----------------------------------------------------------------------------
void CBreakable::Die( void )
{
	Vector vecVelocity;// shard velocity
	char cFlag = 0;
	int pitch;
	float fvol;
	
	pitch = 95 + random->RandomInt(0,29);

	if (pitch > 97 && pitch < 103)
	{
		pitch = 100;
	}

	// The more negative m_iHealth, the louder
	// the sound should be.

	fvol = random->RandomFloat(0.85, 1.0) + (abs(m_iHealth) / 100.0);
	if (fvol > 1.0)
	{
		fvol = 1.0;
	}

	const char *soundname = NULL;

	switch (m_Material)
	{
	default:
		break;

	case matGlass:
		soundname = "Breakable.Glass";
		cFlag = BREAK_GLASS;
		break;

	case matWood:
		soundname = "Breakable.Crate";
		cFlag = BREAK_WOOD;
		break;

	case matComputer:
		soundname = "Breakable.Computer";
		cFlag = BREAK_METAL;
		break;

	case matMetal:
		soundname = "Breakable.Metal";
		cFlag = BREAK_METAL;
		break;

	case matFlesh:
	case matWeb:
		soundname = "Breakable.Flesh";
		cFlag = BREAK_FLESH;
		break;

	case matRocks:
	case matCinderBlock:
		soundname = "Breakable.Concrete";
		cFlag = BREAK_CONCRETE;
		break;

	case matCeilingTile:
		soundname = "Breakable.Ceiling";
		break;
	}

	if ( soundname )
	{
		if ( m_hBreaker && m_hBreaker->IsPlayer() )
		{
			IGameEvent * event = gameeventmanager->CreateEvent( "break_breakable" );
			if ( event )
			{
				event->SetInt( "userid", ToBasePlayer( m_hBreaker )->GetUserID() );
				event->SetInt( "entindex", entindex() );
				event->SetInt( "material", cFlag );
				gameeventmanager->FireEvent( event );
			}
		}

		CSoundParameters params;
		if ( GetParametersForSound( soundname, params, NULL ) )
		{
			CPASAttenuationFilter filter( this );

			EmitSound_t ep;
			ep.m_nChannel = params.channel;
			ep.m_pSoundName = params.soundname;
			ep.m_flVolume = fvol;
			ep.m_SoundLevel = params.soundlevel;
			ep.m_nPitch = pitch;

			EmitSound( filter, entindex(), ep );	
		}
	}
		
	switch( m_Explosion )
	{
	case expDirected:
		vecVelocity = g_vecAttackDir * -200;
		break;

	case expUsePrecise:
		{
			AngleVectors( m_GibDir, &vecVelocity, NULL, NULL );
			vecVelocity *= 200;
		}
		break;

	case expRandom:
		vecVelocity.x = 0;
		vecVelocity.y = 0;
		vecVelocity.z = 0;
		break;

	default:
		DevMsg("**ERROR - Unspecified gib dir method in func_breakable!\n");
		break;
	}

	Vector vecSpot = WorldSpaceCenter();
	CPVSFilter filter2( vecSpot );

	int iModelIndex = 0;
	CCollisionProperty *pCollisionProp = CollisionProp();

	Vector vSize = pCollisionProp->OBBSize();
	int iCount = ( vSize[0] * vSize[1] + vSize[1] * vSize[2] + vSize[2] * vSize[0] ) / ( 3 * 12 * 12 );

	if ( iCount > func_break_max_pieces.GetInt() )
	{
		iCount = func_break_max_pieces.GetInt();
	}

	ConVarRef breakable_disable_gib_limit( "breakable_disable_gib_limit" );
	if ( !breakable_disable_gib_limit.GetBool() && iCount )
	{
		if ( m_PerformanceMode == PM_NO_GIBS )
		{
			iCount = 0;
		}
		else if ( m_PerformanceMode == PM_REDUCED_GIBS )
		{
			int iNewCount = iCount * func_break_reduction_factor.GetFloat();
			iCount = MAX( iNewCount, 1 );
		}
	}

	if ( m_iszModelName != NULL_STRING )
	{
		for ( int i = 0; i < iCount; i++ )
		{

	#ifdef HL1_DLL
			// Use the passed model instead of the propdata type
			const char *modelName = STRING( m_iszModelName );
			
			// if the map specifies a model by name
			if( strstr( modelName, ".mdl" ) != NULL )
			{
				iModelIndex = modelinfo->GetModelIndex( modelName );
			}
			else	// do the hl2 / normal way
	#endif

			iModelIndex = modelinfo->GetModelIndex( g_PropDataSystem.GetRandomChunkModel(  STRING( m_iszModelName ) ) );

			// All objects except the first one in this run are marked as slaves...
			int slaveFlag = 0;
			if ( i != 0 )
			{
				slaveFlag = BREAK_SLAVE;
			}

			te->BreakModel( filter2, 0.0, 
				vecSpot, pCollisionProp->GetCollisionAngles(), vSize, 
				vecVelocity, iModelIndex, 100, 1, 2.5, cFlag | slaveFlag );
		}
	}

	ResetOnGroundFlags();

	// Don't fire something that could fire myself
	SetName( NULL_STRING );

	AddSolidFlags( FSOLID_NOT_SOLID );
	
	// Fire targets on break
	m_OnBreak.FireOutput( m_hBreaker, this );

	VPhysicsDestroyObject();
	SetThink( &CBreakable::SUB_Remove );
	SetNextThink( gpGlobals->curtime + 0.1f );
	if ( m_iszSpawnObject != NULL_STRING )
	{
		CBaseEntity::Create( STRING(m_iszSpawnObject), vecSpot, pCollisionProp->GetCollisionAngles(), this );
	}

	if ( Explodable() )
	{
		ExplosionCreate( vecSpot, pCollisionProp->GetCollisionAngles(), this, GetExplosiveDamage(), GetExplosiveRadius(), true );
	}
}
Ejemplo n.º 30
0
	//=========================================================
	// Deathnotice. 
	//=========================================================
	void CMultiplayRules::DeathNotice( CBasePlayer *pVictim, const CTakeDamageInfo &info )
	{
		// Work out what killed the player, and send a message to all clients about it
		const char *killer_weapon_name = "world";		// by default, the player is killed by the world
		int killer_ID = 0;

		// Find the killer & the scorer
		CBaseEntity *pInflictor = info.GetInflictor();
		CBaseEntity *pKiller = info.GetAttacker();
		CBasePlayer *pScorer = GetDeathScorer( pKiller, pInflictor, pVictim );

		// Custom damage type?
		if ( info.GetDamageCustom() )
		{
			killer_weapon_name = GetDamageCustomString( info );
			if ( pScorer )
			{
				killer_ID = pScorer->GetUserID();
			}
		}
		else
		{
			// Is the killer a client?
			if ( pScorer )
			{
				killer_ID = pScorer->GetUserID();
				
				if ( pInflictor )
				{
					if ( pInflictor == pScorer )
					{
						// If the inflictor is the killer,  then it must be their current weapon doing the damage
						if ( pScorer->GetActiveWeapon() )
						{
							killer_weapon_name = pScorer->GetActiveWeapon()->GetDeathNoticeName();
						}
					}
					else
					{
						killer_weapon_name = STRING( pInflictor->m_iClassname );  // it's just that easy
					}
				}
			}
			else
			{
				killer_weapon_name = STRING( pInflictor->m_iClassname );
			}

			// strip the NPC_* or weapon_* from the inflictor's classname
			if ( strncmp( killer_weapon_name, "weapon_", 7 ) == 0 )
			{
				killer_weapon_name += 7;
			}
			else if ( strncmp( killer_weapon_name, "NPC_", 8 ) == 0 )
			{
				killer_weapon_name += 8;
			}
			else if ( strncmp( killer_weapon_name, "func_", 5 ) == 0 )
			{
				killer_weapon_name += 5;
			}
		}

		IGameEvent * event = gameeventmanager->CreateEvent( "player_death" );
		if ( event )
		{
			event->SetInt("userid", pVictim->GetUserID() );
			event->SetInt("attacker", killer_ID );
			event->SetInt("customkill", info.GetDamageCustom() );
			event->SetInt("priority", 7 );	// HLTV event priority, not transmitted
			
			gameeventmanager->FireEvent( event );
		}

	}