本文整理汇总了C++中SimObject::Life方法的典型用法代码示例。如果您正苦于以下问题:C++ SimObject::Life方法的具体用法?C++ SimObject::Life怎么用?C++ SimObject::Life使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimObject
的用法示例。
在下文中一共展示了SimObject::Life方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
void
TacticalAI::SelectTarget()
{
if (!ship) {
roe = NONE;
return;
}
// unarmed vessels should never engage an enemy:
if (ship->Weapons().size() < 1)
roe = NONE;
SimObject* target = ship_ai->GetTarget();
SimObject* ward = ship_ai->GetWard();
// if not allowed to engage, drop and return:
if (roe == NONE) {
if (target)
ship_ai->DropTarget();
return;
}
// if we have abandoned our ward, drop and return:
if (ward && roe != AGRESSIVE) {
double d = (ward->Location() - ship->Location()).length();
double safe_zone = 50e3;
if (target) {
if (ship->IsStarship())
safe_zone = 100e3;
if (d > safe_zone) {
ship_ai->DropTarget();
return;
}
}
else {
if (d > safe_zone) {
return;
}
}
}
// already have a target, keep it:
if (target) {
if (target->Life()) {
CheckTarget();
// frigates need to be ready to abandon ship-type targets
// in favor of drone-type targets, others should just go
// with what they have:
if (ship->Class() != Ship::CORVETTE && ship->Class() != Ship::FRIGATE)
return;
// in case the check decided to drop the target:
target = ship_ai->GetTarget();
}
// if the old target is dead, forget it:
else {
ship_ai->DropTarget();
target = 0;
}
}
// if not allowed to acquire, forget it:
if (ship_ai->DropTime() > 0)
return;
if (roe == DIRECTED) {
if (target && target->Type() == SimObject::SIM_SHIP)
SelectTargetDirected((Ship*) target);
else if (navpt && navpt->GetTarget() && navpt->GetTarget()->Type() == SimObject::SIM_SHIP)
SelectTargetDirected((Ship*) navpt->GetTarget());
else
SelectTargetDirected();
}
else {
SelectTargetOpportunity();
// don't switch one ship target for another...
if (ship->Class() == Ship::CORVETTE || ship->Class() == Ship::FRIGATE) {
SimObject* potential_target = ship_ai->GetTarget();
if (target && potential_target && target != potential_target) {
if (target->Type() == SimObject::SIM_SHIP &&
potential_target->Type() == SimObject::SIM_SHIP) {
ship_ai->SetTarget(target);
}
}
}
}
}