Exemplo 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;
}
void
FighterTacticalAI::SelectTargetDirected(Ship* tgt)
{
	Ship* potential_target = tgt;

	if (!tgt) {
		// try to target one of the element's objectives
		// (if it shows up in the contact list)

		Element* elem = ship->GetElement();

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

			if (objective) {
				SimObject* obj_sim_obj = objective->GetTarget();
				Ship*      obj_tgt     = 0;

				if (obj_sim_obj && obj_sim_obj->Type() == SimObject::SIM_SHIP)
				obj_tgt = (Ship*) obj_sim_obj;

				if (obj_tgt && ship->FindContact(obj_tgt))
				potential_target = obj_tgt;
			}
		}
	}

	if (!CanTarget(potential_target))
	potential_target = 0;

	ship_ai->SetTarget(potential_target);
	SelectSecondaryForTarget(potential_target);
}
Exemplo n.º 3
0
void
TacticalAI::SelectTargetDirected(Ship* tgt)
{
    Ship* potential_target = tgt;

    // try to target one of the element's objectives
    // (if it shows up in the contact list)

    if (!tgt) {
        Element* elem = ship->GetElement();

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

            if (objective) {
                SimObject* obj_sim_obj = objective->GetTarget();
                Ship*      obj_tgt     = 0;

                if (obj_sim_obj && obj_sim_obj->Type() == SimObject::SIM_SHIP)
                obj_tgt = (Ship*) obj_sim_obj;

                if (obj_tgt) {
                    ListIter<Contact> contact = ship->ContactList();
                    while (++contact && !potential_target) {
                        Ship* test = contact->GetShip();

                        if (obj_tgt == test) {
                            potential_target = test;
                        }
                    }
                }
            }
        }
    }

    if (!CanTarget(potential_target))
    potential_target = 0;

    ship_ai->SetTarget(potential_target);

    if (tgt && tgt == ship_ai->GetTarget())
    directed_tgtid = tgt->Identity();
    else
    directed_tgtid = 0;
}
Exemplo 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;
			}
		}
	}
}