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


C++ ListIter::GetShip方法代码示例

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


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

示例1: while

void
TacticalAI::SelectTargetDirected(Ship* tgt)
{
    Ship* potential_target = tgt;

    // try to target one of the element's objectives
    // (if it shows up in the contact list)

    if (!tgt) {
        Element* elem = ship->GetElement();

        if (elem) {
            Instruction* objective = elem->GetTargetObjective();

            if (objective) {
                SimObject* obj_sim_obj = objective->GetTarget();
                Ship*      obj_tgt     = 0;

                if (obj_sim_obj && obj_sim_obj->Type() == SimObject::SIM_SHIP)
                obj_tgt = (Ship*) obj_sim_obj;

                if (obj_tgt) {
                    ListIter<Contact> contact = ship->ContactList();
                    while (++contact && !potential_target) {
                        Ship* test = contact->GetShip();

                        if (obj_tgt == test) {
                            potential_target = test;
                        }
                    }
                }
            }
        }
    }

    if (!CanTarget(potential_target))
    potential_target = 0;

    ship_ai->SetTarget(potential_target);

    if (tgt && tgt == ship_ai->GetTarget())
    directed_tgtid = tgt->Identity();
    else
    directed_tgtid = 0;
}
开发者ID:Banbury,项目名称:starshatter-open,代码行数:45,代码来源:TacticalAI.cpp

示例2: if

void
TacticalAI::FindThreat()
{
    // pick the closest contact on Threat Warning System:
    Ship*       threat               = 0;
    Shot*       threat_missile       = 0;
    Ship*       rumor                = 0;
    double      threat_dist          = 1e9;
    const DWORD THREAT_REACTION_TIME = 1000; // 1 second

    ListIter<Contact> iter = ship->ContactList();

    while (++iter) {
        Contact* contact = iter.value();

        if (contact->Threat(ship) && 
                (Game::GameTime() - contact->AcquisitionTime()) > THREAT_REACTION_TIME) {

            if (contact->GetShot()) {
                threat_missile = contact->GetShot();
                rumor = (Ship*) threat_missile->Owner();
            }
            else {
                double rng = contact->Range(ship);

                Ship* c_ship = contact->GetShip();
                if (c_ship && !c_ship->InTransition()    &&
                        c_ship->Class() != Ship::FREIGHTER &&
                        c_ship->Class() != Ship::FARCASTER) {

                    if (c_ship->GetTarget() == ship) {
                        if (!threat || c_ship->Class() > threat->Class()) {
                            threat      = c_ship;
                            threat_dist = 0;
                        }
                    }
                    else if (rng < threat_dist) {
                        threat      = c_ship;
                        threat_dist = rng;
                    }
                }
            }
        }
    }

    if (rumor && !rumor->InTransition()) {
        iter.reset();

        while (++iter) {
            if (iter->GetShip() == rumor) {
                rumor = 0;
                ship_ai->ClearRumor();
                break;
            }
        }
    }
    else {
        rumor = 0;
        ship_ai->ClearRumor();
    }

    ship_ai->SetRumor(rumor);
    ship_ai->SetThreat(threat);
    ship_ai->SetThreatMissile(threat_missile);
}
开发者ID:Banbury,项目名称:starshatter-open,代码行数:65,代码来源:TacticalAI.cpp

示例3: ZeroAim

void
Weapon::SelectTarget()
{
    bool        select_locked = false;
    SimObject*  targ = 0;
    double      dist = 1e9;
    double      az   = 0;
    double      el   = 0;

    if (ammo && enabled && (availability > crit_level)) {
        ZeroAim();

        ListIter<Contact> contact = ship->ContactList();

        // lock onto any threatening shots first (if we can):
        if (design->target_type & Ship::DRONE) {
            while (++contact) {
                Shot* c_shot = contact->GetShot();

                if (c_shot && contact->Threat(ship)) {

                    // distance from self to target:
                    double distance = Point(c_shot->Location() - muzzle_pts[0]).length();

                    if (distance > design->min_range && 
                            distance < design->max_range && 
                            distance < dist) {
                        // check aim basket:
                        select_locked = CanLockPoint(c_shot->Location(), az, el);

                        if (select_locked) {
                            targ = c_shot;
                            dist = distance;
                        }
                    }
                }
            }
        }

        // lock onto a threatening ship only if it is (much) closer:
        dist *= 0.2;
        contact.reset();
        while (++contact) {
            Ship* c_ship  = contact->GetShip();

            if (!c_ship) continue;

            // can we lock onto this target?
            if ((c_ship->IsRogue() || c_ship->GetIFF() > 0 && c_ship->GetIFF() != ship->GetIFF()) &&
                    (c_ship->Class() & design->target_type) &&
                    c_ship->Weapons().size() > 0) {
                // distance from self to target:
                double distance = Point(c_ship->Location() - muzzle_pts[0]).length();

                if (distance < design->max_range && distance < dist) {
                    // check aim basket:
                    select_locked = CanLockPoint(c_ship->Location(), az, el);

                    if (select_locked) {
                        targ = c_ship;
                        dist = distance;
                    }
                }
            }
        }
    }

    if (!ammo || !enabled) {
        SetTarget(0,0);
        locked = false;
    }

    else {
        SetTarget(targ, 0);
    }
}
开发者ID:Banbury,项目名称:starshatter-open,代码行数:76,代码来源:Weapon.cpp


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