Ejemplo n.º 1
0
void CSourcePanel::PhysicsAreaSelectedCallback(const tstring& sArgs)
{
	if (m_pPhysicsShapes->GetSelectedNodeId() < ToyEditor()->GetToy().m_aShapes.size())
	{
		Manipulator()->Activate(ToyEditor(), ToyEditor()->GetToy().m_aShapes[m_pPhysicsShapes->GetSelectedNodeId()].m_trsTransform, "PhysicsShape " + sprintf("%d", m_pPhysicsShapes->GetSelectedNodeId()));
		m_pDeletePhysicsShape->SetEnabled(true);
	}
	else
	{
		Manipulator()->Deactivate();
		m_pDeletePhysicsShape->SetEnabled(false);
	}
}
Ejemplo n.º 2
0
void CEditorPanel::PropertyChangedCallback(const tstring& sArgs)
{
    CLevelEntity* pEntity = GetCurrentEntity();
    if (!pEntity)
        return;

    if (pEntity)
    {
        CLevelEditor::PopulateLevelEntityFromPanel(pEntity, m_hPropertiesPanel);

        if (Manipulator()->IsActive())
            Manipulator()->SetTRS(pEntity->GetGlobalTRS());
    }
}
Ejemplo n.º 3
0
void CEditorPanel::EntitySelectedCallback(const tstring& sArgs)
{
    LayoutEntity();

    LevelEditor()->EntitySelected();

    CLevel* pLevel = LevelEditor()->GetLevel();

    if (!pLevel)
        return;

    auto& aEntities = pLevel->GetEntityData();

    if (m_hEntities->GetSelectedNodeId() < aEntities.size())
    {
        Manipulator()->Activate(LevelEditor(), aEntities[m_hEntities->GetSelectedNodeId()].GetGlobalTRS(), "Entity " + sprintf("%d", m_hEntities->GetSelectedNodeId()));
    }
    else
    {
        Manipulator()->Deactivate();
    }
}
Ejemplo n.º 4
0
void CToyEditor::ManipulatorUpdated(const tstring& sArguments)
{
	// Grab this before GetToyToModify since that does a layout and clobbers the list.
	size_t iSelected = m_pSourcePanel->m_pPhysicsShapes->GetSelectedNodeId();

	tvector<tstring> asTokens;
	strtok(sArguments, asTokens);
	TAssert(asTokens.size() == 2);
	TAssert(stoi(asTokens[1]) == iSelected);
	TAssert(iSelected != ~0);

	if (iSelected >= ToyEditor()->GetToy().m_aShapes.size())
		return;

	ToyEditor()->GetToyToModify().m_aShapes[iSelected].m_trsTransform = Manipulator()->GetTRS();
}
/// Helper function for Fire() -- actually emit the "bullets" of flame or ice
void CASW_Sentry_Top_Flamer::FireProjectiles( int numShotsToFire, ///< number of pellets to fire this frame
											  const Vector &vecSrc, ///< origin for bullets
											  const Vector &vecAiming, ///< aim direction for bullets
											  const AngularImpulse &rotSpeed )
{
	CShotManipulator Manipulator( vecAiming );
	CASW_Marine * RESTRICT const pMarineDeployer = GetSentryBase()->m_hDeployer.Get();
	Assert( pMarineDeployer );

	for ( int i = 0 ; i < numShotsToFire ; i++ )
	{
		// create a pellet at some random spread direction		
		Vector projectileVel = Manipulator.GetShotDirection(); // Manipulator.ApplySpread(GetBulletSpread());

		projectileVel *= GetProjectileVelocity();
		projectileVel *= (1.0 + (0.1 * random->RandomFloat(-1,1)));
		CASW_Flamer_Projectile *pFlames = CASW_Flamer_Projectile::Flamer_Projectile_Create( GetSentryDamage(), 
			vecSrc + (projectileVel.Normalized() * BoundingRadius()), QAngle(0,0,0),	projectileVel, rotSpeed, 
			this, pMarineDeployer, this );

		pFlames->SetHurtIgnited( true );
	}
}
Ejemplo n.º 6
0
void CASW_Weapon_Buff_Grenade::PrimaryAttack( void )
{	
	// Only the player fires this way so we can cast
	CASW_Player *pPlayer = GetCommander();

	if (!pPlayer)
		return;

	CASW_Marine *pMarine = GetMarine();
#ifndef CLIENT_DLL
	bool bThisActive = (pMarine && pMarine->GetActiveWeapon() == this);
#endif

	// mine weapon is lost when all mines are gone
	if ( UsesClipsForAmmo1() && !m_iClip1 ) 
	{
		//Reload();
#ifndef CLIENT_DLL
		if (pMarine)
		{
			pMarine->Weapon_Detach(this);
			if (bThisActive)
				pMarine->SwitchToNextBestWeapon(NULL);
		}
		Kill();
#endif
		return;
	}

	if ( !pMarine || pMarine->GetWaterLevel() == 3 )
		return;

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

	// tell the marine to tell its weapon to draw the muzzle flash
	//pMarine->DoMuzzleFlash();

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

	//pMarine->DoAnimationEvent(PLAYERANIMEVENT_HEAL);

	// sets the animation on the marine holding this weapon
	//pMarine->SetAnimation( PLAYER_ATTACK1 );
#ifndef CLIENT_DLL
	Vector	vecSrc		= pMarine->Weapon_ShootPosition( );
	Vector	vecAiming	= pPlayer->GetAutoaimVectorForMarine(pMarine, GetAutoAimAmount(), GetVerticalAdjustOnlyAutoAimAmount());	// 45 degrees = 0.707106781187
	
	if ( !pMarine->IsInhabited() && vecSrc.DistTo( pMarine->m_vecOffhandItemSpot ) < 150.0f )
	{
		vecSrc.x = pMarine->m_vecOffhandItemSpot.x;
		vecSrc.y = pMarine->m_vecOffhandItemSpot.y;
		vecSrc.z += 50.0f;
	}

	QAngle ang = pPlayer->EyeAngles();
	ang.x = 0;
	ang.z = 0;
	CShotManipulator Manipulator( vecAiming );
	AngularImpulse rotSpeed(0,0,720);
	
	// create a pellet at some random spread direction			
	Vector newVel = Manipulator.ApplySpread(GetBulletSpread());

	newVel *= ASW_MINE_VELOCITY;
	if ( !pMarine->IsInhabited() )
	{
		newVel = vec3_origin;
	}

	float flRadius = asw_damage_amp_radius.GetFloat();
	float flDuration = asw_damage_amp_duration.GetFloat();
	CASW_BuffGrenade_Projectile::Grenade_Projectile_Create( vecSrc, ang, newVel, rotSpeed, pMarine, flRadius, flDuration );

	pMarine->OnWeaponFired( this, 1 );

	pMarine->GetMarineSpeech()->Chatter(CHATTER_MINE_DEPLOYED);
#endif
	// decrement ammo
	m_iClip1 -= 1;

#ifndef CLIENT_DLL
	DestroyIfEmpty( true );
#endif

	m_flSoonestPrimaryAttack = gpGlobals->curtime + ASW_FLARES_FASTEST_REFIRE_TIME;
	if (m_iClip1 > 0)		// only force the fire wait time if we have ammo for another shot
		m_flNextPrimaryAttack = gpGlobals->curtime + GetFireRate();
	else
		m_flNextPrimaryAttack = gpGlobals->curtime;
}
void CASW_Weapon_HealGrenade::PrimaryAttack( void )
{	
	CASW_Player *pPlayer = GetCommander();
	if (!pPlayer)
		return;

	CASW_Marine *pMarine = GetMarine();
#ifndef CLIENT_DLL
	bool bThisActive = (pMarine && pMarine->GetActiveWeapon() == this);
#endif

	if ( !pMarine )
		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
	Vector	vecSrc		= pMarine->Weapon_ShootPosition( );
	Vector	vecAiming	= pPlayer->GetAutoaimVectorForMarine(pMarine, GetAutoAimAmount(), GetVerticalAdjustOnlyAutoAimAmount());	// 45 degrees = 0.707106781187

	if ( !pMarine->IsInhabited() && vecSrc.DistTo( pMarine->m_vecOffhandItemSpot ) < 150.0f )
	{
		vecSrc.x = pMarine->m_vecOffhandItemSpot.x;
		vecSrc.y = pMarine->m_vecOffhandItemSpot.y;
		vecSrc.z += 50.0f;
	}

	QAngle ang = pPlayer->EyeAngles();
	ang.x = 0;
	ang.z = 0;
	CShotManipulator Manipulator( vecAiming );
	AngularImpulse rotSpeed(0,0,720);

	// create a pellet at some random spread direction			
	Vector newVel = Manipulator.ApplySpread(GetBulletSpread());
	if ( pMarine->GetWaterLevel() != 3 )
	{
		CreateProjectile( vecSrc, ang, newVel, rotSpeed, pMarine );
		pMarine->OnWeaponFired( this, 1 );
	}

	pMarine->GetMarineSpeech()->Chatter(CHATTER_MEDKIT);
#endif

	// decrement ammo
	m_iClip1 -= 1;

#ifndef CLIENT_DLL
	// destroy if empty
	if ( UsesClipsForAmmo1() && !m_iClip1 ) 
	{
		ASWFailAdvice()->OnMedSatchelEmpty();

		pMarine->GetMarineSpeech()->Chatter( CHATTER_MEDS_NONE );

		if ( pMarine )
		{
			pMarine->Weapon_Detach(this);
			if ( bThisActive )
				pMarine->SwitchToNextBestWeapon(NULL);
		}
		Kill();

		return;
	}
#endif

	m_flSoonestPrimaryAttack = gpGlobals->curtime + GetRefireTime();
	if (m_iClip1 > 0)		// only force the fire wait time if we have ammo for another shot
		m_flNextPrimaryAttack = gpGlobals->curtime + GetFireRate();
	else
		m_flNextPrimaryAttack = gpGlobals->curtime;

	//m_flLastFireTime = gpGlobals->curtime;
}
Ejemplo n.º 8
0
void CGizmoTransformMove::Draw()
{
	ComputeScreenFactor();

	if (m_pMatrix)
	{
		CRenderingContext c(Manipulator()->GetRenderer(), true);
		c.UseProgram("model");
		c.SetUniform("bDiffuse", false);

		//glDisable(GL_DEPTH_TEST);
		tvector3 orig = m_pMatrix->GetTranslation();

		tvector3 axeX(1,0,0),axeY(0,1,0),axeZ(0,0,1);


        if (mLocation == LOCATE_LOCAL)
        {
            axeX.TransformVector(*m_pMatrix);
		    axeY.TransformVector(*m_pMatrix);
		    axeZ.TransformVector(*m_pMatrix);
		    axeX.Normalize();
		    axeY.Normalize();
		    axeZ.Normalize();
        }




		DrawQuad(&c, orig, 0.5f*GetScreenFactor(), (m_MoveTypePredict == MOVE_XZ), axeX, axeZ);
		DrawQuad(&c, orig, 0.5f*GetScreenFactor(), (m_MoveTypePredict == MOVE_XY), axeX, axeY);
		DrawQuad(&c, orig, 0.5f*GetScreenFactor(), (m_MoveTypePredict == MOVE_YZ), axeY, axeZ);

		axeX*=GetScreenFactor();
		axeY*=GetScreenFactor();
		axeZ*=GetScreenFactor();

		// plan1
		if (m_MoveTypePredict != MOVE_X)
			DrawAxis(&c, orig,axeX,axeY,axeZ,0.05f,0.83f,vector4(1,0,0,1));
		else
			DrawAxis(&c, orig,axeX,axeY,axeZ, 0.05f,0.83f,vector4(1,1,1,1));

		//plan2
		if (m_MoveTypePredict != MOVE_Y)
			DrawAxis(&c, orig,axeY,axeX,axeZ, 0.05f,0.83f,vector4(0,1,0,1));
		else
			DrawAxis(&c, orig,axeY,axeX,axeZ, 0.05f,0.83f,vector4(1,1,1,1));

		//plan3
		if (m_MoveTypePredict != MOVE_Z)
			DrawAxis(&c, orig,axeZ,axeX,axeY, 0.05f,0.83f,vector4(0,0,1,1));
		else
			DrawAxis(&c, orig,axeZ,axeX,axeY, 0.05f,0.83f,vector4(1,1,1,1));
#if 0
#ifdef WIN32
    GDD->GetD3D9Device()->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
    GDD->GetD3D9Device()->SetRenderState(D3DRS_CULLMODE , D3DCULL_NONE );
    GDD->GetD3D9Device()->SetRenderState(D3DRS_ZENABLE , D3DZB_TRUE);
	GDD->GetD3D9Device()->SetRenderState(D3DRS_ALPHATESTENABLE , FALSE);
	GDD->GetD3D9Device()->SetRenderState(D3DRS_ZWRITEENABLE , TRUE);
#endif
	extern RenderingState_t GRenderingState;
	GRenderingState.mAlphaTestEnable = 0;
	GRenderingState.mZWriteEnable = 1;
	GRenderingState.mBlending = 0;
	GRenderingState.mCulling = 0;
	GRenderingState.mZTestType = 1;
#endif
/*

PSM_LVERTEX svVts[2];
	svVts[0].x = ptd.x;
    svVts[0].y = ptd.y;
    svVts[0].z = ptd.z;
    svVts[0].diffuse = 0xFFFFFFFF;

	svVts[1].x = ptd.x+10;
    svVts[1].y = ptd.y+10;
    svVts[1].z = ptd.z+10;
    svVts[1].diffuse = 0xFFFFFFFF;


    IDirect3DDevice9 *pDev = ((PSM_D3D9RenderDevice*)PSM_D3D9RenderDevice::GetInterfacePtr())->d3dDevice;
	pDev->DrawPrimitiveUP(D3DPT_LINESTRIP , 1, svVts, sizeof(PSM_LVERTEX));
    */
}
/*
		// debug
		glPointSize(20);
		glBegin(GL_POINTS);
		glVertex3fv(&ptd.x);
		glEnd();

		glEnable(GL_DEPTH_TEST);
*/

}
void C_TEHL2MPFireBullets::CreateEffects( void )
{
	CAmmoDef*	pAmmoDef	= GetAmmoDef();

	if ( pAmmoDef == NULL )
		 return;

	C_BaseEntity *pEnt = ClientEntityList().GetEnt( m_iPlayer );

	if ( pEnt )
	{
		C_BasePlayer *pPlayer = dynamic_cast<C_BasePlayer *>(pEnt);

		if ( pPlayer && pPlayer->GetActiveWeapon() )
		{
			C_BaseCombatWeapon *pWpn = dynamic_cast<C_BaseCombatWeapon *>( pPlayer->GetActiveWeapon() );

			if ( pWpn )
			{
				int iSeed = m_iSeed;
					
				CShotManipulator Manipulator( m_vecDir );

				for (int iShot = 0; iShot < m_iShots; iShot++)
				{
					RandomSeed( iSeed );	// init random system with this seed

					// Don't run the biasing code for the player at the moment.
					Vector vecDir = Manipulator.ApplySpread( Vector( m_flSpread, m_flSpread, m_flSpread ) );
					Vector vecEnd = m_vecOrigin + vecDir * MAX_TRACE_LENGTH;
					trace_t tr;
					CTraceFilterSkipPlayerAndViewModelOnly traceFilter;

					if( m_iShots > 1 && iShot % 2 )
					{
						// Half of the shotgun pellets are hulls that make it easier to hit targets with the shotgun.
						UTIL_TraceHull( m_vecOrigin, vecEnd, Vector( -3, -3, -3 ), Vector( 3, 3, 3 ), MASK_SHOT, &traceFilter, &tr );
					}
					else
					{
						UTIL_TraceLine( m_vecOrigin, vecEnd, MASK_SHOT, &traceFilter, &tr);
					}

					if ( m_bDoTracers )
					{
						const char *pTracerName = pWpn->GetTracerType();

						CEffectData data;
						data.m_vStart = tr.startpos;
						data.m_vOrigin = tr.endpos;
						data.m_hEntity = pWpn->GetRefEHandle();
						data.m_flScale = 0.0f;
						data.m_fFlags |= TRACER_FLAG_USEATTACHMENT;
						// Stomp the start, since it's not going to be used anyway
						data.m_nAttachmentIndex = 1;

						if ( pTracerName )
						{
							DispatchEffect( pTracerName, data );
						}
						else
						{
							DispatchEffect( "Tracer", data );
						}
					}
					
					if ( m_bDoImpacts )
					{
						pWpn->DoImpactEffect( tr, pAmmoDef->DamageType( m_iAmmoID ) );
					}

					iSeed++;
				}
			}
		}
	}

}
Ejemplo n.º 10
0
void CASW_Weapon_T75::PrimaryAttack( void )
{	
	// Only the player fires this way so we can cast
	CASW_Player *pPlayer = GetCommander();
	if (!pPlayer)
		return;

	CASW_Marine *pMarine = GetMarine();
#ifndef CLIENT_DLL
	bool bThisActive = (pMarine && pMarine->GetActiveWeapon() == this);
#endif

	// weapon is lost when all charges are gone
	if ( UsesClipsForAmmo1() && !m_iClip1 ) 
	{
		//Reload();
#ifndef CLIENT_DLL
		if (pMarine)
		{
			pMarine->Weapon_Detach(this);
			if (bThisActive)
				pMarine->SwitchToNextBestWeapon(NULL);
		}
		Kill();
#endif
		return;
	}

	if ( !pMarine || pMarine->GetWaterLevel() == 3 )		// firing from a marine
		return;

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

#ifndef CLIENT_DLL
	Vector	vecSrc		= pMarine->Weapon_ShootPosition( );
	// TODO: Fix for AI
	Vector	vecAiming	= pPlayer->GetAutoaimVectorForMarine(pMarine, GetAutoAimAmount(), GetVerticalAdjustOnlyAutoAimAmount());

	if ( !pMarine->IsInhabited() && vecSrc.DistTo( pMarine->m_vecOffhandItemSpot ) < 150.0f )
	{
		vecSrc.x = pMarine->m_vecOffhandItemSpot.x;
		vecSrc.y = pMarine->m_vecOffhandItemSpot.y;
		vecSrc.z += 50.0f;
	}
	
	QAngle ang = pPlayer->EyeAngles();
	ang.x = 0;
	ang.z = 0;
	CShotManipulator Manipulator( vecAiming );
	AngularImpulse rotSpeed(0,0,720);
			
	Vector newVel = Manipulator.ApplySpread(GetBulletSpread());

	newVel *= ASW_MINE_VELOCITY;

	if ( !pMarine->IsInhabited() )
	{
		newVel = vec3_origin;
	}

	CASW_T75 *pT75 = CASW_T75::ASW_T75_Create( vecSrc, ang, newVel, rotSpeed, pMarine, this );
	if ( pT75 && !pMarine->IsInhabited() )
	{
		pT75->ActivateUseIcon( pMarine, ASW_USE_RELEASE_QUICK );
	}

	//pMarine->GetMarineSpeech()->Chatter(CHATTER_MINE_DEPLOYED);
#endif
	// decrement ammo
	m_iClip1 -= 1;

#ifndef CLIENT_DLL
	DestroyIfEmpty( true );
#endif

	m_flSoonestPrimaryAttack = gpGlobals->curtime + ASW_FLARES_FASTEST_REFIRE_TIME;
	if (m_iClip1 > 0)		// only force the fire wait time if we have ammo for another shot
		m_flNextPrimaryAttack = gpGlobals->curtime + GetFireRate();
	else
		m_flNextPrimaryAttack = gpGlobals->curtime;
}
void CASW_Weapon_Shotgun::PrimaryAttack( void )
{
	// If my clip is empty (and I use clips) start reload
	if ( UsesClipsForAmmo1() && !m_iClip1 ) 
	{
		Reload();
		return;
	}

	CASW_Player *pPlayer = GetCommander();
	CASW_Marine *pMarine = GetMarine();

	if (pMarine)		// firing from a marine
	{
		// MUST call sound before removing a round from the clip of a CMachineGun
		WeaponSound(SINGLE);
		if (m_iClip1 <= AmmoClickPoint())
		{
			LowAmmoSound();
		}

		m_bIsFiring = true;

		// tell the marine to tell its weapon to draw the muzzle flash
		pMarine->DoMuzzleFlash();

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

#ifdef GAME_DLL	// check for turning on lag compensation
		if (pPlayer && pMarine->IsInhabited())
		{
			CASW_Lag_Compensation::RequestLagCompensation( pPlayer, pPlayer->GetCurrentUserCommand() );
		}
#endif

		Vector vecSrc = pMarine->Weapon_ShootPosition( );
		// hull trace out to this shoot position, so we can be sure we're not firing from over an alien's head
		trace_t tr;
		CTraceFilterSimple tracefilter(pMarine, COLLISION_GROUP_NONE);
		Vector vecMarineMiddle(pMarine->GetAbsOrigin());
		vecMarineMiddle.z = vecSrc.z;
		AI_TraceHull( vecMarineMiddle, vecSrc, Vector( -10, -10, -20 ), Vector( 10, 10, 10 ), MASK_SHOT, &tracefilter, &tr );
		vecSrc = tr.endpos;

		Vector vecAiming = vec3_origin;
		if ( pPlayer && pMarine->IsInhabited() )
		{
			vecAiming = pPlayer->GetAutoaimVectorForMarine(pMarine, GetAutoAimAmount(), GetVerticalAdjustOnlyAutoAimAmount());	// 45 degrees = 0.707106781187
		}
		else
		{
#ifndef CLIENT_DLL
			vecAiming = pMarine->GetActualShootTrajectory( vecSrc );
#endif
		}

		if (true)		// hitscan pellets
		{

#ifndef CLIENT_DLL
			if (asw_DebugAutoAim.GetBool())
			{
				NDebugOverlay::Line(vecSrc, vecSrc + vecAiming * asw_weapon_max_shooting_distance.GetFloat(), 64, 0, 64, false, 120.0);
			}
#endif
			int iPellets = GetNumPellets();
			for (int i=0;i<iPellets;i++)
			{
				FireBulletsInfo_t info( 1, vecSrc, vecAiming, GetAngularBulletSpread(), asw_weapon_max_shooting_distance.GetFloat(), m_iPrimaryAmmoType );
				info.m_pAttacker = pMarine;
				info.m_iTracerFreq = 1;
				info.m_nFlags = FIRE_BULLETS_NO_PIERCING_SPARK | FIRE_BULLETS_HULL | FIRE_BULLETS_ANGULAR_SPREAD;
				info.m_flDamage = GetWeaponDamage();
				info.m_flDamageForceScale = asw_weapon_force_scale.GetFloat();
	#ifndef CLIENT_DLL
				if (asw_debug_marine_damage.GetBool())
					Msg("Weapon dmg = %f\n", info.m_flDamage);
				info.m_flDamage *= pMarine->GetMarineResource()->OnFired_GetDamageScale();
	#endif
				// shotgun bullets have a base 50% chance of piercing
				//float fPiercingChance = 0.5f;
				//if (pMarine->GetMarineResource() && pMarine->GetMarineProfile() && pMarine->GetMarineProfile()->GetMarineClass() == MARINE_CLASS_SPECIAL_WEAPONS)
					//fPiercingChance += MarineSkills()->GetSkillBasedValueByMarine(pMarine, ASW_MARINE_SKILL_PIERCING);
				
				//pMarine->FirePenetratingBullets(info, 5, fPiercingChance);

				//pMarine->FirePenetratingBullets(info, 5, 1.0f, i, false );
				pMarine->FirePenetratingBullets(info, 0, 1.0f, i, false );
			}
		}
		else	// projectile pellets
		{
#ifndef CLIENT_DLL
			CShotManipulator Manipulator( vecAiming );
					
			int iPellets = GetNumPellets();
			for (int i=0;i<iPellets;i++)
			{
				// create a pellet at some random spread direction
				//CASW_Shotgun_Pellet *pPellet = 			
				Vector newVel = Manipulator.ApplySpread(GetBulletSpread());
				//Vector newVel = ApplySpread( vecAiming, GetBulletSpread() );
				if ( pMarine->GetWaterLevel() == 3 )
					newVel *= PELLET_WATER_VELOCITY;
				else
					newVel *= PELLET_AIR_VELOCITY;
				newVel *= (1.0 + (0.1 * random->RandomFloat(-1,1)));
				CreatePellet(vecSrc, newVel, pMarine);
				
				//CASW_Shotgun_Pellet_Predicted::CreatePellet(vecSrc, newVel, pPlayer, pMarine);
			}
#endif
		}

		// increment shooting stats
#ifndef CLIENT_DLL
		if (pMarine && pMarine->GetMarineResource())
		{
			pMarine->GetMarineResource()->UsedWeapon(this, 1);
			pMarine->OnWeaponFired( this, GetNumPellets() );
		}
#endif

		// decrement ammo
		m_iClip1 -= 1;
#ifdef GAME_DLL
		CASW_Marine *pMarine = GetMarine();
		if (pMarine && m_iClip1 <= 0 && pMarine->GetAmmoCount(m_iPrimaryAmmoType) <= 0 )
		{
			// check he doesn't have ammo in an ammo bay
			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))
				pMarine->OnWeaponOutOfAmmo(true);
		}
#endif
	}
	
	if (m_iClip1 > 0)		// only force the fire wait time if we have ammo for another shot
		m_flNextPrimaryAttack = gpGlobals->curtime + GetFireRate();
	else
		m_flNextPrimaryAttack = gpGlobals->curtime;
	m_fSlowTime = gpGlobals->curtime + 0.1f;
}
Ejemplo n.º 12
0
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CUnitBase::FireBullets( const FireBulletsInfo_t &info )
{
	VPROF_BUDGET( "CUnitBase::FireBullets", VPROF_BUDGETGROUP_UNITS );

	static int	tracerCount;
	trace_t		tr;
	CAmmoDef*	pAmmoDef	= GetAmmoDef();
	int			nDamageType	= pAmmoDef->DamageType(info.m_iAmmoType);
	//int			nAmmoFlags	= pAmmoDef->Flags(info.m_iAmmoType);
	int iNumShots;
	float flActualDamage;

	// the default attacker is ourselves
	CBaseEntity *pAttacker = info.m_pAttacker ? info.m_pAttacker : this;

	ClearMultiDamage();
	g_MultiDamage.SetDamageType( nDamageType | DMG_NEVERGIB );

	Vector vecDir;
	Vector vecEnd;

	// Adjust spread to accuracy
	Vector vecSpread( info.m_vecSpread );
	//vecSpread.x = sin( ( (asin( info.m_vecSpread.x ) * 2.0f) * m_fAccuracy ) / 2.0f );
	//vecSpread.y = sin( ( (asin( info.m_vecSpread.y ) * 2.0f) * m_fAccuracy ) / 2.0f );
	//vecSpread.z = sin( ( (asin( info.m_vecSpread.z ) * 2.0f) * m_fAccuracy ) / 2.0f );

	// Skip multiple entities when tracing
	CWarsBulletsFilter traceFilter( this, COLLISION_GROUP_NONE );
	traceFilter.SetPassEntity( this ); // Standard pass entity for THIS so that it can be easily removed from the list after passing through a portal
	traceFilter.AddEntityToIgnore( info.m_pAdditionalIgnoreEnt );

	CShotManipulator Manipulator( info.m_vecDirShooting );

	iNumShots = info.m_iShots;
	flActualDamage = info.m_flDamage;
	if ( flActualDamage == 0.0 )
	{
		flActualDamage = g_pGameRules->GetAmmoDamage( pAttacker, tr.m_pEnt, info.m_iAmmoType );
	}

	flActualDamage *= m_fAccuracy; // Pretty much a damage modifier

	for (int iShot = 0; iShot < iNumShots; iShot++)
	{
		//vecDir = info.m_vecDirShooting;
		vecDir = Manipulator.ApplySpread( vecSpread );

		vecEnd = info.m_vecSrc + vecDir * info.m_flDistance;

		AI_TraceLine(info.m_vecSrc, vecEnd, MASK_SHOT, &traceFilter, &tr);

		if( unit_debugfirebullets.GetBool() )
		{
#ifdef CLIENT_DLL
			NDebugOverlay::Line(info.m_vecSrc, vecEnd, 255, 0, 0, 255, 0.1f);
			NDebugOverlay::Line(info.m_vecSrc, tr.endpos, 0, 255, 0, 255, 0.1f);
#else
			NDebugOverlay::Line(info.m_vecSrc, vecEnd, 255, 255, 0, 255, 0.1f);
			NDebugOverlay::Line(info.m_vecSrc, tr.endpos, 0, 255, 255, 255, 0.1f);
#endif // CLIENT_DLL
		}

		// Make sure given a valid bullet type
		if (info.m_iAmmoType == -1)
		{
			DevMsg("ERROR: Undefined ammo type!\n");
			return;
		}

		Vector vecTracerDest = tr.endpos;

		// do damage, paint decals
		if (tr.fraction != 1.0)
		{
			CTakeDamageInfo dmgInfo( pAttacker, pAttacker, flActualDamage, nDamageType );
			CalculateBulletDamageForce( &dmgInfo, info.m_iAmmoType, vecDir, tr.endpos );
			dmgInfo.ScaleDamageForce( info.m_flDamageForceScale );
			dmgInfo.SetAmmoType( info.m_iAmmoType );

			(dynamic_cast<CBaseEntity *>(tr.m_pEnt))->DispatchTraceAttack( dmgInfo, vecDir, &tr );

			// Effects only, FireBullets should be called on the client.
			// Dispatching on the server generates far too many events/data!
#ifdef CLIENT_DLL 
			DoImpactEffect( tr, nDamageType );

			Vector vecTracerSrc = vec3_origin;
			ComputeTracerStartPosition( info.m_vecSrc, &vecTracerSrc );

			trace_t Tracer;
			Tracer = tr;
			Tracer.endpos = vecTracerDest;

			MakeTracer( vecTracerSrc, Tracer, pAmmoDef->TracerType(info.m_iAmmoType) );
#endif // CLIENT_DLL
		}
	}

#ifdef GAME_DLL
	ApplyMultiDamage();
#endif // GAME_DLL
}
void CASW_Weapon_Pistol::PrimaryAttack( void )
{
	// If my clip is empty (and I use clips) start reload
	if ( UsesClipsForAmmo1() && !m_iClip1 ) 
	{
		Reload();
		return;
	}

	CASW_Player *pPlayer = GetCommander();
	CASW_Marine *pMarine = GetMarine();

	if (pMarine)		// firing from a marine
	{
		// MUST call sound before removing a round from the clip of a CMachineGun
		WeaponSound(SINGLE);
		if (m_iClip1 <= AmmoClickPoint())
			BaseClass::WeaponSound( EMPTY );

		m_bIsFiring = true;

		// tell the marine to tell its weapon to draw the muzzle flash
		pMarine->DoMuzzleFlash();

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

		// sets the animation on the marine holding this weapon
		//pMarine->SetAnimation( PLAYER_ATTACK1 );

#ifdef GAME_DLL	// check for turning on lag compensation
		if (pPlayer && pMarine->IsInhabited())
		{
			CASW_Lag_Compensation::RequestLagCompensation( pPlayer, pPlayer->GetCurrentUserCommand() );
		}
#endif

		//	if (asw_pistol_hitscan.GetBool())
		if (true)
		{
			FireBulletsInfo_t info;
			info.m_vecSrc = pMarine->Weapon_ShootPosition( );
			if ( pPlayer && pMarine->IsInhabited() )
			{
				info.m_vecDirShooting = pPlayer->GetAutoaimVectorForMarine(pMarine, GetAutoAimAmount(), GetVerticalAdjustOnlyAutoAimAmount());	// 45 degrees = 0.707106781187
			}
			else
			{
#ifdef CLIENT_DLL
				Msg("Error, clientside firing of a weapon that's being controlled by an AI marine\n");
#else
				info.m_vecDirShooting = pMarine->GetActualShootTrajectory( info.m_vecSrc );
#endif
			}
			
			info.m_iShots = 1;			

			// Make sure we don't fire more than the amount in the clip
			if ( UsesClipsForAmmo1() )
			{
				info.m_iShots = MIN( info.m_iShots, m_iClip1 );
				m_iClip1 -= info.m_iShots;
#ifdef GAME_DLL
				CASW_Marine *pMarine = GetMarine();
				if (pMarine && m_iClip1 <= 0 && pMarine->GetAmmoCount(m_iPrimaryAmmoType) <= 0 )
				{
					pMarine->OnWeaponOutOfAmmo(true);
				}
#endif
			}
			else
			{
				info.m_iShots = MIN( info.m_iShots, pMarine->GetAmmoCount( m_iPrimaryAmmoType ) );
				pMarine->RemoveAmmo( info.m_iShots, m_iPrimaryAmmoType );
			}

			info.m_flDistance = asw_weapon_max_shooting_distance.GetFloat();
			info.m_iAmmoType = m_iPrimaryAmmoType;
			info.m_iTracerFreq = 1;
			info.m_flDamageForceScale = asw_weapon_force_scale.GetFloat();
		
			info.m_vecSpread = GetBulletSpread();
			info.m_flDamage = GetWeaponDamage();
#ifndef CLIENT_DLL
			if (asw_debug_marine_damage.GetBool())
				Msg("Weapon dmg = %f\n", info.m_flDamage);
			info.m_flDamage *= pMarine->OnFired_GetDamageScale();
#endif

			pMarine->FireBullets( info );

			//FireBulletsInfo_t info( 1, vecSrc, vecAiming, GetBulletSpread(), MAX_TRACE_LENGTH, m_iPrimaryAmmoType );
			//info.m_pAttacker = pMarine;

			// Fire the bullets, and force the first shot to be perfectly accuracy
			//pMarine->FireBullets( info );
		}
		else	// projectile pistol
		{
		
#ifndef CLIENT_DLL
			Vector vecSrc = pMarine->Weapon_ShootPosition( );
			Vector vecAiming = vec3_origin;
			if ( pPlayer && pMarine->IsInhabited() )
			{
				vecAiming = pPlayer->GetAutoaimVectorForMarine(pMarine, GetAutoAimAmount(), GetVerticalAdjustOnlyAutoAimAmount());	// 45 degrees = 0.707106781187
			}
			else
			{
				vecAiming = pMarine->GetActualShootTrajectory( vecSrc );
			}

			CShotManipulator Manipulator( vecAiming );
			AngularImpulse rotSpeed(0,0,720);
					
			Vector newVel = Manipulator.ApplySpread(GetBulletSpread());
			if ( pMarine->GetWaterLevel() == 3 )
				newVel *= PELLET_WATER_VELOCITY;
			else
				newVel *= PELLET_AIR_VELOCITY;
			newVel *= (1.0 + (0.1 * random->RandomFloat(-1,1)));
			CASW_Shotgun_Pellet::Shotgun_Pellet_Create( vecSrc, QAngle(0,0,0),
					newVel, rotSpeed, pMarine, GetWeaponDamage() );

			// decrement ammo
			m_iClip1 -= 1;
			CASW_Marine *pMarine = GetMarine();
			if (pMarine && m_iClip1 <= 0 && pMarine->GetAmmoCount(m_iPrimaryAmmoType) <= 0 )
			{
				pMarine->OnWeaponOutOfAmmo(true);
			}
#endif
		}

		// increment shooting stats
#ifndef CLIENT_DLL
		if (pMarine && pMarine->GetMarineResource())
		{
			pMarine->GetMarineResource()->UsedWeapon(this, 1);
			pMarine->OnWeaponFired( this, 1 );
		}
#endif		
	}
	
	if (m_iClip1 > 0)		// only force the fire wait time if we have ammo for another shot
		m_flNextPrimaryAttack = gpGlobals->curtime + GetFireRate();
	else
		m_flNextPrimaryAttack = gpGlobals->curtime;
	m_fSlowTime = gpGlobals->curtime + 0.03f;

	if ( m_currentPistol == ASW_WEAPON_PISTOL_LEFT )
	{
		m_currentPistol = ASW_WEAPON_PISTOL_RIGHT;
	}
	else
	{
		m_currentPistol = ASW_WEAPON_PISTOL_LEFT;
	}
}
Ejemplo n.º 14
0
void CToyEditor::RenderScene()
{
	GameServer()->GetRenderer()->SetRenderingTransparent(false);

	if (m_iMeshPreview != ~0)
		TAssert(CModelLibrary::GetModel(m_iMeshPreview));

	if (m_iMeshPreview != ~0 && CModelLibrary::GetModel(m_iMeshPreview))
	{
		CGameRenderingContext c(GameServer()->GetRenderer(), true);

		if (!c.GetActiveFrameBuffer())
			c.UseFrameBuffer(GameServer()->GetRenderer()->GetSceneBuffer());

		c.SetColor(Color(255, 255, 255));

		c.RenderModel(m_iMeshPreview);
	}

	if (m_hMaterialPreview.IsValid())
	{
		CGameRenderingContext c(GameServer()->GetRenderer(), true);

		if (!c.GetActiveFrameBuffer())
			c.UseFrameBuffer(GameServer()->GetRenderer()->GetSceneBuffer());

		c.SetColor(Color(255, 255, 255));

		c.RenderMaterialModel(m_hMaterialPreview);
	}

	GameServer()->GetRenderer()->SetRenderingTransparent(true);

	if (m_iPhysPreview != ~0 && CModelLibrary::GetModel(m_iPhysPreview))
	{
		CGameRenderingContext c(GameServer()->GetRenderer(), true);

		if (!c.GetActiveFrameBuffer())
			c.UseFrameBuffer(GameServer()->GetRenderer()->GetSceneBuffer());

		c.ClearDepth();

		float flAlpha = 0.3f;
		if (m_iMeshPreview == ~0 && m_hMaterialPreview.IsValid() == 0)
			flAlpha = 1.0f;

		c.SetColor(Color(0, 100, 155, (int)(255*flAlpha)));
		c.SetAlpha(flAlpha);
		if (flAlpha < 1)
			c.SetBlend(BLEND_ALPHA);

		c.RenderModel(m_iPhysPreview);
	}

	for (size_t i = 0; i < GetToy().m_aShapes.size(); i++)
	{
		CGameRenderingContext c(GameServer()->GetRenderer(), true);

		if (!c.GetActiveFrameBuffer())
			c.UseFrameBuffer(GameServer()->GetRenderer()->GetSceneBuffer());

		c.ClearDepth();

		c.UseProgram("model");
		c.SetUniform("bDiffuse", false);

		float flAlpha = 0.2f;
		if (m_pSourcePanel->m_pPhysicsShapes->GetSelectedNodeId() == i)
			flAlpha = 0.8f;
		if (m_iMeshPreview == ~0 && m_hMaterialPreview.IsValid() == 0)
			flAlpha = 1.0f;
		if (flAlpha < 1)
			c.SetBlend(BLEND_ALPHA);

		if (m_pSourcePanel->m_pPhysicsShapes->GetSelectedNodeId() == i)
			c.SetUniform("vecColor", Color(255, 50, 100, (char)(255*flAlpha)));
		else
			c.SetUniform("vecColor", Color(0, 100, 200, (char)(255*flAlpha)));

		if (m_pSourcePanel->m_pPhysicsShapes->GetSelectedNodeId() == i)
			c.Transform(Manipulator()->GetTransform());
		else
			c.Transform(GetToy().m_aShapes[i].m_trsTransform.GetMatrix4x4());

		c.RenderWireBox(CToy::s_aabbBoxDimensions);

		// Reset the uniforms so other stuff doesn't get this ugly color.
		c.SetUniform("bDiffuse", true);
		c.SetUniform("vecColor", Color(255, 255, 255, 255));
	}
}
Ejemplo n.º 15
0
void CSourcePanel::Layout()
{
	float flWidth = glgui::CRootPanel::Get()->GetWidth();
	float flHeight = glgui::CRootPanel::Get()->GetHeight();

	float flMenuBarBottom = glgui::CRootPanel::Get()->GetMenuBar()->GetBottom();

	float flCurrLeft = 20;
	float flCurrTop = flMenuBarBottom + 10;

	SetDimensions(flCurrLeft, flCurrTop, 200, flHeight-30-flMenuBarBottom);

	m_pFilename->Layout_AlignTop();
	m_pFilename->Layout_FullWidth(0);

	BaseClass::Layout();

	const CToySource* pToySource = &ToyEditor()->GetToy();

	if (!pToySource->m_sFilename.length())
		return;

	LayoutFilename();

	m_pToyFileLabel->Layout_AlignTop(m_pFilename);
	m_pToyFileLabel->SetWidth(10);
	m_pToyFileLabel->SetHeight(1);
	m_pToyFileLabel->EnsureTextFits();
	m_pToyFileLabel->Layout_FullWidth();

	m_pToyFileText->Layout_FullWidth();
	m_pToyFileText->SetTop(m_pToyFileLabel->GetTop()+12);

	float flControlMargin = 12;

	m_pMeshMenu->Layout_AlignTop(m_pToyFileText, flControlMargin);
	m_pMeshMenu->SetWidth(10);
	m_pMeshMenu->SetHeight(1);
	m_pMeshMenu->EnsureTextFits();
	m_pMeshMenu->SetLeft(m_pToyFileText->GetLeft());

	m_pMeshText->Layout_FullWidth();
	m_pMeshText->SetTop(m_pMeshMenu->GetBottom());

	m_pPhysLabel->Layout_AlignTop(m_pMeshText, flControlMargin);
	m_pPhysLabel->SetWidth(10);
	m_pPhysLabel->SetHeight(1);
	m_pPhysLabel->EnsureTextFits();
	m_pPhysLabel->Layout_FullWidth();

	m_pPhysText->Layout_FullWidth();
	m_pPhysText->SetTop(m_pPhysLabel->GetTop()+12);

	m_pPhysShapesLabel->Layout_AlignTop(m_pPhysText, flControlMargin);
	m_pPhysShapesLabel->SetWidth(10);
	m_pPhysShapesLabel->SetHeight(1);
	m_pPhysShapesLabel->EnsureTextFits();
	m_pPhysShapesLabel->Layout_FullWidth();

	m_pPhysicsShapes->Layout_FullWidth();
	m_pPhysicsShapes->SetTop(m_pPhysShapesLabel->GetTop()+12);
	m_pPhysicsShapes->SetHeight(100);

	m_pPhysicsShapes->ClearTree();

	for (size_t i = 0; i < pToySource->m_aShapes.size(); i++)
		m_pPhysicsShapes->AddNode("Box");

	m_pNewPhysicsShape->SetHeight(20);
	m_pNewPhysicsShape->Layout_Column(2, 0);
	m_pNewPhysicsShape->Layout_AlignTop(m_pPhysicsShapes, 5);
	m_pDeletePhysicsShape->SetHeight(20);
	m_pDeletePhysicsShape->Layout_Column(2, 1);
	m_pDeletePhysicsShape->Layout_AlignTop(m_pPhysicsShapes, 5);
	m_pDeletePhysicsShape->SetEnabled(false);

	m_pSave->Layout_Column(2, 0);
	m_pSave->Layout_AlignBottom();
	m_pBuild->Layout_Column(2, 1);
	m_pBuild->Layout_AlignBottom();

	BaseClass::Layout();

	Manipulator()->Deactivate();
}