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


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

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


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

示例1: if

void
TacticalAI::SelectTargetOpportunity()
{
    // NON-COMBATANTS do not pick targets of opportunity:
    if (ship->GetIFF() == 0)
    return;

    SimObject* potential_target = 0;

    // pick the closest combatant ship with a different IFF code:
    double target_dist = ship->Design()->commit_range;

    SimObject* ward   = ship_ai->GetWard();

    // FRIGATES are primarily anti-air platforms, but may
    // also attack smaller starships:

    if (ship->Class() == Ship::CORVETTE || ship->Class() == Ship::FRIGATE) {
        Ship* current_ship_target = 0;
        Shot* current_shot_target = 0;

        // if we are escorting a larger warship, it is good to attack
        // the same target as our ward:

        if (ward) {
            Ship* s = (Ship*) ward;

            if (s->Class() > ship->Class()) {
                SimObject* obj = s->GetTarget();

                if (obj && obj->Type() == SimObject::SIM_SHIP) {
                    current_ship_target = (Ship*) obj;
                    target_dist = (ship->Location() - obj->Location()).length();
                }
            }
        }

        ListIter<Contact> contact = ship->ContactList();
        while (++contact) {
            Ship* c_ship = contact->GetShip();
            Shot* c_shot = contact->GetShot();

            if (!c_ship && !c_shot)
            continue;

            int   c_iff  = contact->GetIFF(ship);
            bool  rogue  = c_ship && c_ship->IsRogue();
            bool  tgt_ok = c_iff > 0               &&
            c_iff != ship->GetIFF() &&
            c_iff < 1000;

            if (rogue || tgt_ok) {
                if (c_ship && c_ship != ship && !c_ship->InTransition()) {
                    if (c_ship->Class() <  Ship::DESTROYER || 
                            (c_ship->Class() >= Ship::MINE && c_ship->Class() <= Ship::DEFSAT)) {
                        // found an enemy, check distance:
                        double dist = (ship->Location() - c_ship->Location()).length();

                        if (dist < 0.75 * target_dist &&
                                (!current_ship_target || c_ship->Class() <= current_ship_target->Class())) {
                            current_ship_target = c_ship;
                            target_dist = dist;
                        }
                    }
                }

                else if (c_shot) {
                    // found an enemy shot, is there enough time to engage?
                    if (c_shot->GetEta() < 3)
                    continue;

                    // found an enemy shot, check distance:
                    double dist = (ship->Location() - c_shot->Location()).length();

                    if (!current_shot_target) {
                        current_shot_target = c_shot;
                        target_dist = dist;
                    }

                    // is this shot a better target than the one we've found?
                    else {
                        Ship* ward = ship_ai->GetWard();

                        if ((c_shot->IsTracking(ward) || c_shot->IsTracking(ship)) &&
                                (!current_shot_target->IsTracking(ward) || 
                                    !current_shot_target->IsTracking(ship))) {
                            current_shot_target = c_shot;
                            target_dist = dist;
                        }
                        else if (dist < target_dist) {
                            current_shot_target = c_shot;
                            target_dist = dist;
                        }
                    }
                }
            }
        }

        if (current_shot_target)
        potential_target = current_shot_target;
//.........这里部分代码省略.........
开发者ID:Banbury,项目名称:starshatter-open,代码行数:101,代码来源:TacticalAI.cpp


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