bool FleeDoneState::CheckAlertLevel(idAI* owner) { // FleeDoneState terminates itself when the AI reaches Suspicious (aka Investigating) if (owner->AI_AlertIndex < ESearching) { // Alert index is too low for this state, fall back WrapUp(owner); return false; } // Alert Index is matching, return OK return true; }
// State machine manager. Layout and content of dialog panel will be changed here based on state. void ProfileWizard::UpdateState(const int change) { ShowStatus(wxEmptyString); if (SemanticCheck(m_State, change)) { m_State = (DialogState) RangeCheck(((int)m_State + change)); if (m_State >= 0 && m_State < NUM_PAGES) { const wxBitmap& bmp = *m_bitmaps[m_State]; m_bitmap->SetSize(bmp.GetSize()); m_bitmap->SetBitmap(bmp); } switch (m_State) { case STATE_GREETINGS: SetTitle(TitlePrefix + _("Introduction")); m_pPrevBtn->Enable(false); m_pGearLabel->Show(false); m_pGearChoice->Show(false); m_pUserProperties->Show(false); m_pWrapUp->Show(false); m_pInstructions->SetLabel(_("Welcome to the PHD2 'first light' wizard")); m_pHelpText->SetSizeHints(wxSize(-1, TallHelpHeight)); SetSizerAndFit(m_pvSizer); break; case STATE_CAMERA: SetTitle(TitlePrefix + _("Choose a Guide Camera")); m_pPrevBtn->Enable(true); m_pGearLabel->SetLabel(_("Guide Camera:")); m_pGearChoice->Clear(); m_pGearChoice->Append(GuideCamera::List()); if (m_SelectedCamera.length() > 0) m_pGearChoice->SetStringSelection(m_SelectedCamera); m_pGearLabel->Show(true); m_pGearChoice->Show(true); m_pUserProperties->Show(true); m_pWrapUp->Show(false); m_pHelpText->SetSizeHints(wxSize(-1, NormalHelpHeight)); SetSizerAndFit(m_pvSizer); m_pInstructions->SetLabel(_("Select your guide camera and specify the optical properties of your guiding set-up")); m_pInstructions->Wrap(TextWrapPoint); break; case STATE_MOUNT: SetTitle(TitlePrefix + _("Choose a Mount Connection")); m_pPrevBtn->Enable(true); m_pGearLabel->SetLabel(_("Mount:")); m_pGearChoice->Clear(); m_pGearChoice->Append(Scope::List()); if (m_SelectedMount.length() > 0) m_pGearChoice->SetStringSelection(m_SelectedMount); m_pUserProperties->Show(false); m_pInstructions->SetLabel(_("Select your mount connection - this will determine how guide signals are transmitted")); break; case STATE_AUXMOUNT: if (m_PositionAware) // Skip this state if the selected mount is already position aware { UpdateState(change); } else { SetTitle(TitlePrefix + _("Choose an Auxiliary Mount Connection (optional)")); m_pGearLabel->SetLabel(_("Aux Mount:")); m_pGearChoice->Clear(); m_pGearChoice->Append(Scope::AuxMountList()); m_pGearChoice->SetStringSelection(m_SelectedAuxMount); // SelectedAuxMount is never null m_pInstructions->SetLabel(_("Since your primary mount connection does not report pointing position, you may want to choose an 'Aux Mount' connection")); } break; case STATE_AO: SetTitle(TitlePrefix + _("Choose an Adaptive Optics Device (optional)")); m_pGearLabel->SetLabel(_("AO:")); m_pGearChoice->Clear(); m_pGearChoice->Append(StepGuider::List()); m_pGearChoice->SetStringSelection(m_SelectedAO); // SelectedAO is never null m_pInstructions->SetLabel(_("Specify your adaptive optics device if desired")); if (change == -1) // User is backing up in wizard dialog { // Assert UI state for gear selection m_pGearGrid->Show(true); m_pNextBtn->SetLabel(_("Next >")); m_pNextBtn->SetToolTip(_("Move forward to next screen")); m_pWrapUp->Show(false); } break; case STATE_WRAPUP: SetTitle(TitlePrefix + _("Finish Creating Your New Profile")); m_pGearGrid->Show(false); m_pWrapUp->Show(true); m_pNextBtn->SetLabel(_("Finish")); m_pNextBtn->SetToolTip(_("Finish creating the equipment profile")); m_pInstructions->SetLabel(_("Enter a name for your profile and optionally launch the process to build a dark library")); SetSizerAndFit(m_pvSizer); break; case STATE_DONE: WrapUp(); break; } } ShowHelp(m_State); }
// Gets called each time the mind is thinking void FleeDoneState::Think(idAI* owner) { if ( owner->AI_DEAD || owner->AI_KNOCKEDOUT ) // grayman #3317 - quit if KO'ed or dead { WrapUp(owner); owner->GetMind()->EndState(); return; } UpdateAlertLevel(); // Ensure we are in the correct alert level if (!CheckAlertLevel(owner)) { // terminate FleeDoneState when time is over WrapUp(owner); owner->GetMind()->EndState(); return; } // Let the AI check its senses owner->PerformVisualScan(); if (owner->AI_ALERTED) { // terminate FleeDoneState when the AI is alerted WrapUp(owner); owner->GetMind()->EndState(); return; // grayman #3474 } if ( !owner->emitFleeBarks ) // grayman #3474 { // not crying for help, time to end this state WrapUp(owner); owner->GetMind()->EndState(); return; } // Shortcut reference Memory& memory = owner->GetMemory(); if (!_searchForFriendDone) { idActor* friendlyAI = owner->FindFriendlyAI(-1); if ( friendlyAI != NULL) { // We found a friend, cry for help to him DM_LOG(LC_AI, LT_INFO)LOGSTRING("%s found friendly AI %s, crying for help\r", owner->name.c_str(),friendlyAI->name.c_str()); _searchForFriendDone = true; owner->movementSubsystem->ClearTasks(); owner->SetTurnRate(_oldTurnRate); owner->TurnToward(friendlyAI->GetPhysics()->GetOrigin()); //float distanceToFriend = (friendlyAI->GetPhysics()->GetOrigin() - owner->GetPhysics()->GetOrigin()).LengthFast(); // Cry for help // Create a new help message CommMessagePtr message(new CommMessage( CommMessage::RequestForHelp_CommType, owner, friendlyAI, NULL, memory.alertPos, memory.currentSearchEventID // grayman #3857 (was '0') )); CommunicationTaskPtr barkTask(new SingleBarkTask("snd_flee", message)); if (cv_ai_debug_transition_barks.GetBool()) { gameLocal.Printf("%d: %s flees, barks 'snd_flee'\n",gameLocal.time,owner->GetName()); } owner->commSubsystem->AddCommTask(barkTask); memory.lastTimeVisualStimBark = gameLocal.time; } else if (gameLocal.time >= _turnEndTime) { // We didn't find a friend, stop looking for them after some time _searchForFriendDone = true; owner->movementSubsystem->ClearTasks(); owner->SetTurnRate(_oldTurnRate); // Play the cowering animation owner->SetAnimState(ANIMCHANNEL_TORSO, "Torso_Cower", 4); owner->SetAnimState(ANIMCHANNEL_LEGS, "Legs_Cower", 4); } } }