Ejemplo n.º 1
0
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;
			}
		}
	}
}
Ejemplo n.º 2
0
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;

    case INTERCEPT:
    case STRIKE:
    case ASSAULT:
        {
            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->Name() == tgt_name) {
                    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;

    case RECON:
        break;

    default:
        break;
    }
}
Ejemplo n.º 3
0
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);
					}

					else {
						objective_list->SetItemText(item, 1, "0");
						objective_list->SetItemData(item, 1, 0);
					}
				}
				break;

			case 5:  // SCOUT?
				break;

			default: break;
			}
		}
	}

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

		if (design) {
			ListIter<ShipLoad> sl = (List<ShipLoad>&) design->loadouts;
			while (++sl) {
				int item = loadout_list->AddItem(sl->name) - 1;

				char weight[32];
				sprintf_s(weight, "%d kg", (int) ((design->mass + sl->mass) * 1000));
				loadout_list->SetItemText(item, 1, weight);
				loadout_list->SetItemData(item, 1, (DWORD) (sl->mass * 1000));
			}
		}
	}
}