本文整理汇总了C++中CombatGroup::GetFirstUnit方法的典型用法代码示例。如果您正苦于以下问题:C++ CombatGroup::GetFirstUnit方法的具体用法?C++ CombatGroup::GetFirstUnit怎么用?C++ CombatGroup::GetFirstUnit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CombatGroup
的用法示例。
在下文中一共展示了CombatGroup::GetFirstUnit方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
void
CampaignPlanMovement::MoveUnit(CombatUnit* u)
{
if (u) {
// starship repair:
double damage = u->GetSustainedDamage();
if (damage > 0 && u->GetDesign()) {
int percent = (int) (100 * damage / u->GetDesign()->integrity);
if (percent > 50) {
u->SetSustainedDamage(0.90 * damage);
}
}
Point loc = u->Location();
Point dir = loc;
double dist = dir.Normalize();
const double MAX_RAD = 320e3;
const double MIN_DIST = 150e3;
if (dist < MAX_RAD) {
double scale = 1 - dist/MAX_RAD;
loc += dir * (Random(30e3, 90e3) * scale) + RandomDirection() * 10e3;
if (fabs(loc.z) > 20e3)
loc.z *= 0.1;
u->MoveTo(loc);
CombatGroup* g = u->GetCombatGroup();
if (g && g->Type() > CombatGroup::FLEET && g->GetFirstUnit() == u) {
g->MoveTo(loc);
if (g->IntelLevel() > Intel::KNOWN)
g->SetIntelLevel(Intel::KNOWN);
}
}
else if (dist > 1.25 * MAX_RAD) {
double scale = 1 - dist/MAX_RAD;
loc += dir * (Random(80e3, 120e3) * scale) + RandomDirection() * 3e3;
if (fabs(loc.z) > 20e3)
loc.z *= 0.1;
u->MoveTo(loc);
CombatGroup* g = u->GetCombatGroup();
if (g && g->Type() > CombatGroup::FLEET && g->GetFirstUnit() == u) {
g->MoveTo(loc);
if (g->IntelLevel() > Intel::KNOWN)
g->SetIntelLevel(Intel::KNOWN);
}
}
else {
loc += RandomDirection() * 30e3;
if (fabs(loc.z) > 20e3)
loc.z *= 0.1;
u->MoveTo(loc);
CombatGroup* g = u->GetCombatGroup();
if (g && g->Type() > CombatGroup::FLEET && g->GetFirstUnit() == u) {
g->MoveTo(loc);
if (g->IntelLevel() > Intel::KNOWN)
g->SetIntelLevel(Intel::KNOWN);
}
}
CombatUnit* closest_unit = 0;
double closest_dist = 1e6;
ListIter<CombatUnit> iter = all_units;
while (++iter) {
CombatUnit* unit = iter.value();
if (unit->GetCombatGroup() != u->GetCombatGroup() && unit->GetRegion() == u->GetRegion() && !unit->IsDropship()) {
Point delta = loc - unit->Location();
dist = delta.Normalize();
if (dist < closest_dist) {
closest_unit = unit;
closest_dist = dist;
}
}
}
if (closest_unit && closest_dist < MIN_DIST) {
Point delta = loc - closest_unit->Location();
dist = delta.Normalize();
loc += delta * 1.1 * (MIN_DIST - closest_dist);
//.........这里部分代码省略.........