Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void CCrossbowBolt::BoltTouch( CBaseEntity *pOther )
- {
- trace_t tr, tr2;
- tr = BaseClass::GetTouchTrace();
- Vector vecNormalizedVel = GetAbsVelocity();
- // Damage person hit by the nail
- CBaseEntity *pevOwner = GetOwnerEntity();
- if (!pevOwner || !pOther)
- {
- UTIL_Remove(this);
- return;
- }
- // CrossbowBolt don't touch each other.
- if (dynamic_cast< CCrossbowBolt* >(pOther) == NULL)
- {
- Vector vVelNorm = GetAbsVelocity();
- VectorNormalize(vVelNorm);
- Vector vDamageForce = vVelNorm;
- Vector vDamagePosition = GetAbsOrigin();
- int iStartHealth = pOther->GetHealth();
- CTakeDamageInfo info(this, pevOwner, vDamageForce, vDamagePosition, m_takedamage, DMG_DISSOLVE);
- pOther->TakeDamage(info);
- // Did they take the damage?
- if (pOther->GetHealth() < iStartHealth)
- {
- SpawnBlood(GetAbsOrigin(), GetAbsVelocity(), pOther->BloodColor(), m_takedamage);
- }
- //Adrian: keep going through the glass.
- if (pOther->GetCollisionGroup() == COLLISION_GROUP_BREAKABLE_GLASS)
- return;
- if (!pOther->IsAlive())
- {
- // We killed it!
- const surfacedata_t *pdata = physprops->GetSurfaceData(tr.surface.surfaceProps);
- if (pdata->game.material == CHAR_TEX_GLASS)
- {
- return;
- }
- }
- // See if we struck the world
- if (pOther->GetMoveType() == MOVETYPE_NONE && !(tr.surface.flags & SURF_SKY))
- {
- EmitSound("Weapon_Crossbow.BoltHitWorld");
- // if what we hit is static architecture, can stay around for a while.
- Vector vecDir = GetAbsVelocity();
- float speed = VectorNormalize(vecDir);
- // See if we should reflect off this surface
- float hitDot = DotProduct(tr.plane.normal, -vecDir);
- if ((hitDot < 0.5f) && (speed > 100))
- {
- Vector vReflection = 2.0f * tr.plane.normal * hitDot + vecDir;
- QAngle reflectAngles;
- VectorAngles(vReflection, reflectAngles);
- SetLocalAngles(reflectAngles);
- SetAbsVelocity(vReflection * speed * 0.75f);
- // Start to sink faster
- SetGravity(1.0f);
- }
- else
- {
- SetThink(&CCrossbowBolt::SUB_Remove);
- SetNextThink(gpGlobals->curtime + 2.0f);
- //FIXME: We actually want to stick (with hierarchy) to what we've hit
- SetMoveType(MOVETYPE_NONE);
- Vector vForward;
- AngleVectors(GetAbsAngles(), &vForward);
- VectorNormalize(vForward);
- CEffectData data;
- data.m_vOrigin = tr.endpos;
- data.m_vNormal = vForward;
- data.m_nEntIndex = 0;
- DispatchEffect("BoltImpact", data);
- UTIL_ImpactTrace(&tr, DMG_BULLET);
- AddEffects(EF_NODRAW);
- SetTouch(NULL);
- SetThink(&CCrossbowBolt::SUB_Remove);
- SetNextThink(gpGlobals->curtime + 2.0f);
- if (m_pGlowSprite != NULL)
- {
- m_pGlowSprite->TurnOn();
- m_pGlowSprite->FadeAndDie(3.0f);
- }
- }
- // Shoot some sparks
- if (UTIL_PointContents(GetAbsOrigin()) != CONTENTS_WATER)
- {
- g_pEffects->Sparks(GetAbsOrigin());
- }
- }
- else
- {
- // Put a mark unless we've hit the sky
- if ((tr.surface.flags & SURF_SKY) == false)
- {
- UTIL_ImpactTrace(&tr, DMG_BULLET);
- }
- UTIL_Remove(this);
- }
- // play body "thwack" sound
- EmitSound("Weapon_Crossbow.BoltHitBody");
- if (tr.fraction < 1)
- {
- UTIL_ImpactTrace(&tr, DMG_DISSOLVE);
- }
- UTIL_Remove(this);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement