⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gameprojectiles.cpp

📁 Blood 2全套源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
		dwFlags &= ~FLAG_GRAVITY;
		pServerDE->SetObjectFlags(m_hObject, dwFlags);

		m_bArmed = DTRUE;
		m_fStartTime = pServerDE->GetTime();
		PlaySoundFromPos(&m_LastPos, "Sounds\\Weapons\\proximities\\stick.wav", 500.0f, SOUNDPRIORITY_MISC_MEDIUM);
	}
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	CProximityBomb::AddExplosion()
//
//	PURPOSE:	Add an explosion
//
// ----------------------------------------------------------------------- //

void CProximityBomb::AddExplosion(DVector vPos, DVector vNormal)
{
	CServerDE* pServerDE = BaseClass::GetServerDE();
	if (!pServerDE) return;

	DDWORD		nType = EXP_DEFAULT_MEDIUM;

	HMESSAGEWRITE hMessage = pServerDE->StartInstantSpecialEffectMessage(&vPos);
	pServerDE->WriteToMessageByte(hMessage, SFX_EXPLOSIONFX_ID);

	pServerDE->WriteToMessageVector(hMessage, &vPos);
	pServerDE->WriteToMessageVector(hMessage, &vNormal);
	pServerDE->WriteToMessageDWord(hMessage, nType);

	pServerDE->EndMessage2(hMessage, MESSAGE_GUARANTEED);

	PlaySoundFromPos(&vPos, "Sounds\\Weapons\\proximities\\explode.wav", 1000.0f, SOUNDPRIORITY_MISC_MEDIUM);
}




BEGIN_CLASS(CRemoteBomb)
END_CLASS_DEFAULT_FLAGS(CRemoteBomb, CProjectile, NULL, NULL, CF_HIDDEN)

// ----------------------------------------------------------------------- //
//
//	ROUTINE:	CRemoteBomb::CRemoteBomb()
//
//	PURPOSE:	Constructor
//
// ----------------------------------------------------------------------- //

CRemoteBomb::CRemoteBomb() : CProjectile()
{
	CServerDE* pServerDE = BaseClass::GetServerDE();
	if (!pServerDE) return;

	m_bShockwave			= DFALSE;
	m_bExplosion			= DTRUE;

	m_pProjectileFilename	= "Models\\Ammo\\c4.abc";
	m_pProjectileSkin		= "Skins\\Ammo\\c4_remote.dtx";

	m_nDamageType			= DAMAGE_TYPE_EXPLODE;

	m_dwFlags				= m_dwFlags | FLAG_GRAVITY;
	m_bArmed				= DFALSE;
	m_bExplode				= DFALSE;
	m_fStartTime			= 0.0f;

	m_bFalling				= DFALSE;

	// Set up angular velocities
	m_fPitch				= 0.0f;
	m_fYaw					= 0.0f;
	m_fPitchVel				= pServerDE->Random(-MATH_CIRCLE, MATH_CIRCLE);
	m_fYawVel				= pServerDE->Random(-MATH_CIRCLE, MATH_CIRCLE);

	m_damage.SetDeathDelay(0.25f);		// .25 second delay if killed by explosion
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	CRemoteBomb::Update()
//
//	PURPOSE:	Do update
//
// ----------------------------------------------------------------------- //

DBOOL CRemoteBomb::Update(DVector *pMovement)
{
	CServerDE* pServerDE = BaseClass::GetServerDE();
	if (!pServerDE) return DFALSE;

	pServerDE->SetNextUpdate(m_hObject, (DFLOAT)0.001);
	DFLOAT fTime = pServerDE->GetTime();

	pServerDE->GetObjectPos(m_hObject, &m_LastPos);

	if(m_bExplode || m_damage.IsDead())
	{
		if(m_hFiredFrom && IsPlayer(m_hFiredFrom)) 
		{
			CPlayerObj *pObj = (CPlayerObj*)pServerDE->HandleToObject(m_hFiredFrom);
			pObj->RemoveRemoteBomb(this);
		}

		Explode();
		return DFALSE;
	}

	if(m_bArmed)
	{
		DVector		vVel;
		VEC_INIT(vVel);
		pServerDE->SetVelocity(m_hObject, &vVel);
	}
	else
	{
		DRotation rRot;
		pServerDE->GetObjectRotation(m_hObject, &rRot);

		// Rotate the object as it flys through the air
		if (m_fPitchVel != 0 || m_fYawVel != 0)
		{
			DFLOAT fDeltaTime = pServerDE->GetFrameTime();

			m_fPitch += m_fPitchVel * fDeltaTime;
			m_fYaw += m_fYawVel * fDeltaTime;

			pServerDE->SetupEuler(&rRot, m_fPitch, m_fYaw, 0.0f);
			pServerDE->SetObjectRotation(m_hObject, &rRot);	
		}
	}

	return DTRUE;
}

// ----------------------------------------------------------------------- //
//
//	ROUTINE:	CRemoteBomb::HandleTouch()
//
//	PURPOSE:	Handle touch notify message
//
// ----------------------------------------------------------------------- //

void CRemoteBomb::HandleTouch(HOBJECT hObj)
{
	CServerDE* pServerDE = BaseClass::GetServerDE();
	if (!pServerDE) return;

	if(m_bArmed)
		return;

	if(hObj == m_hFiredFrom)
		return;

	if(hObj != pServerDE->GetWorldObject() && !(pServerDE->GetObjectFlags(hObj) & FLAG_SOLID))
		return;

	if (pServerDE->IsKindOf(pServerDE->GetObjectClass(hObj), pServerDE->GetClass("CBaseCharacter")))
	{
		if(m_bFalling)	return;

		DVector vVel;
		VEC_SET(vVel, 0.0f, 0.0f, 0.0f);
		pServerDE->SetVelocity(m_hObject, &vVel);

		m_bFalling = DTRUE;

//		CBaseCharacter *pObj = (CBaseCharacter*)pServerDE->HandleToObject(hObj);
//		if(pObj->IsDead())	return;

//		CProjectile::HandleTouch(hObj);	// Explode on impact type.
	}
	else
	{
		CollisionInfo colInfo;
		pServerDE->GetLastCollision( &colInfo );

		DVector		vU, vR, vF;
		DRotation	rRot;

		VEC_SET(vU, 0.0f, 1.0f, 0.0f);

		pServerDE->AlignRotation(&rRot, &colInfo.m_Plane.m_Normal, &vU);
		pServerDE->GetRotationVectors(&rRot, &vU, &vR, &vF);
		pServerDE->RotateAroundAxis(&rRot, &vR, MATH_PI * 0.5f);
		pServerDE->SetObjectRotation(m_hObject, &rRot);

		DDWORD	dwFlags = pServerDE->GetObjectFlags(m_hObject);
		dwFlags &= ~FLAG_GRAVITY;
		pServerDE->SetObjectFlags(m_hObject, dwFlags);

		m_bArmed = DTRUE;
	}
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	CRemoteBomb::AddExplosion()
//
//	PURPOSE:	Add an explosion
//
// ----------------------------------------------------------------------- //

void CRemoteBomb::AddExplosion(DVector vPos, DVector vNormal)
{
	CServerDE* pServerDE = BaseClass::GetServerDE();
	if (!pServerDE) return;

	DDWORD		nType = EXP_DEFAULT_SMALL;

	HMESSAGEWRITE hMessage = pServerDE->StartInstantSpecialEffectMessage(&vPos);
	pServerDE->WriteToMessageByte(hMessage, SFX_EXPLOSIONFX_ID);

	pServerDE->WriteToMessageVector(hMessage, &vPos);
	pServerDE->WriteToMessageVector(hMessage, &vNormal);
	pServerDE->WriteToMessageDWord(hMessage, nType);

	pServerDE->EndMessage2(hMessage, MESSAGE_GUARANTEED);

	PlaySoundFromPos(&vPos, "Sounds\\Weapons\\time\\explode.wav", 1000.0f, SOUNDPRIORITY_MISC_MEDIUM);
}

#endif _DEMO


BEGIN_CLASS(CHowitzerShell)
END_CLASS_DEFAULT_FLAGS(CHowitzerShell, CProjectile, NULL, NULL, CF_HIDDEN)

// ----------------------------------------------------------------------- //
//
//	ROUTINE:	CHowitzerShell::CHowitzerShell()
//
//	PURPOSE:	Constructor
//
// ----------------------------------------------------------------------- //

CHowitzerShell::CHowitzerShell() : CProjectile(OT_NORMAL)
{
	m_bShockwave			= DFALSE;
	m_bExplosion			= DTRUE;
	m_fShockwaveDuration	= 0.75f;
	m_fLifeTime				= 5.0f;

	m_nDamageType			= DAMAGE_TYPE_EXPLODE;
	m_dwFlags				= m_dwFlags | FLAG_POINTCOLLIDE;

	VEC_SET(m_vShockwaveScaleMin, 0.1f, 0.1f, 0.0f);
	VEC_SET(m_vShockwaveScaleMax, 2.0f, 2.0f, 0.0f);
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	CHowitzerShell::Update()
//
//	PURPOSE:	Cast a ray to see if it hits anything, then 
//
// ----------------------------------------------------------------------- //

DBOOL CHowitzerShell::Update(DVector *pMovement)
{
	CServerDE* pServerDE = BaseClass::GetServerDE();
	if (!pServerDE) return DFALSE;

	IntersectQuery iq;
	IntersectInfo  ii;
	DRotation rRot;
	DVector vFrom, vTo, vDist, vFire;

	pServerDE->GetObjectRotation(m_hObject, &rRot);
	// Get the forward vector
	pServerDE->GetRotationVectors(&rRot, &vTo, &vTo, &vFire);

    pServerDE->GetObjectPos(m_hObject, &vFrom);
	VEC_COPY(vTo, vFrom);
	VEC_INIT(vDist);

// Add distance to rotation    
	VEC_MULSCALAR(vDist, vFire, 3000.0f)

// Get distination point    
	VEC_ADD(vTo, vTo, vDist);

	VEC_COPY(iq.m_From, vFrom);
	VEC_COPY(iq.m_To, vTo);
    
	iq.m_Flags = INTERSECT_OBJECTS | IGNORE_NONSOLID;
	iq.m_FilterFn = LiquidFilterFn;
	iq.m_pUserData = NULL;	

	DBOOL bHit;
	
	// Greg 10/5 - Don't shoot the sap who fired this.
	if (bHit = pServerDE->IntersectSegment(&iq, &ii))
	{
		if (m_hFiredFrom == ii.m_hObject)
		{
			VEC_COPY(iq.m_From, ii.m_Point);
			bHit = pServerDE->IntersectSegment(&iq, &ii);		
		}
	}

	if (bHit)
	{
		pServerDE->TeleportObject(m_hObject, &ii.m_Point);
		AddImpact(ii.m_Point, ii.m_Plane.m_Normal, ii.m_hObject);

		if(m_nRadius) 
			DamageObjectsWithinRadius();

		// If we directly hit someone, do some more damage...
		if(pServerDE->IsKindOf(pServerDE->GetObjectClass(m_hFiredFrom), pServerDE->GetClass("CBaseCharacter")))
			DamageObject(m_hFiredFrom, this, ii.m_hObject, m_fDamage, vDist, ii.m_Point, m_nDamageType);
	}
	return DFALSE;
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	CHowitzerShell::AddExplosion()
//
//	PURPOSE:	Add an explosion
//
// ----------------------------------------------------------------------- //

void CHowitzerShell::AddExplosion(DVector vPos, DVector vNormal)
{
	CServerDE* pServerDE = BaseClass::GetServerDE();
	if (!pServerDE) return;

	DDWORD		nType = EXP_HOWITZER_PRIMARY;

	HMESSAGEWRITE hMessage = pServerDE->StartInstantSpecialEffectMessage(&vPos);
	pServerDE->WriteToMessageByte(hMessage, SFX_EXPLOSIONFX_ID);

	pServerDE->WriteToMessageVector(hMessage, &vPos);
	pServerDE->WriteToMessageVector(hMessage, &vNormal);
	pServerDE->WriteToMessageDWord(hMessage, nType);

	pServerDE->EndMessage2(hMessage, MESSAGE_GUARANTEED);

	PlaySoundFromPos(&vPos, "Sounds\\Weapons\\c4\\explosion_1.wav", 1000.0f, SOUNDPRIORITY_MISC_MEDIUM);
}



BEGIN_CLASS(CHowitzerAltShell)
END_CLASS_DEFAULT_FLAGS(CHowitzerAltShell, CProjectile, NULL, NULL, CF_HIDDEN)

// ----------------------------------------------------------------------- //
//
//	ROUTINE:	CHowitzerAltShell::CHowitzerAltShell()
//
//	PURPOSE:	Constructor
//
// ----------------------------------------------------------------------- //

CHowitzerAltShell::CHowitzerAltShell() : CProjectile(OT_NORMAL)
{
	m_bShockwave			= DFALSE;
	m_bExplosion			= DTRUE;
	m_fShockwaveDuration	= 0.75f;
	m_fLifeTime				= 5.0f;

	m_nDamageType			= DAMAGE_TYPE_EXPLODE;
	m_dwFlags				= m_dwFlags | FLAG_POINTCOLLIDE;

	VEC_SET(m_vShockwaveScaleMin, 0.1f, 0.1f, 0.0f);
	VEC_SET(m_vShockwaveScaleMax, 2.0f, 2.0f, 0.0f);
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	CHowitzerAltShell::Update()
//
//	PURPOSE:	Cast a ray to see if it hits anything, then 
//
// ----------------------------------------------------------------------- //

DBOOL CHowitzerAltShell::Update(DVector *pMovement)
{
	CServerDE* pServerDE = BaseClass::GetServerDE();
	if (!pServerDE) return DFALSE;

	IntersectQuery iq;
	IntersectInfo  ii;
	DRotation rRot;
	DVector vFrom, vTo, vDist, vFire, vScale;

	VEC_INIT(vScale);
	pServerDE->ScaleObject(m_hObject, &vScale);

	pServerDE->GetObjectRotation(m_hObject, &rRot);
	// Get the forward vector
	pServerDE->GetRotationVectors(&rRot, &vTo, &vTo, &vFire);

    pServerDE->GetObjectPos(m_hObject, &vFrom);
	VEC_COPY(vTo, vFrom);
	VEC_INIT(vDist);

// Add distance to rotation    
	VEC_MULSCALAR(vDist, vFire, 3000.0f)

// Get distination point    
	VEC_ADD(vTo, vTo, vDist);

	VEC_COPY(iq.m_From, vFrom);
	VEC_COPY(iq.m_To, vTo);
    
	iq.m_Flags = INTERSECT_OBJECTS | IGNORE_NONSOLID;
	iq.m_FilterFn = LiquidFilterFn;
	iq.m_pUserData = NULL;	

	DBOOL bHit;
	
	if(bHit = pServerDE->IntersectSegment(&iq, &ii))
	{
		if (m_hFiredFrom == ii.m_hObject)
		{
			VEC_COPY(iq.m_From, ii.m_Point);
			bHit = pServerDE->IntersectSegment(&iq, &ii);		
		}
	}

	if(bHit)
	{
		pServerDE->TeleportObject(m_hObject, &ii.m_Point);
		AddImpact(ii.m_Point, ii.m_Plane.m_Normal, ii.m_hObject);

		if(m_nRadius) 
			DamageObjectsWithinRadius();

		// If we directly hit someone, do some more damage...
//		if(pServerDE->IsKindOf(pServerDE->GetObjectClass(m_hFiredFrom), pServerDE->GetClass("CBaseCharacter")))
//			DamageObject(m_hFiredFrom, this, ii.m_hObject, m_fDamage, vDist, ii.m_Point, m_nDamageType);
	}
	return DFALSE;
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	CHowitzerAltShell::AddExplosion()
//
//	PURPOSE:	Add an explosion
//
// ----------------------------------------------------------------------- //

void CHowitzerAltShell::AddExplosion(DVector vPos, DVector vNormal)
{
	CServerDE* pServerDE = BaseClass::GetServerDE();
	if (!pServerDE) return;

	DDWORD		nType = EXP_HOWITZER_ALT;

	HMESSAGEWRITE hMessage = pServerDE->StartInstantSpecialEffectMessage(&vPos);
	pServerDE->WriteToMessageByte(hMessage, SFX_EXPLOSIONFX_ID);

	pServerDE->WriteToMessageVector(hMessage, &vPos);
	pServerDE->WriteToMessageVector(hMessage, &vNormal);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -