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

📄 gameprojectiles.cpp

📁 Blood 2全套源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	pServerDE->WriteToMessageDWord(hMessage, nType);

	pServerDE->EndMessage2(hMessage, MESSAGE_GUARANTEED);

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

	//***** Make the projectiles the explode from the impact *****//
	CProjectile	*pProjectile = NULL;
	DVector		vFire, vUp, vU, vR, vF;
	DRotation	rRot;
	DFLOAT		fVelocity = 30.0f, fDamage = m_fDamage / 2;
	int			nRadius = m_nRadius / 2;

	ObjectCreateStruct ocStruct;
	INIT_OBJECTCREATESTRUCT(ocStruct);
	VEC_COPY(ocStruct.m_Pos, vPos);

	HCLASS hClass = pServerDE->GetClass("CHowitzerAltFrag");
	VEC_SET(vUp, 0.0f, 1.0f, 0.0f);

	pServerDE->AlignRotation(&rRot, &vNormal, &vUp);
	pServerDE->RotateAroundAxis(&rRot, &vNormal, pServerDE->Random(-MATH_PI, MATH_PI));

	for(int i = 0; i < pServerDE->IntRandom(5, 10); i++)
	{
		pServerDE->RotateAroundAxis(&rRot, &vNormal, MATH_PI / 2.0f);
		pServerDE->GetRotationVectors(&rRot, &vU, &vR, &vF);

		VEC_MULSCALAR(vFire, vNormal, fVelocity);
		VEC_MULSCALAR(vR, vR, fVelocity * pServerDE->Random(0.25f,4.0f));
		VEC_ADD(vFire, vFire, vR);

		VEC_NORM(vFire);
		VEC_MULSCALAR(vFire, vFire, fVelocity);

		if (hClass)
			pProjectile = (CProjectile*)pServerDE->CreateObject(hClass, &ocStruct);

		if(pProjectile)
			pProjectile->Setup(&vFire, m_nWeaponType, fDamage / 2.0f, fVelocity, m_nRadius / 2, m_hFiredFrom);
	}
}



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

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

CHowitzerAltFrag::CHowitzerAltFrag() : CProjectile(OT_SPRITE)
{
	m_bShockwave			= DFALSE;
	m_bExplosion			= DTRUE;
	m_bClientFX				= DFALSE;

	m_pProjectileFilename	= "Sprites\\howitzerball.spr";
	m_pProjectileSkin		= 0;

	m_nDamageType			= DAMAGE_TYPE_EXPLODE;
	m_dwFlags				= m_dwFlags | FLAG_POINTCOLLIDE | FLAG_NOSLIDING;

	m_damage.SetGodMode(DTRUE);

	AddLight(100.0f, 1.0f, 0.75f, 0.0f);
	VEC_SET(m_vInitScale, 0.15f, 0.15f, 0.0f);
	VEC_SET(tempNorm, 0.0f, 1.0f, 0.0f);

	m_fTrailScale		= 1.75f;
	m_dwTrailScaleFlags	= OBJFX_SCALERADIUS;
	m_dwTrailFXID		= OBJFX_SMOKETRAIL_1;
}


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

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

	DVector		vPos, vVel, vGravity;
	DFLOAT		fTime = pServerDE->GetTime();

	pServerDE->SetNextUpdate(m_hObject, (DFLOAT)0.001);

	if(m_bExplode || m_damage.IsDead())
	{
		Explode();
 		return DFALSE;
	}

	pServerDE->GetVelocity(m_hObject, &vVel);
	pServerDE->GetGlobalForce(&vGravity);
	VEC_MULSCALAR(vGravity, vGravity, 0.02f);
	VEC_ADD(vVel, vVel, vGravity);
	pServerDE->SetVelocity(m_hObject, &vVel);

	if(m_hLight)
	{
		pServerDE->GetObjectPos(m_hObject, &vPos);
		pServerDE->SetObjectPos(m_hLight, &vPos);
	}

	return DTRUE;
}


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

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

	// return if it hit a non solid object
	if (hObj != pServerDE->GetWorldObject() && !(pServerDE->GetObjectFlags(hObj) & FLAG_SOLID)) // Ignore non-solid objects
		return;

	// return if it hit another of this same class
	if (pServerDE->GetObjectClass(hObj) == pServerDE->GetObjectClass(m_hObject))
		return;

	m_bExplode = DTRUE;
	m_hHitObject = hObj;

 	// Cast a ray from our last known position to see what we hit
	IntersectQuery iq;
	IntersectInfo  ii;
	DVector vVel, vLift;

	pServerDE->GetVelocity(m_hObject, &vVel);
	VEC_COPY(vLift, vVel);
	pServerDE->GetObjectPos(m_hObject, &m_LastPos);

	VEC_COPY(iq.m_From, m_LastPos);			// Get start point at the last known position.
	VEC_MULSCALAR(iq.m_To, vVel, 1.1f);
	VEC_ADD(iq.m_To, iq.m_To, iq.m_From);	// Get destination point slightly past where we should be
	iq.m_Flags = INTERSECT_OBJECTS | IGNORE_NONSOLID;
	iq.m_FilterFn = NULL;
	iq.m_pUserData = NULL;	

	if(pServerDE->IntersectSegment(&iq, &ii))
		VEC_COPY(tempNorm, ii.m_Plane.m_Normal);
}


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

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

	DDWORD		nType = EXP_HOWITZER_MINI;

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

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

	pServerDE->EndMessage2(hMessage, MESSAGE_GUARANTEED);

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



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

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

CNapalmProjectile::CNapalmProjectile() : CProjectile(OT_SPRITE)
{
	m_bShockwave			= DFALSE;
	m_bExplosion			= DTRUE;

	m_pProjectileFilename	= "Sprites\\napalmprime.spr";
	m_pProjectileSkin		= 0;

	m_nDamageType			= DAMAGE_TYPE_EXPLODE;
	m_dwFlags				= m_dwFlags | FLAG_POINTCOLLIDE | FLAG_NOSLIDING;
	m_fStartTime			= g_pServerDE->GetTime();
	m_fDelay				= 0.01f;

	m_hSound				= 0;

	AddLight(100.0f, 1.0f, 0.75f, 0.0f);
	VEC_INIT(m_vInitScale);

	m_dwTrailFXID	= OBJFX_SMOKETRAIL_2;
}


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

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

	// Create a sound attached to the projectile
	if(!m_hSound)
		m_hSound = PlaySoundFromObject(m_hObject, "Sounds\\Weapons\\napalm\\projectile.wav", 750.0f, SOUNDPRIORITY_MISC_MEDIUM, DTRUE, DTRUE, DFALSE, 100, DFALSE, DFALSE);

	DVector		vScale;
	VEC_SET(vScale, 0.25f, 0.25f, 0.25f);

	if(pServerDE->GetTime() - m_fStartTime < m_fDelay)
		VEC_INIT(vScale);

	pServerDE->ScaleObject(m_hObject, &vScale);
	DBOOL bRet = CProjectile::Update(pMovement);

	return bRet;
}


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

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

	if(m_hSound)
		{ pServerDE->KillSound(m_hSound); m_hSound = 0; }

	DDWORD		nType = EXP_NAPALM_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\\napalm\\impact.wav", 2000.0f, SOUNDPRIORITY_MISC_MEDIUM);
}


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

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

CNapalmAltProjectile::CNapalmAltProjectile() : CProjectile(OT_SPRITE)
{
	m_bShockwave			= DFALSE;
	m_bExplosion			= DTRUE;

	m_pProjectileFilename	= "Sprites\\napalmprime.spr";
	m_pProjectileSkin		= 0;

	m_nDamageType			= DAMAGE_TYPE_EXPLODE;
	m_dwFlags				= m_dwFlags | FLAG_POINTCOLLIDE | FLAG_NOSLIDING;
	m_fStartTime			= g_pServerDE->GetTime();
	m_fDelay				= 0.01f;

	m_hSound				= 0;

	AddLight(100.0f, 1.0f, 0.75f, 0.0f);
	VEC_INIT(m_vInitScale);

	m_dwTrailFXID	= OBJFX_SMOKETRAIL_2;
}


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

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

	// Create a sound attached to the projectile
	if(!m_hSound)
		m_hSound = PlaySoundFromObject(m_hObject, "Sounds\\Weapons\\napalm\\projectile.wav", 750.0f, SOUNDPRIORITY_MISC_MEDIUM, DTRUE, DTRUE, DFALSE, 100, DFALSE, DFALSE);

	DVector		vScale;
	VEC_SET(vScale, 0.25f, 0.25f, 0.25f);

	if(pServerDE->GetTime() - m_fStartTime < m_fDelay)
		VEC_INIT(vScale);

	pServerDE->ScaleObject(m_hObject, &vScale);
	DBOOL bRet = CProjectile::Update(pMovement);

	return bRet;
}


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

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

	if(m_hSound)
		{ pServerDE->KillSound(m_hSound); m_hSound = 0; }

	DDWORD		nType = EXP_NAPALM_ALT;

	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\\napalm\\altimpact.wav", 2000.0f, SOUNDPRIORITY_MISC_MEDIUM);

	//***** Make the projectiles that explode from the impact *****//
	CProjectile	*pProjectile = NULL;
	DVector		vFire, vUp, vU, vR, vF;
	DRotation	rRot, tempRot;
	DFLOAT		fVelocity, fDamage = m_fDamage / 3;
	int			nRadius = m_nRadius / 3;

	ObjectCreateStruct ocStruct;
	INIT_OBJECTCREATESTRUCT(ocStruct);
	VEC_COPY(ocStruct.m_Pos, vPos);

	HCLASS hClass = pServerDE->GetClass("CNapalmFireball");
	VEC_SET(vUp, 0.0f, 1.0f, 0.0f);

	pServerDE->GetVelocity(m_hObject, &vFire);
	pServerDE->AlignRotation(&rRot, &vNormal, &vUp);
	pServerDE->GetRotationVectors(&rRot, &vU, &vR, &vF);
	pServerDE->AlignRotation(&rRot, &vF, &vFire);

	DFLOAT	lowSpread = MATH_PI * 0.15f;
	DFLOAT	hiSpread = MATH_PI * 0.85f;
	fVelocity = 35.0f;

	for(int i = 0; i < 8; i++)
	{
		ROT_COPY(tempRot, rRot);
		pServerDE->RotateAroundAxis(&tempRot, &vNormal, pServerDE->Random(lowSpread, hiSpread));
		pServerDE->GetRotationVectors(&tempRot, &vU, &vR, &vF);

		VEC_MULSCALAR(vFire, vNormal, fVelocity);
		VEC_MULSCALAR(vR, vR, pServerDE->Random(fVelocity * 0.75f, fVelocity * 3.0f));
		VEC_ADD(vFire, vFire, vR);

		VEC_NORM(vFire);
		VEC_MULSCALAR(vFire, vFire, fVelocity);

		if (hClass)
			pProjectile = (CProjectile*)pServerDE->CreateObject(hClass, &ocStruct);

		if(pProjectile)
			pProjectile->Setup(&vFire, m_nWeaponType, fDamage, fVelocity, m_nRadius, m_hFiredFrom);
	}
}



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

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

CNapalmFireball::CNapalmFireball() : CProjectile(OT_SPRITE)
{
	m_bShockwave			= DFALSE;
	m_bExplosion			= DTRUE;
	m_bClientFX				= DFALSE;
	m_fLifeTime				= g_pServerDE->Random(1.5f,2.5f);

	m_pProjectileFilename	= "Sprites\\napalmprime.spr";
	m_pProjectileSkin		= 0;

	m_nDamageType			= DAMAGE_TYPE_EXPLODE;
	m_dwFlags				= m_dwFlags | FLAG_POINTCOLLIDE | FLAG_GRAVITY | FLAG_NOSLIDING;
	m_fStartTime			= g_pServerDE->GetTime();

	m_damage.SetGodMode(DTRUE);

	AddLight(150.0f, 1.0f, 0.75f, 0.0f);
	VEC_INIT(m_vInitScale);

	m_nBounces				= 0;
}


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

⌨️ 快捷键说明

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