Esempio n. 1
0
void AvHHealingSpray::FireProjectiles(void)
{
	#ifdef AVH_SERVER
	
	// Look for entities in cone
	CBaseEntity* theCurrentEntity = NULL;
	vec3_t theOriginatingPosition = this->m_pPlayer->GetGunPosition();

	while((theCurrentEntity = UTIL_FindEntityInSphere(theCurrentEntity, theOriginatingPosition, kHealingSprayRange)) != NULL)
	{
		bool isSelf=(theCurrentEntity == this->m_pPlayer);
		// Can't affect self
//		if(theCurrentEntity != this->m_pPlayer)
//		{
			// If entity is in view cone, and within range
			if(isSelf  || this->m_pPlayer->FInViewCone(&theCurrentEntity->pev->origin) )
			{
				// UTIL_FindEntityInSphere doesn't seem to take height into account.  Make sure the entity is within range.
                float theMaxEntitySize = max(Length(theCurrentEntity->pev->mins), Length(theCurrentEntity->pev->maxs));

                vec3_t theVectorDiff;
                VectorSubtract(theCurrentEntity->pev->origin, theOriginatingPosition, theVectorDiff);
				float theDiff = Length(theVectorDiff) - theMaxEntitySize;

                if(theDiff < kHealingSprayRange/2)
				{
					// Make sure entity is in line of fire
					TraceResult tr;
					UTIL_TraceLine(theOriginatingPosition, theCurrentEntity->Center(), dont_ignore_monsters, dont_ignore_glass, ENT(pev)/*pentIgnore*/, &tr);

					CBaseEntity* theBlockedByEntity = CBaseEntity::Instance(tr.pHit);

					if((tr.flFraction == 1.0) || (theBlockedByEntity == theCurrentEntity))
					{
						// Heal friendly player or building in range 
                        float theFocusAmount = 1.0f;
                        if(AvHSHUGetIsWeaponFocusable(AvHWeaponID(this->m_iId)))
                        {
                            theFocusAmount = AvHPlayerUpgrade::GetFocusDamageUpgrade(this->m_pPlayer->pev->iuser4);
                        }
                        
						float theDamage = this->mDamage*theFocusAmount;
						AvHPlayer* thePlayer = dynamic_cast<AvHPlayer*>(theCurrentEntity);
						
						if(theCurrentEntity->pev->team == this->m_pPlayer->pev->team)
						{
							// Players and buildables heal armor too
							AvHBaseBuildable* theBuildable = dynamic_cast<AvHBaseBuildable*>(theCurrentEntity);
							const int theBuildableHealingSprayScalar = BALANCE_VAR(kHealingSprayBuildableScalar);
							if(thePlayer)
							{
								// Players heal by base amount, plus percentage of health
								float thePercentage = BALANCE_VAR(kHealingSprayPlayerPercent)/100.0f;
								theDamage += thePercentage*theCurrentEntity->pev->max_health;
								if ( isSelf ) theDamage *= 0.5f;
								thePlayer->Heal(theDamage, true);
							}
							else if(theBuildable)
							{
								// Structures heal base amount times scalar
                                float theAmount = theDamage*(float)theBuildableHealingSprayScalar;
								if(theBuildable->Regenerate(theAmount, true))
                                {
                                    // Award experience for healing the hive.  Might award a little more if barely wounded, but that seems OK.
                                    if(GetGameRules()->GetIsCombatMode() && (theBuildable->pev->iuser3 == AVH_USER3_HIVE))
                                    {
                                        AvHPlayer* theHealsprayingPlayer = dynamic_cast<AvHPlayer*>(this->m_pPlayer);
                                        if(theHealsprayingPlayer && (theHealsprayingPlayer->pev->team == theBuildable->pev->team))
                                        {
                                            float theCombatHealExperienceScalar = BALANCE_VAR(kCombatHealExperienceScalar);
                                            theHealsprayingPlayer->AwardExperienceForObjective(theAmount*theCombatHealExperienceScalar, theBuildable->GetMessageID());
                                        }
                                    }
                                }
							}
							else
							{
								theCurrentEntity->TakeHealth(theDamage, this->GetDamageType());
							}
						}
						else if(thePlayer)
						{
							thePlayer->TakeDamage(this->pev, this->m_pPlayer->pev, theDamage, this->GetDamageType());
						}
					}
				}
			}
//		}
	}
	
	#endif	
}