daily pastebin goal
50%
SHARE
TWEET

Untitled

a guest Oct 23rd, 2018 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void CCrossbowBolt::BoltTouch( CBaseEntity *pOther )
  2. {
  3.  
  4.     trace_t tr, tr2;
  5.     tr = BaseClass::GetTouchTrace();
  6.     Vector  vecNormalizedVel = GetAbsVelocity();
  7.  
  8.     // Damage person hit by the nail
  9.     CBaseEntity *pevOwner = GetOwnerEntity();
  10.     if (!pevOwner || !pOther)
  11.     {
  12.         UTIL_Remove(this);
  13.         return;
  14.     }
  15.  
  16.     // CrossbowBolt don't touch each other.
  17.     if (dynamic_cast< CCrossbowBolt* >(pOther) == NULL)
  18.     {
  19.         Vector vVelNorm = GetAbsVelocity();
  20.         VectorNormalize(vVelNorm);
  21.  
  22.         Vector vDamageForce = vVelNorm;
  23.         Vector vDamagePosition = GetAbsOrigin();
  24.  
  25.         int iStartHealth = pOther->GetHealth();
  26.         CTakeDamageInfo info(this, pevOwner, vDamageForce, vDamagePosition, m_takedamage, DMG_DISSOLVE);
  27.         pOther->TakeDamage(info);
  28.  
  29.         // Did they take the damage?
  30.         if (pOther->GetHealth() < iStartHealth)
  31.         {
  32.             SpawnBlood(GetAbsOrigin(), GetAbsVelocity(), pOther->BloodColor(), m_takedamage);
  33.         }
  34.  
  35.         //Adrian: keep going through the glass.
  36.         if (pOther->GetCollisionGroup() == COLLISION_GROUP_BREAKABLE_GLASS)
  37.             return;
  38.  
  39.         if (!pOther->IsAlive())
  40.         {
  41.             // We killed it!
  42.             const surfacedata_t *pdata = physprops->GetSurfaceData(tr.surface.surfaceProps);
  43.             if (pdata->game.material == CHAR_TEX_GLASS)
  44.             {
  45.                 return;
  46.             }
  47.         }
  48.  
  49.         // See if we struck the world
  50.         if (pOther->GetMoveType() == MOVETYPE_NONE && !(tr.surface.flags & SURF_SKY))
  51.         {
  52.             EmitSound("Weapon_Crossbow.BoltHitWorld");
  53.  
  54.             // if what we hit is static architecture, can stay around for a while.
  55.             Vector vecDir = GetAbsVelocity();
  56.             float speed = VectorNormalize(vecDir);
  57.  
  58.             // See if we should reflect off this surface
  59.             float hitDot = DotProduct(tr.plane.normal, -vecDir);
  60.  
  61.             if ((hitDot < 0.5f) && (speed > 100))
  62.             {
  63.                 Vector vReflection = 2.0f * tr.plane.normal * hitDot + vecDir;
  64.  
  65.                 QAngle reflectAngles;
  66.  
  67.                 VectorAngles(vReflection, reflectAngles);
  68.  
  69.                 SetLocalAngles(reflectAngles);
  70.  
  71.                 SetAbsVelocity(vReflection * speed * 0.75f);
  72.  
  73.                 // Start to sink faster
  74.                 SetGravity(1.0f);
  75.             }
  76.             else
  77.             {
  78.                 SetThink(&CCrossbowBolt::SUB_Remove);
  79.                 SetNextThink(gpGlobals->curtime + 2.0f);
  80.  
  81.                 //FIXME: We actually want to stick (with hierarchy) to what we've hit
  82.                 SetMoveType(MOVETYPE_NONE);
  83.  
  84.                 Vector vForward;
  85.  
  86.                 AngleVectors(GetAbsAngles(), &vForward);
  87.                 VectorNormalize(vForward);
  88.  
  89.                 CEffectData data;
  90.  
  91.                 data.m_vOrigin = tr.endpos;
  92.                 data.m_vNormal = vForward;
  93.                 data.m_nEntIndex = 0;
  94.  
  95.                 DispatchEffect("BoltImpact", data);
  96.  
  97.                 UTIL_ImpactTrace(&tr, DMG_BULLET);
  98.  
  99.                 AddEffects(EF_NODRAW);
  100.                 SetTouch(NULL);
  101.                 SetThink(&CCrossbowBolt::SUB_Remove);
  102.                 SetNextThink(gpGlobals->curtime + 2.0f);
  103.  
  104.                 if (m_pGlowSprite != NULL)
  105.                 {
  106.                     m_pGlowSprite->TurnOn();
  107.                     m_pGlowSprite->FadeAndDie(3.0f);
  108.                 }
  109.             }
  110.  
  111.             // Shoot some sparks
  112.             if (UTIL_PointContents(GetAbsOrigin()) != CONTENTS_WATER)
  113.             {
  114.                 g_pEffects->Sparks(GetAbsOrigin());
  115.             }
  116.         }
  117.         else
  118.         {
  119.             // Put a mark unless we've hit the sky
  120.             if ((tr.surface.flags & SURF_SKY) == false)
  121.             {
  122.                 UTIL_ImpactTrace(&tr, DMG_BULLET);
  123.             }
  124.  
  125.             UTIL_Remove(this);
  126.         }
  127.  
  128.         // play body "thwack" sound
  129.         EmitSound("Weapon_Crossbow.BoltHitBody");
  130.  
  131.         if (tr.fraction < 1)
  132.         {
  133.             UTIL_ImpactTrace(&tr, DMG_DISSOLVE);
  134.         }
  135.  
  136.         UTIL_Remove(this);
  137.     }
  138. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top