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


C++ Contact::GetIFF方法代码示例

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


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

示例1: if

bool
QuitView::CanAccept()
{
    sim = Sim::GetSim();

    if (!sim || sim->IsNetGame())
    return true;

    Ship* player_ship = sim->GetPlayerShip();

    if (player_ship->MissionClock() < 60000) {
        RadioView::Message(Game::GetText("QuitView.too-soon"));
        RadioView::Message(Game::GetText("QuitView.abort"));
        return false;
    }

    ListIter<Contact> iter = player_ship->ContactList();
    while (++iter) {
        Contact* c = iter.value();
        Ship*    cship = c->GetShip();
        int      ciff  = c->GetIFF(player_ship);

        if (c->Threat(player_ship)) {
            RadioView::Message(Game::GetText("QuitView.threats-present"));
            RadioView::Message(Game::GetText("QuitView.abort"));
            return false;
        }

        else if (cship && ciff > 0 && ciff != player_ship->GetIFF()) {
            Point  delta = c->Location() - player_ship->Location();
            double dist  = delta.length();

            if (cship->IsDropship() && dist < 50e3) {
                RadioView::Message(Game::GetText("QuitView.threats-present"));
                RadioView::Message(Game::GetText("QuitView.abort"));
                return false;
            }

            else if (cship->IsStarship() && dist < 100e3) {
                RadioView::Message(Game::GetText("QuitView.threats-present"));
                RadioView::Message(Game::GetText("QuitView.abort"));
                return false;
            }
        }
    }

    return true;
}
开发者ID:Banbury,项目名称:starshatter-open,代码行数:48,代码来源:QuitView.cpp

示例2: while

void
GroundAI::SelectTarget()
{
    SimObject* potential_target = 0;

    // pick the closest combatant ship with a different IFF code:
    double target_dist = 1.0e15;

    Ship* current_ship_target = 0;

    ListIter<Contact> c_iter = ship->ContactList();
    while (++c_iter) {
        Contact* contact = c_iter.value();
        int      c_iff   = contact->GetIFF(ship);
        Ship*    c_ship  = contact->GetShip();
        Shot*    c_shot  = contact->GetShot();
        bool     rogue   = false;

        if (c_ship)
        rogue = c_ship->IsRogue();

        if (rogue || c_iff > 0 && c_iff != ship->GetIFF() && c_iff < 1000) {
            if (c_ship && !c_ship->InTransition()) {
                // found an enemy, check distance:
                double dist = (ship->Location() - c_ship->Location()).length();

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

        potential_target = current_ship_target;
    }

    SetTarget(potential_target);
}
开发者ID:Banbury,项目名称:starshatter-open,代码行数:39,代码来源:GroundAI.cpp

示例3: if

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

	Ship* potential_target    = 0;
	Shot* current_shot_target = 0;

	// pick the closest combatant ship with a different IFF code:
	double target_dist = 1.0e15;
	double min_dist    = 5.0e3;

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

	Ship* ward = 0;
	if (element_index > 1)
	ward = ship->GetLeader();

	// commit range for patrol/sweep is 80 Km
	// (about 2 minutes for a fighter at max speed)
	if (roe == FLEXIBLE || roe == AGRESSIVE)
	target_dist = ship->Design()->commit_range;

	if (roe < FLEXIBLE)
	target_dist = 0.5 * ship->Design()->commit_range;

	int class_limit = Ship::LCA;

	if (ship->Class() == Ship::ATTACK)
	class_limit = Ship::DESTROYER;

	ListIter<Contact> c_iter = ship->ContactList();
	while (++c_iter) {
		Contact* contact = c_iter.value();
		Ship*    c_ship  = contact->GetShip();
		Shot*    c_shot  = contact->GetShot();
		int      c_iff   = contact->GetIFF(ship);
		bool     rogue   = false;

		if (c_ship)
		rogue = c_ship->IsRogue();

		if (!rogue && (c_iff <= 0 || c_iff == ship->GetIFF() || c_iff == 1000))
		continue;

		// reasonable target?
		if (c_ship && c_ship->Class() <= class_limit && !c_ship->InTransition()) {
			if (!rogue) {
				SimObject* ttgt = c_ship->GetTarget();

				// if we are self-defensive, is this contact engaging us?
				if (roe == SELF_DEFENSIVE && ttgt != ship)
				continue;

				// if we are defending, is this contact engaging us or our ward?
				if (roe == DEFENSIVE && ttgt != ship && ttgt != ward)
				continue;
			}

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

			if (dist < 0.75 * target_dist) {

				// if on patrol, check target distance from navpoint:
				if (roe == FLEXIBLE && navpt) {
					double ndist = (navpt->Location().OtherHand() - c_ship->Location()).length();
					if (ndist > 80e3)
					continue;
				}

				potential_target = c_ship;
				target_dist = dist;
			}
		}

		else if (c_shot && c_shot->IsDrone()) {
			// found an enemy shot, do we have enough time to engage?
			if (c_shot->GetEta() < 10)
			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) && !current_shot_target->IsTracking(ward)) ||
						(dist < target_dist)) {
					current_shot_target = c_shot;
					target_dist = dist;
//.........这里部分代码省略.........
开发者ID:The-E,项目名称:Starshatter-Experimental,代码行数:101,代码来源:FighterTacticalAI.cpp

示例4: if


//.........这里部分代码省略.........
			sprintf_s(msg_buf, "%s.", TranslateVox("Acknowledged").data());
			else
			sprintf_s(msg_buf, "%s.", TranslateVox("Unable").data());
		}
		else if (msg->Sender()) {
			dst_buf[0] = 0;

			if (msg->Info().length()) {
				sprintf_s(msg_buf, "%s. %s", 
				TranslateVox(act_buf).data(),
				(const char*) msg->Info());
			}
			else {
				sprintf_s(msg_buf, "%s.", TranslateVox(act_buf).data());
			}
		}
		else {
			if (msg->Info().length()) {
				sprintf_s(msg_buf, "%s. %s", 
				TranslateVox(act_buf).data(),
				(const char*) msg->Info());
			}
			else {
				sprintf_s(msg_buf, "%s.", TranslateVox(act_buf).data());
			}
		}
	}

	else if (msg->Action() == RadioMessage::MOVE_PATROL) {
		sprintf_s(msg_buf, TranslateVox("Move patrol.").data());
	}

	else if (target && dst_ship && msg->Sender()) {
		Contact* c = msg->Sender()->FindContact(target);

		if (c && c->GetIFF(msg->Sender()) > 10) {
			sprintf_s(msg_buf, "%s %s.", TranslateVox(act_buf).data(), TranslateVox("unknown contact").data());
		}

		else {
			sprintf_s(msg_buf, "%s %s.", 
			TranslateVox(act_buf).data(),
			target->Name());
		}
	}

	else if (target) {
		sprintf_s(msg_buf, "%s %s.", 
		TranslateVox(act_buf).data(),
		target->Name());
	}

	else if (msg->Info().length()) {
		sprintf_s(msg_buf, "%s %s", 
		TranslateVox(act_buf).data(),
		(const char*) msg->Info());
	}

	else {
		strcpy_s(msg_buf, TranslateVox(act_buf).data());
	}

	char last_char = msg_buf[strlen(msg_buf)-1];
	if (last_char != '!' && last_char != '.' && last_char != '?')
	strcat_s(msg_buf, ".");

	// final format:
	if (dst_buf[0] && src_buf[0]) {
		sprintf_s(txt_buf, "%s %s. %s", TranslateVox(dst_buf).data(), TranslateVox(src_buf).data(), msg_buf);
		txt_buf[0] = toupper(txt_buf[0]);
	}

	else if (src_buf[0]) {
		sprintf_s(txt_buf, "%s. %s", TranslateVox(src_buf).data(), msg_buf);
		txt_buf[0] = toupper(txt_buf[0]);
	}

	else if (dst_buf[0]) {
		sprintf_s(txt_buf, "%s %s", TranslateVox(dst_buf).data(), msg_buf);
		txt_buf[0] = toupper(txt_buf[0]);
	}

	else {
		strcpy_s(txt_buf, msg_buf);
	}

	// vox:
	const char* path[8] = { "1", "1", "2", "3", "4", "5", "6", "7" };

	RadioVox* vox = new(__FILE__,__LINE__) RadioVox(vox_channel, path[vox_channel], txt_buf);

	vox->AddPhrase(dst_buf);
	vox->AddPhrase(src_buf);
	vox->AddPhrase(act_buf);

	if (vox && !vox->Start()) {
		RadioView::Message(txt_buf);
		delete vox;
	}
}
开发者ID:The-E,项目名称:Starshatter-Experimental,代码行数:101,代码来源:RadioTraffic.cpp


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