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


C++ SimObject::Life方法代码示例

本文整理汇总了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);
                }
            }
        }
    }
}
开发者ID:Banbury,项目名称:starshatter-open,代码行数:94,代码来源:TacticalAI.cpp


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