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


C++ Sim::GetElements方法代码示例

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


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

示例1:

void
Element::ResumeAssignment()
{
	SetAssignment(0);

	if (objectives.isEmpty())
	return;

	Instruction* objective = 0;

	for (int i = 0; i < objectives.size() && !objective; i++) {
		Instruction* instr = objectives[i];

		if (instr->Status() <= Instruction::ACTIVE) {
			switch (instr->Action()) {
			case Instruction::INTERCEPT:
			case Instruction::STRIKE:
			case Instruction::ASSAULT:
				objective = instr;
				break;
			}
		}
	}

	if (objective) {
		Sim* sim = Sim::GetSim();

		ListIter<Element> iter = sim->GetElements();
		while (++iter) {
			Element*    elem = iter.value();
			SimObject*  tgt  = objective->GetTarget();

			if (tgt && tgt->Type() == SimObject::SIM_SHIP && elem->Contains((const Ship*) tgt)) {
				SetAssignment(elem);
				return;
			}
		}
	}
}
开发者ID:The-E,项目名称:Starshatter-Experimental,代码行数:39,代码来源:Element.cpp

示例2: if

void
Instruction::Evaluate(Ship* ship)
{
    Sim* sim = Sim::GetSim();

    switch (action) {
    case VECTOR:
        break;

    case LAUNCH:
        if (ship->GetFlightPhase() == Ship::ACTIVE)
        SetStatus(COMPLETE);
        break;

    case DOCK:
    case RTB:
        if (sim->GetPlayerShip() == ship &&
                (ship->GetFlightPhase() == Ship::DOCKING ||
                    ship->GetFlightPhase() == Ship::DOCKED))
        SetStatus(COMPLETE);
        else if (ship->Integrity() < 1)
        SetStatus(FAILED);
        break;

    case DEFEND:
    case ESCORT:
        {
            bool found = false;
            bool safe  = true;

            ListIter<Element> iter = sim->GetElements();
            while (++iter && !found) {
                Element* e = iter.value();

                if (e->IsFinished() || e->IsSquadron())
                continue;

                if (e->Name() == tgt_name || 
                        (e->GetCommander() && e->GetCommander()->Name() == tgt_name)) {

                    found = true;

                    for (int i = 0; i < e->NumShips(); i++) {
                        Ship* s = e->GetShip(i+1);

                        if (s && s->Integrity() < 1)
                        SetStatus(FAILED);
                    }

                    if (status == PENDING) {
                        // if the element had a flight plan, and all nav points
                        // have been addressed, then the element is safe
                        if (e->FlightPlanLength() > 0) {
                            if (e->GetNextNavPoint() == 0)
                            SetStatus(COMPLETE);
                            else
                            safe = false;
                        }
                    }
                }
            }

            if (status == PENDING && safe &&
                    sim->GetPlayerShip() == ship &&
                    (ship->GetFlightPhase() == Ship::DOCKING ||
                        ship->GetFlightPhase() == Ship::DOCKED)) {
                SetStatus(COMPLETE);
            }
        }
        break;

    case PATROL:
    case SWEEP:
        {
            Sim* sim   = Sim::GetSim();
            bool alive = false;

            ListIter<Element> iter = sim->GetElements();
            while (++iter) {
                Element* e = iter.value();

                if (e->IsFinished() || e->IsSquadron())
                continue;

                if (e->GetIFF() && e->GetIFF() != ship->GetIFF()) {
                    for (int i = 0; i < e->NumShips(); i++) {
                        Ship* s = e->GetShip(i+1);

                        if (s && s->Integrity() >= 1)
                        alive = true;
                    }
                }
            }

            if (status == PENDING && !alive) {
                SetStatus(COMPLETE);
            }
        }
        break;

//.........这里部分代码省略.........
开发者ID:Banbury,项目名称:starshatter-open,代码行数:101,代码来源:Instruction.cpp

示例3:

void
FltDlg::OnMissionType(AWEvent* event)
{
	mission_type = -1;

	for (int i = 0; i < 6; i++) {
		if (mission_btn[i]) {
			if (mission_btn[i] == event->window) {
				mission_btn[i]->SetButtonState(1);
				mission_type = i;
			}
			else {
				mission_btn[i]->SetButtonState(0);
			}
		}
	}

	if (objective_list && mission_type > -1) {
		objective_list->ClearItems();

		char txt[32];
		Sim* sim = Sim::GetSim();
		ListIter<Element> iter = sim->GetElements();

		while (++iter) {
			Element* elem = iter.value();

			if (!elem->IsActive() || elem->IsFinished() || elem->IsSquadron())
			continue;

			CombatGroup*   group = elem->GetCombatGroup();
			int            iff   = elem->GetIFF();
			Ship*          s     = elem->GetShip(1);
			double         r     = 0;
			bool           con   = false;

			if (iff != ship->GetIFF()) {
				if (elem->IntelLevel() < Intel::LOCATED)
				continue;

				if (group && group->IntelLevel() < Intel::LOCATED)
				continue;
			}

			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;
				}
			}

			switch (mission_type) {
			case 1:  // INTERCEPT
				if (iff && iff != ship->GetIFF() && s && s->IsDropship()) {
					int item = objective_list->AddItem(elem->Name()) - 1;
					objective_list->SetItemText(item, 1, s->GetRegion()->Name());

					objective_list->SetItemText(item, 2, txt);
					objective_list->SetItemData(item, 2, (DWORD) r);
				}
				break;

			case 2:  // ASSAULT
				if (iff && iff != ship->GetIFF() && s && (s->IsStarship() || s->IsStatic())) {
					int item = objective_list->AddItem(elem->Name()) - 1;
					objective_list->SetItemText(item, 1, s->GetRegion()->Name());

					objective_list->SetItemText(item, 2, txt);
					objective_list->SetItemData(item, 2, (DWORD) r);
				}
				break;

			case 3:  // STRIKE
				if (iff && iff != ship->GetIFF() && s && s->IsGroundUnit()) {
					int item = objective_list->AddItem(elem->Name()) - 1;
					objective_list->SetItemText(item, 1, s->GetRegion()->Name());

					objective_list->SetItemText(item, 2, txt);
					objective_list->SetItemData(item, 2, (DWORD) r);
				}
				break;

			case 4:  // ESCORT
				if ((iff == 0 || iff == ship->GetIFF()) && (!s || !s->IsStatic())) {
					int item = objective_list->AddItem(elem->Name()) - 1;

					if (s) {
						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,代码行数:101,代码来源:FltDlg.cpp


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