예제 #1
0
//------------------------------------------------------------------------
void CItem::OnHit(float damage, const char* damageType)
{
    if(!m_properties.hitpoints)
        return;

    if(damageType && !stricmp(damageType, "repair"))
    {
        if (m_stats.health < m_properties.hitpoints) //repair only to maximum
        {
            bool destroyed = m_stats.health<=0.f;
            m_stats.health = min(float(m_properties.hitpoints),m_stats.health+damage);

            UpdateDamageLevel();

            if(destroyed && m_stats.health>0.f)
                OnRepaired();
        }
    }
    else
    {
        if (m_stats.health > 0.0f)
        {
            m_stats.health -= damage;

            UpdateDamageLevel();

            if (m_stats.health <= 0.0f)
            {
                m_stats.health = 0.0f;
                OnDestroyed();

                int n=(int)m_damageLevels.size();
                for (int i=0; i<n; ++i)
                {
                    SDamageLevel &level=m_damageLevels[i];
                    if (level.min_health==0 && level.max_health==0)
                    {
                        int slot=(m_stats.viewmode&eIVM_FirstPerson)?eIGS_FirstPerson:eIGS_ThirdPerson;

                        SpawnEffect(slot, level.effect, level.helper, Vec3Constants<float>::fVec3_Zero,
                                    Vec3Constants<float>::fVec3_OneZ, level.scale);
                    }
                }
            }
        }
    }
}
예제 #2
0
//------------------------------------------------------------------------
void CItem::OnReset()
{
    //Hidden entities must have physics disabled
    if(!GetEntity()->IsHidden())
        GetEntity()->EnablePhysics(true);

    DestroyedGeometry(false);
    m_stats.health = (float)m_properties.hitpoints;

    UpdateDamageLevel();

    if(m_sharedparams->params.scopeAttachment)
        DrawSlot(eIGS_Aux1,false); //Hide secondary FP scope

    if (m_properties.mounted && m_sharedparams->params.mountable)
    {
        MountAt(GetEntity()->GetWorldPos());

        SEntityPhysicalizeParams params;
        params.mass = 0;
        params.nSlot = -1; // todo: -1 doesn't work for characters
        params.type = PE_STATIC;
        GetEntity()->Physicalize(params);
    }
    else
    {
        SetViewMode(eIVM_ThirdPerson);

        if (m_properties.pickable)
        {
            const bool hasOwner = (GetOwnerId() != 0);
            Physicalize(hasOwner ? false : true, m_properties.physics);
            Pickalize(true, false);
        }
        else
            Physicalize(m_properties.physics, true);
    }

    GetEntity()->InvalidateTM();
}
예제 #3
0
//------------------------------------------------------------------------
bool CGunTurret::NetSerialize(TSerialize ser, EEntityAspects aspect, uint8 profile, int flags)
{
	// call base class
	if(!CWeapon::NetSerialize(ser, aspect, profile, flags))
		return false;

	if(aspect == ASPECT_STATEBITS)
	{
		bool was_destroyed = IsDestroyed();
		bool destr=was_destroyed;
		ser.Value("destroyed",destr,'bool');

		if(ser.IsReading() && destr != was_destroyed)
		{
			if(destr)
				OnDestroyed();
			else
			{
				OnRepaired();
			}
		}

		bool enabled = m_turretparams.enabled;
		ser.Value("enabled",m_turretparams.enabled,'bool');

		if(ser.IsReading() && enabled != m_turretparams.enabled)
			Activate(m_turretparams.enabled);

		ser.Value("health", m_stats.health, 'iii');

		if(ser.IsReading())
			UpdateDamageLevel();
	}

	if(aspect == ASPECT_GOALORIENTATION)
	{
		//adjust the range
		if(ser.IsReading())
		{
			float yaw = 0.f;
			ser.Value("target_yaw",yaw, 'frad');
			m_goalYaw = yaw<0.0f?yaw + gf_PI2:yaw;
		}
		else
		{
			float yaw = m_goalYaw>gf_PI?m_goalYaw - gf_PI2:m_goalYaw;
			ser.Value("target_yaw",yaw, 'frad');
		}

		ser.Value("target_pitch",m_goalPitch, 'frad');

		EntityId old_id = m_targetId;
		ser.Value("target", m_targetId, 'eid');

		if(old_id != m_targetId)
		{
			OnTargetLocked(m_targetId ? gEnv->pEntitySystem->GetEntity(m_targetId) : 0);
		}

		if(m_fireparams.deviation_amount != 0.f)
			ser.Value("deviation", m_deviationPos);
	}

	return true;
}