本文整理汇总了C++中Damage::getTotalDamage方法的典型用法代码示例。如果您正苦于以下问题:C++ Damage::getTotalDamage方法的具体用法?C++ Damage::getTotalDamage怎么用?C++ Damage::getTotalDamage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Damage
的用法示例。
在下文中一共展示了Damage::getTotalDamage方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: hit
void CSubStructure::hit(const b2Transform& trafo, Damage damage, vector2d position, vector2d direction)
{
// check that position is not inside the ship, otherwise move!
// first, raytrace against armour to find hit segment
b2RayCastInput rcin{position, position + direction, 1000};
b2RayCastOutput rcout;
ArmourSegment* armour_hit{};
for(auto& seg : mArmour)
{
b2EdgeShape temp;
temp.Set(seg.p1, seg.p2);
if(temp.RayCast(&rcout, rcin, trafo, 0))
{
rcin.maxFraction = rcout.fraction;
armour_hit = seg.armour.get();
}
}
// if there was an armour segment that was hit.
if(armour_hit)
{
damage = armour_hit->hit(damage);
}
// now, for the internal segments
struct HitCell
{
float frac;
IStructureCell* cell;
};
rcin.maxFraction = 10000;
std::vector<HitCell> hit_cells;
for(auto& cell : mCells)
{
if(physics::raycast(rcout, cell->shape(), rcin, trafo))
{
rcin.maxFraction = rcout.fraction;
hit_cells.push_back(HitCell{rcout.fraction, cell.get()});
}
}
// sort hits
std::sort( hit_cells.begin(), hit_cells.end(), [](HitCell a, HitCell b) { return a.frac < b.frac; } );
// now go through all cells and hit the components
/// \todo make damage processing more interesting here!
float internal_damage = 0.5 * damage.getTotalDamage();
mStructurePoints -= internal_damage;
for(auto& hc : hit_cells)
{
IStructureCell* cell = hc.cell;
std::size_t comp_count = cell->component_count();
float cmp_dmg = internal_damage / comp_count;
for(auto& c : cell->components())
{
internal_damage -= c.damage(cmp_dmg);
}
}
/// \todo hit event listener, including ship destruction
}