当前位置: 首页>>代码示例>>C++>>正文


C++ Damage::Clear方法代码示例

本文整理汇总了C++中Damage::Clear方法的典型用法代码示例。如果您正苦于以下问题:C++ Damage::Clear方法的具体用法?C++ Damage::Clear怎么用?C++ Damage::Clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Damage的用法示例。


在下文中一共展示了Damage::Clear方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: CalculateTotalDamage

/**
* @param damage damage description for this weapon detonation
* Point defense and air cannons should use a different model
*/
void tcDamageModel::CalculateTotalDamage(tcWeaponObject* weapon, tcGameObject* target, Damage& damage)
{
    if ((weapon == 0) || (target == 0))
    {
        wxASSERT(false);
        return;
    }

    bool goodDetonation = weapon->IsGoodDetonation();

    damage.Clear();


    const tcWeaponDamage* weaponDamage = GetWeaponDamageModel(weapon);


    /* if missile is targeted and has scored direct hit, then apply
    ** kinetic damage from missile (big fragment) and apply
    ** internal damage assuming missile has delayed warhead that explodes
    ** after penetrating target exterior
    */
    if (weapon->IsDirectHit() && (weapon->GetIntendedTarget() == target->mnID))
    {
        float speed_collide = weapon->mcKin.CalculateRangeRate(target->mcKin);
        if (speed_collide < 0)
        {
            wxASSERT(false);
            speed_collide = 0; // opening range rate case, shouldnt happen
        }

        float kinEnergy_J = 0.5*weapon->GetMassKg()*speed_collide*speed_collide;

        // fractional damage from kinetic energy of impact
        damage.kinetic_J = kinEnergy_J;

        damage.isPenetration = weaponDamage->isPenetration;

        // treat blast and frag as the same for now
        damage.explosive_kg = weaponDamage->blastCharge_kg + weaponDamage->fragCharge_kg + weaponDamage->fragMetal_kg; 
        return;
    }

    // no damage for direct hit weapons to other targets, or if weapon is a dud
    if (weapon->IsDirectHit() || (!goodDetonation)) return;

	tcBallisticWeapon* ballistic = dynamic_cast<tcBallisticWeapon*>(weapon);
	if ((ballistic != 0) && ballistic->IsClusterBomb())
	{
		CalculateTotalDamageCluster(ballistic, target, damage);
		return;
	}


    // determine if this is an underwater or underground explosion
    bool underwaterExplosion = ((weapon->mcKin.mfAlt_m <= -1.0f) && (weapon->mcTerrain.mfHeight_m < -1.0f));
    bool targetUnderwater = (target->mcKin.mfAlt_m <= 0) && (target->mcTerrain.mfHeight_m < -1.0f);
    bool targetAbovewater = (target->mcKin.mfAlt_m >= -3.0f); // target can be both under and above water
    
    bool affectsTarget = (underwaterExplosion && targetUnderwater) || (!underwaterExplosion && targetAbovewater);
    if (!affectsTarget) return;


    float range_m = 1000.0f * weapon->mcKin.RangeToKmAlt(target->mcKin);

    //float cumulativeDamage = 0;

    if (underwaterExplosion)
    {
        float damageRange_m = range_m;
        Vec3 collisionPoint;
        float collisionRange_m;

        if (damageRange_m < 250.0f) // dont check collisions for distance platforms affected by blast
        {
            // check collision along ray to origin
            if (target->CalculateCollisionPointOrigin(weapon, collisionPoint, collisionRange_m))
            {
                // wxASSERT(collisionRange_m < damageRange_m);
                damageRange_m = std::min(damageRange_m, collisionRange_m);
            }

            // check collision along "up" ray
            if (target->CalculateCollisionPointDir(weapon, Vec3(0, 1, 0), collisionPoint, collisionRange_m))
            {
                damageRange_m = std::min(damageRange_m, collisionRange_m);
            }
        }

        damageRange_m = std::max(damageRange_m, 10.0f); // don't allow anything closer than 10 m

        damage.waterBlast_psi = CalculateWaterBlastOverpressure(damageRange_m, weaponDamage->blastCharge_kg);
#ifdef _DEBUG
        fprintf(stdout, "Underwater explosion, %s, range: %.1f m, blast: %.1f PSI\n", target->mzClass.c_str(), damageRange_m, damage.waterBlast_psi);
#endif
        return; // no thermal or frag damage underwater
    }
//.........这里部分代码省略.........
开发者ID:WarfareCode,项目名称:gcblue,代码行数:101,代码来源:tcDamageModel.cpp


注:本文中的Damage::Clear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。