void SeekerAI::ExecFrame(double seconds) { // setup: FindObjective(); // adaptive behavior: Navigator(); }
void BrigadeClass::SetUnitOrders (int neworders, VU_ID oid) { Objective o,so; GridIndex x,y,dx,dy; Unit e; SetOrdered(1); SetUnitTactic(0); o = FindObjective(oid); #ifdef DEBUG if (gDumping) { FILE *fp; int id1; char buffer[256]; char name1[80],name2[80],timestr[80]; sprintf(buffer,"campaign\\save\\dump\\%d.BRI",GetCampID()); fp = fopen(buffer,"a"); if (fp) { if (o) { o->GetName(name1,79,FALSE); id1 = o->GetCampID(); } else { sprintf(name1,"NONE"); id1 = 0; } GetName(name2,79,FALSE); GetTimeString(TheCampaign.CurrentTime,timestr); sprintf(buffer,"%s (%d) ordered to %s %s (%d) @ %s.\n",name2,GetCampID(),OrderStr[neworders],name1,id1,timestr); fprintf(fp,buffer); fclose(fp); } else gDumping = 0; } #endif if (!o) return; o->GetLocation(&dx,&dy); GetLocation(&x,&y); if ((x != dx || y != dy) && GetMovementType() != NoMove) { SetMoving(1); SetUnitDestination(dx,dy); } SetTempDest(0); if (neworders == GetOrders() && oid == GetUnitObjectiveID()) return; DisposeWayPoints(); SetUnitObjective(oid); GroundUnitClass::SetUnitOrders(neworders); // Reset component ordered state e = GetFirstUnitElement(); while (e) { e->SetAssigned(0); e = GetNextUnitElement(); } // If this is near the front, send a low priority request for an enemy recon patrol if (o->IsNearfront()) { MissionRequestClass mis; mis.tot = Camp_GetCurrentTime() + (rand()%MIN_TASK_GROUND + 30) * CampaignMinutes; mis.vs = GetTeam(); mis.tot_type = TYPE_NE; o->GetLocation(&mis.tx,&mis.ty); mis.targetID = Id(); mis.mission = AMIS_RECONPATROL; mis.roe_check = ROE_AIR_OVERFLY; mis.RequestEnemyMission(); } // Let's make sure our objective tree jives with our assignment if (o->IsSecondary()) { so = o->GetObjectiveParent(); if (so) SetUnitPrimaryObj(so->Id()); SetUnitSecondaryObj(o->Id()); } else if (o->IsPrimary()) { SetUnitPrimaryObj(o->Id()); SetUnitSecondaryObj(o->Id()); } else { so = o->GetObjectiveParent(); if (so) { SetUnitSecondaryObj(so->Id()); o = so->GetObjectiveParent(); if (o) SetUnitPrimaryObj(o->Id()); } } }
void Weapon::Aim() { locked = false; centered = false; FindObjective(); if (target) { double az = 0; double el = 0; locked = CanLockPoint(obj_w, az, el, &objective); double spread_az = design->spread_az; double spread_el = design->spread_el; // beam sweep target: if (design->beam) { double factor = 0; double az_phase = 0; double el_phase = 0; if (target->Type() == SimObject::SIM_SHIP) { Ship* s = (Ship*) target; if (s->IsStarship()) { switch (sweep) { default: case SWEEP_NONE: factor = 0; break; case SWEEP_TIGHT: factor = 1; break; case SWEEP_WIDE: factor = 2; break; } } } if (factor > 0) { factor *= atan2(target->Radius(), (double) objective.z); for (int i = 0; i < nbarrels; i++) { if (beams && beams[i]) { az_phase = sin(beams[i]->Life() * 0.4 * PI); el_phase = sin(beams[i]->Life() * 1.0 * PI); break; } } az += factor * spread_az * az_phase; el += factor * spread_el * el_phase * 0.25; } } else if (!design->beam) { if (spread_az > 0) az += Random(-spread_az, spread_az); if (spread_el > 0) el += Random(-spread_el, spread_el); } AimTurret(az, -el); // check range for guided weapons: if (locked && guided) { double range = objective.length(); if (range > design->max_track) locked = false; else if (range > design->max_range) { if (firing) { if (RandomChance(1,4)) // 1 in 4 chance of locking anyway locked = false; } else { locked = false; } } } if (locked) { Point tloc = target->Location(); tloc = Transform(tloc); if (tloc.z > 1) { az = atan2(fabs(tloc.x), tloc.z); el = atan2(fabs(tloc.y), tloc.z); double firing_cone = 10*DEGREES; if (orders == MANUAL) firing_cone = 30*DEGREES; if (az < firing_cone && el < firing_cone) centered = true; } } } else { AimTurret(aim_az_rest, -aim_el_rest); } }
void NavAI::ExecFrame(double s) { if (!ship) return; seconds = s; ship->SetDirectorInfo(" "); if (ship->GetFlightPhase() == Ship::TAKEOFF) takeoff = true; else if (takeoff && ship->MissionClock() > 10000) takeoff = false; FindObjective(); Navigator(); // watch for disconnect: if (ShipCtrl::Toggled(KEY_AUTO_NAV)) { NavSystem* navsys = ship->GetNavSystem(); if (navsys) { HUDView::GetInstance()->SetHUDMode(HUDView::HUD_MODE_TAC); navsys->DisengageAutoNav(); Sim* sim = Sim::GetSim(); if (sim) { ship->SetControls(sim->GetControls()); return; } } } static double time_til_change = 0.0; if (time_til_change < 0.001) { if (ship->GetShield()) { Shield* shield = ship->GetShield(); double level = shield->GetPowerLevel(); if (ShipCtrl::KeyDown(KEY_SHIELDS_FULL)) { HUDSounds::PlaySound(HUDSounds::SND_SHIELD_LEVEL); shield->SetPowerLevel(100); time_til_change = 0.5f; } else if (ShipCtrl::KeyDown(KEY_SHIELDS_ZERO)) { HUDSounds::PlaySound(HUDSounds::SND_SHIELD_LEVEL); shield->SetPowerLevel(0); time_til_change = 0.5f; } else if (ShipCtrl::KeyDown(KEY_SHIELDS_UP)) { if (level < 25) level = 25; else if (level < 50) level = 50; else if (level < 75) level = 75; else level = 100; HUDSounds::PlaySound(HUDSounds::SND_SHIELD_LEVEL); shield->SetPowerLevel(level); time_til_change = 0.5f; } else if (ShipCtrl::KeyDown(KEY_SHIELDS_DOWN)) { if (level > 75) level = 75; else if (level > 50) level = 50; else if (level > 25) level = 25; else level = 0; HUDSounds::PlaySound(HUDSounds::SND_SHIELD_LEVEL); shield->SetPowerLevel(level); time_til_change = 0.5f; } } } else { time_til_change -= seconds; } if (ShipCtrl::Toggled(KEY_DECOY)) ship->FireDecoy(); if (ShipCtrl::Toggled(KEY_LAUNCH_PROBE)) ship->LaunchProbe(); if (ShipCtrl::Toggled(KEY_GEAR_TOGGLE)) ship->ToggleGear(); if (ShipCtrl::Toggled(KEY_NAVLIGHT_TOGGLE)) ship->ToggleNavlights(); if (drop_state < 0) { ship->DropOrbit(); return; } if (drop_state > 0) { ship->MakeOrbit(); return; } }