コード例 #1
0
void
FighterTacticalAI::FindThreat()
{
	// pick the closest contact on Threat Warning System:
	Ship*       threat_ship          = 0;
	Shot*       threat_missile       = 0;
	double      threat_dist          = 1e9;

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

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

		if (contact->Threat(ship) && 
				(Game::GameTime() - contact->AcquisitionTime()) > THREAT_REACTION_TIME) {
			
			double rng = contact->Range(ship);

			if (contact->GetShot()) {
				threat_missile = contact->GetShot();
			}

			else if (rng < threat_dist && contact->GetShip()) {
				Ship* candidate = contact->GetShip();

				if (candidate->InTransition())
				continue;

				if (candidate->IsStarship() && rng < 50e3) {
					threat_ship = candidate;
					threat_dist = rng;
				}

				else if (candidate->IsDropship() && rng < 25e3) {
					threat_ship = candidate;
					threat_dist = rng;
				}

				// static and ground units:
				else if (rng < 30e3) {
					threat_ship = candidate;
					threat_dist = rng;
				}
			}
		}
	}

	ship_ai->SetThreat(threat_ship);
	ship_ai->SetThreatMissile(threat_missile);
}
コード例 #2
0
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);
}
コード例 #3
0
void
TacticalAI::CheckTarget()
{
    SimObject* tgt = ship_ai->GetTarget();

    if (!tgt) return;

    if (tgt->GetRegion() != ship->GetRegion()) {
        ship_ai->DropTarget();
        return;
    }

    if (tgt->Type() == SimObject::SIM_SHIP) {
        Ship* target = (Ship*) tgt;

        // has the target joined our side?
        if (target->GetIFF() == ship->GetIFF() && !target->IsRogue()) {
            ship_ai->DropTarget();
            return;
        }

        // is the target already jumping/breaking/dying?
        if (target->InTransition()) {
            ship_ai->DropTarget();
            return;
        }

        // have we been ordered to pursue the target?
        if (directed_tgtid) {
            if (directed_tgtid != target->Identity()) {
                ship_ai->DropTarget();
            }

            return;
        }

        // can we catch the target?
        if (target->Design()->vlimit  <= ship->Design()->vlimit ||
                ship->Velocity().length() <= ship->Design()->vlimit)
        return;

        // is the target now out of range?
        WeaponDesign* wep_dsn = ship->GetPrimaryDesign();
        if (!wep_dsn)
        return;

        // compute the "give up" range:
        double drop_range = 3 * wep_dsn->max_range;
        if (drop_range > 0.75 * ship->Design()->commit_range)
        drop_range = 0.75 * ship->Design()->commit_range;

        double range = Point(target->Location() - ship->Location()).length();
        if (range < drop_range)
        return;

        // is the target closing or separating?
        Point  delta = (target->Location() + target->Velocity()) -
        (ship->Location()   + ship->Velocity());

        if (delta.length() < range)
        return;

        ship_ai->DropTarget();
    }

    else if (tgt->Type() == SimObject::SIM_DRONE) {
        Drone* drone = (Drone*) tgt;

        // is the target still a threat?
        if (drone->GetEta() < 1 || drone->GetTarget() == 0)
        ship_ai->DropTarget();
    }
}