Esempio n. 1
0
bool
TacticalAI::CheckObjectives()
{
    bool     processed = false;
    Ship*    ward      = 0;
    Element* elem      = ship->GetElement();

    if (elem) {
        Instruction* obj = elem->GetTargetObjective();

        if (obj) {
            ship_ai->ClearPatrol();

            if (obj->Action()) {
                switch (obj->Action()) {
                case Instruction::INTERCEPT:
                case Instruction::STRIKE:
                case Instruction::ASSAULT:
                    {
                        SimObject* tgt = obj->GetTarget();
                        if (tgt && tgt->Type() == SimObject::SIM_SHIP) {
                            roe = DIRECTED;
                            SelectTargetDirected((Ship*) tgt);
                        }
                    }
                    break;

                case Instruction::DEFEND:
                case Instruction::ESCORT:
                    {
                        SimObject* tgt = obj->GetTarget();
                        if (tgt && tgt->Type() == SimObject::SIM_SHIP) {
                            roe = DEFENSIVE;
                            ward = (Ship*) tgt;
                        }
                    }
                    break;

                default:
                    break;
                }
            }

            orders    = obj;
            processed = true;
        }
    }

    ship_ai->SetWard(ward);
    return processed;
}
Esempio n. 2
0
Instruction*
Element::GetTargetObjective()
{
	for (int i = 0; i < objectives.size(); i++) {
		Instruction* obj = objectives[i];

		if (obj->Status() <= Instruction::ACTIVE) {
			switch (obj->Action()) {
			case Instruction::INTERCEPT:
			case Instruction::STRIKE:
			case Instruction::ASSAULT:
			case Instruction::SWEEP:
			case Instruction::PATROL:
			case Instruction::RECON:
			case Instruction::ESCORT:
			case Instruction::DEFEND:
				return obj;

			default:
				break;
			}
		}
	}

	return 0;
}
Esempio n. 3
0
bool
Element::IsObjectiveTargetOf(const Ship* s) const
{
	if (!s || launch_time == 0 || IsFinished())
	return false;

	const char* e_name = Name().data();
	int         e_len  = Name().length();

	Instruction* orders = s->GetRadioOrders();
	if (orders && orders->Action() > Instruction::SWEEP) {
		const char* o_name = orders->TargetName();
		int         o_len  = 0;

		if (o_name && *o_name)
		o_len = strlen(o_name);

		if (e_len < o_len)
		o_len = e_len;

		if (!strncmp(e_name, o_name, o_len))
		return true;
	}

	Element* elem = s->GetElement();
	if (elem) {
		for (int i = 0; i < elem->NumObjectives(); i++) {
			Instruction* obj = elem->GetObjective(i);

			if (obj) {
				const char* o_name = obj->TargetName();
				int         o_len  = 0;

				if (o_name && *o_name)
				o_len = strlen(o_name);

				if (e_len < o_len)
				o_len = e_len;

				if (!strncmp(e_name, o_name, o_len))
				return true;
			}
		}
	}

	return false;
}
Esempio n. 4
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;
			}
		}
	}
}
void
MsnElemDlg::Show()
{
	FormWindow::Show();

	if (!elem) return;

	int current_class = 0;

	if (cmb_class) {
		cmb_class->ClearItems();

		cmb_class->AddItem(Ship::ClassName(Ship::DRONE));
		cmb_class->AddItem(Ship::ClassName(Ship::FIGHTER));
		cmb_class->AddItem(Ship::ClassName(Ship::ATTACK));

		cmb_class->AddItem(Ship::ClassName(Ship::LCA));
		cmb_class->AddItem(Ship::ClassName(Ship::COURIER));
		cmb_class->AddItem(Ship::ClassName(Ship::CARGO));
		cmb_class->AddItem(Ship::ClassName(Ship::CORVETTE));
		cmb_class->AddItem(Ship::ClassName(Ship::FREIGHTER));
		cmb_class->AddItem(Ship::ClassName(Ship::FRIGATE));
		cmb_class->AddItem(Ship::ClassName(Ship::DESTROYER));
		cmb_class->AddItem(Ship::ClassName(Ship::CRUISER));
		cmb_class->AddItem(Ship::ClassName(Ship::BATTLESHIP));
		cmb_class->AddItem(Ship::ClassName(Ship::CARRIER));
		cmb_class->AddItem(Ship::ClassName(Ship::SWACS));
		cmb_class->AddItem(Ship::ClassName(Ship::DREADNAUGHT));
		cmb_class->AddItem(Ship::ClassName(Ship::STATION));
		cmb_class->AddItem(Ship::ClassName(Ship::FARCASTER));

		cmb_class->AddItem(Ship::ClassName(Ship::MINE));
		cmb_class->AddItem(Ship::ClassName(Ship::COMSAT));
		cmb_class->AddItem(Ship::ClassName(Ship::DEFSAT));

		cmb_class->AddItem(Ship::ClassName(Ship::BUILDING));
		cmb_class->AddItem(Ship::ClassName(Ship::FACTORY));
		cmb_class->AddItem(Ship::ClassName(Ship::SAM));
		cmb_class->AddItem(Ship::ClassName(Ship::EWR));
		cmb_class->AddItem(Ship::ClassName(Ship::C3I));
		cmb_class->AddItem(Ship::ClassName(Ship::STARBASE));

		const ShipDesign* design = elem->GetDesign();

		for (int i = 0; i < cmb_class->NumItems(); i++) {
			const char* cname   = cmb_class->GetItem(i);
			int         classid = Ship::ClassForName(cname);

			if (design && classid == design->type) {
				cmb_class->SetSelection(i);
				current_class = classid;
				break;
			}
		}
	}

	if (cmb_design) {
		OnClassSelect(0);
		OnDesignSelect(0);
	}

	if (cmb_role) {
		cmb_role->ClearItems();

		for (int i = Mission::PATROL; i <= Mission::OTHER; i++) {
			cmb_role->AddItem(Mission::RoleName(i));

			if (i == 0)
			cmb_role->SetSelection(0);

			else if (elem->MissionRole() == i)
			cmb_role->SetSelection(cmb_role->NumItems()-1);
		}
	}

	if (cmb_region) {
		cmb_region->ClearItems();

		if (mission) {
			StarSystem* sys = mission->GetStarSystem();
			if (sys) {
				List<OrbitalRegion> regions;
				regions.append(sys->AllRegions());
				regions.sort();

				ListIter<OrbitalRegion> iter = regions;
				while (++iter) {
					OrbitalRegion* region = iter.value();
					cmb_region->AddItem(region->Name());

					if (!strcmp(elem->Region(), region->Name()))
					cmb_region->SetSelection(cmb_region->NumItems()-1);
				}
			}
		}
	}

	char buf[64];

	if (edt_name)  edt_name->SetText(elem->Name());

	sprintf_s(buf, "%d", elem->Count());
	if (edt_size)  edt_size->SetText(buf);

	sprintf_s(buf, "%d", elem->GetIFF());
	if (edt_iff)   edt_iff->SetText(buf);

	sprintf_s(buf, "%d", (int) elem->Location().x / 1000);
	if (edt_loc_x) edt_loc_x->SetText(buf);

	sprintf_s(buf, "%d", (int) elem->Location().y / 1000);
	if (edt_loc_y) edt_loc_y->SetText(buf);

	sprintf_s(buf, "%d", (int) elem->Location().z / 1000);
	if (edt_loc_z) edt_loc_z->SetText(buf);

	sprintf_s(buf, "%d", elem->RespawnCount());
	if (edt_respawns) edt_respawns->SetText(buf);

	sprintf_s(buf, "%d", elem->HoldTime());
	if (edt_hold_time) edt_hold_time->SetText(buf);

	if (btn_player)      btn_player->SetButtonState(elem->Player() > 0 ? 1 : 0);
	if (btn_playable)    btn_playable->SetButtonState(elem->IsPlayable() ? 1 : 0);
	if (btn_alert)       btn_alert->SetButtonState(elem->IsAlert() ? 1 : 0);
	if (btn_command_ai)  btn_command_ai->SetButtonState(elem->CommandAI());

	UpdateTeamInfo();

	if (cmb_intel) {
		cmb_intel->ClearItems();

		for (int i = Intel::RESERVE; i < Intel::TRACKED; i++) {
			cmb_intel->AddItem(Intel::NameFromIntel(i));

			if (i == 0)
			cmb_intel->SetSelection(0);

			else if (elem->IntelLevel() == i)
			cmb_intel->SetSelection(cmb_intel->NumItems()-1);
		}
	}

	Instruction* instr = 0;
	if (elem->Objectives().size() > 0)
	instr = elem->Objectives().at(0);

	if (cmb_objective) {
		cmb_objective->ClearItems();
		cmb_objective->AddItem("");
		cmb_objective->SetSelection(0);

		for (int i = 0; i < Instruction::NUM_ACTIONS; i++) {
			cmb_objective->AddItem(Instruction::ActionName(i));

			if (instr && instr->Action() == i)
			cmb_objective->SetSelection(i+1);
		}
	}

	if (cmb_target) {
		OnObjectiveSelect(0);
	}

	if (cmb_heading) {
		double heading = elem->Heading();

		while (heading > 2*PI)
		heading -= 2*PI;

		while (heading < 0)
		heading += 2*PI;

		if (heading >= PI/4 && heading < 3*PI/4)
		cmb_heading->SetSelection(1);

		else if (heading >= 3*PI/4 && heading < 5*PI/4)
		cmb_heading->SetSelection(2);

		else if (heading >= 5*PI/4 && heading < 7*PI/4)
		cmb_heading->SetSelection(3);

		else
		cmb_heading->SetSelection(0);
	}

	exit_latch = true;
}