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


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

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


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

示例1:

void
FltDlg::UpdateObjective()
{
	if (!objective_list || mission_type < 0 || !ship) return;

	Sim* sim = Sim::GetSim();
	char txt[32];

	for (int item = 0; item < objective_list->NumItems(); item++) {
		const char* obj_name = objective_list->GetItemText(item);

		Element* elem = sim->FindElement(obj_name);

		// if element has expired, remove it from the objective list
		if (!elem || !elem->IsActive() || elem->IsFinished()) {
			objective_list->RemoveItem(item);
			item--;
		}

		// otherwise, the element is still active, so update range/region
		else {
			Ship*    s   = elem->GetShip(1);
			double   r   = 0;
			bool     con = false;

			if (s) {
				Point s_loc = s->Location()    + s->GetRegion()->Location();
				Point h_loc = ship->Location() + ship->GetRegion()->Location();

				r = (s_loc - h_loc).length();

				con = ship->FindContact(s) != 0;

				if (con) {
					FormatNumber(txt, r);
				}
				else {
					strcpy_s(txt, Game::GetText("FltDlg.Unknown").data());
					r = 2e9;
				}
			}

			objective_list->SetItemText(item, 1, s->GetRegion()->Name());

			objective_list->SetItemText(item, 2, txt);
			objective_list->SetItemData(item, 2, (DWORD) r);
		}
	}
}
开发者ID:lightgemini78,项目名称:Starshatter-Rearmed,代码行数:49,代码来源:FltDlg.cpp

示例2: Update

bool
CameraDirector::Update(SimObject* obj)
{
    if (obj->Type() == SimObject::SIM_SHIP) {
        Ship* s = (Ship*) obj;
        if (ship == s)
        ship = 0;

        if (external_ship == s) {
            external_point = s->Location();
            external_ship = 0;
        }

        if (external_group.contains(s))
        external_group.remove(s);
    }

    return SimObserver::Update(obj);
}
开发者ID:Banbury,项目名称:starshatter-open,代码行数:19,代码来源:CameraDirector.cpp

示例3: if

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();
    }
}
开发者ID:Banbury,项目名称:starshatter-open,代码行数:73,代码来源:TacticalAI.cpp

示例4: if

bool
MissionEvent::CheckTrigger()
{
	Sim* sim = Sim::GetSim();

	if (time > 0 && time > sim->MissionClock())
	return false;

	switch (trigger) {
	case TRIGGER_TIME: {
			if (time <= sim->MissionClock())
			Activate();
		}
		break;

	case TRIGGER_DAMAGE: {
			Ship* ship = sim->FindShip(trigger_ship);
			if (ship) {
				double damage = 100.0 * (ship->Design()->integrity - ship->Integrity()) /
				(ship->Design()->integrity);
				
				if (damage >= trigger_param[0])
				Activate();
			}
		}
		break;

	case TRIGGER_DETECT: {
			Ship* ship = sim->FindShip(trigger_ship);
			Ship* tgt  = sim->FindShip(trigger_target);
			
			if (ship && tgt) {
				if (ship->FindContact(tgt))
				Activate();
			}
			else {
				Skip();
			}
		}
		break;

	case TRIGGER_RANGE: {
			Ship* ship = sim->FindShip(trigger_ship);
			Ship* tgt  = sim->FindShip(trigger_target);
			
			if (ship && tgt) {
				double range     = (ship->Location() - tgt->Location()).length();
				double min_range = 0;
				double max_range = 1e12;

				if (trigger_param[0] > 0)
				min_range = trigger_param[0];
				else
				max_range = -trigger_param[0];

				if (range < min_range || range > max_range)
				Activate();
			}
			else {
				Skip();
			}
		}
		break;

	case TRIGGER_SHIPS_LEFT: {
			int alive   = 0;
			int count   = 0;
			int iff     = -1;
			int nparams = NumTriggerParams();

			if (nparams > 0) count = TriggerParam(0);
			if (nparams > 1) iff   = TriggerParam(1);

			ListIter<SimRegion> iter = sim->GetRegions();
			while (++iter) {
				SimRegion* rgn = iter.value();

				ListIter<Ship> s_iter = rgn->Ships();
				while (++s_iter) {
					Ship* ship = s_iter.value();

					if (ship->Type() >= Ship::STATION)
					continue;

					if (ship->Life() == 0 && ship->RespawnCount() < 1)
					continue;

					if (iff < 0 || ship->GetIFF() == iff)
					alive++;
				}
			}

			if (alive <= count)
			Activate();
		}
		break;

	case TRIGGER_EVENT_ALL: {
			bool  all     = true;
			int   nparams = NumTriggerParams();
//.........这里部分代码省略.........
开发者ID:The-E,项目名称:Starshatter-Experimental,代码行数:101,代码来源:MissionEvent.cpp


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