bool AScriptedMarine::GetWeaponStates(int weap, FState *&melee, FState *&missile) { static ENamedName WeaponNames[] = { NAME_None, NAME_Fist, NAME_Berserk, NAME_Chainsaw, NAME_Pistol, NAME_Shotgun, NAME_SSG, NAME_Chaingun, NAME_Rocket, NAME_Plasma, NAME_Railgun, NAME_BFG }; if (weap < WEAPON_Dummy || weap > WEAPON_BFG) weap = WEAPON_Dummy; melee = FindState(NAME_Melee, WeaponNames[weap], true); missile = FindState(NAME_Missile, WeaponNames[weap], true); return melee != NULL || missile != NULL; }
FState *AWeapon::GetAltAtkState (bool hold) { FState * state=NULL; if (hold) state = FindState(NAME_AltHold); if (state == NULL) state = FindState(NAME_AltFire); return state; }
void WIZARD::SetState (int stNew, BOOL fForce) { SendStateCommand (m_stCurrent, wcSTATE_LEAVE); int stOriginal = m_stCurrent; m_stCurrent = stNew; if (!fForce && SendStateCommand (stNew, wcIS_STATE_DISABLED)) { if (stOriginal <= stNew) { int st; for (st = stNew+1; st < (int)m_cStates; ++st) { LPWIZARD_STATE pState; if ((pState = FindState (st)) != NULL) { m_stCurrent = st; if (!SendStateCommand (st, wcIS_STATE_DISABLED)) break; m_stCurrent = stOriginal; SendStateCommand (st, wcSTATE_ENTER); SendStateCommand (st, wcSTATE_LEAVE); } } stNew = (st < (int)m_cStates) ? st : m_stCurrent; } else // (moving backwards?) { int st; for (st = stNew-1; st >= 0; --st) { LPWIZARD_STATE pState; if ((pState = FindState (st)) != NULL) { m_stCurrent = st; if (!SendStateCommand (st, wcIS_STATE_DISABLED)) break; m_stCurrent = stOriginal; SendStateCommand (st, wcSTATE_ENTER); SendStateCommand (st, wcSTATE_LEAVE); } } stNew = (st >= 0) ? st : m_stCurrent; } } m_stCurrent = stNew; SendStateCommand (m_stCurrent, wcSTATE_ENTER); if (m_fShowing) { Refresh (REFRESH_RIGHT_PANE); } }
bool ACustomInventory::TryPickup (AActor *&toucher) { FState *pickupstate = FindState(NAME_Pickup); bool useok = CallStateChain (toucher, pickupstate); if ((useok || pickupstate == NULL) && FindState(NAME_Use) != NULL) { useok = Super::TryPickup (toucher); } else if (useok) { GoAwayAndDie(); } return useok; }
void RemoveState(KEY key) { typename States::iterator it = FindState(key); if (it != states.end()) states.erase(it); }
void InstallStates(FActorInfo *info, AActor *defaults) { // First ensure we have a valid spawn state. FState * state = FindState(defaults, info->Class, "Spawn"); // Stateless actors that are direct subclasses of AActor // have their spawnstate default to something that won't // immediately destroy them. if (state == &AActor::States[2] && info->Class->ParentClass == RUNTIME_CLASS(AActor)) { AddState("Spawn", &AActor::States[0]); } else if (state == NULL) { // A NULL spawn state will crash the engine so set it to something that will make // the actor disappear as quickly as possible. AddState("Spawn", &AActor::States[2]); } if (info->StateList != NULL) { info->StateList->Destroy(); free(info->StateList); } info->StateList = CreateStateLabelList(StateLabels); // Cache these states as member veriables. defaults->SpawnState = info->FindState(NAME_Spawn); defaults->SeeState = info->FindState(NAME_See); // Melee and Missile states are manipulated by the scripted marines so they // have to be stored locally defaults->MeleeState = info->FindState(NAME_Melee); defaults->MissileState = info->FindState(NAME_Missile); }
void __fastcall TOrdEntryForm::OvcSpinner1Click(TObject *Sender, TOvcSpinState State, double Delta, bool Wrap) { int i; String CurState = ""; // Get the current value of the field TOvcSimpleField* sf = dynamic_cast<TOvcSimpleField*>(OvcSpinner1->FocusedControl); CurState = sf->AsString; if (CurState == "") if (State == ssUpBtn) i = 1; else i = MaxStates; else // Look for the state i = FindState(CurState); if (i != -1) { if (State == ssUpBtn) if (i == 1) i = MaxStates; else i--; else if (i == MaxStates) i = 1; else i++; TOvcSimpleField* sf = dynamic_cast<TOvcSimpleField*>(OvcSpinner1->FocusedControl); if (sf) sf->AsString = StateAbbrevs[i]; } }
void FStateDefinitions::InstallStates(PClassActor *info, AActor *defaults) { // First ensure we have a valid spawn state. FState *state = FindState("Spawn"); if (state == NULL) { // A NULL spawn state will crash the engine so set it to something valid. SetStateLabel("Spawn", GetDefault<AActor>()->SpawnState); } if (info->StateList != NULL) { info->StateList->Destroy(); M_Free(info->StateList); } info->StateList = CreateStateLabelList(StateLabels); // Cache these states as member veriables. defaults->SpawnState = info->FindState(NAME_Spawn); defaults->SeeState = info->FindState(NAME_See); // Melee and Missile states are manipulated by the scripted marines so they // have to be stored locally defaults->MeleeState = info->FindState(NAME_Melee); defaults->MissileState = info->FindState(NAME_Missile); }
//--------------------------------------------------------------------------- void __fastcall TOrdEntryForm::StateFieldUserCommand(TObject *Sender, WORD Command) { String CurState; int i; // Get the current value of the field TOvcSimpleField* sf = dynamic_cast<TOvcSimpleField*>(OvcSpinner1->FocusedControl); if (sf) { CurState = sf->AsString; if (CurState == "") if (Command == ccUser0) i = 1; else i = MaxStates; else // Look for the state i = FindState(CurState); if (i != -1) { if (Command == ccUser0) if (i == 1) i = MaxStates; else i--; else if (i == MaxStates) i = 1; else i++; sf->AsString = StateAbbrevs[i]; } } }
//----------------------------------------------------------------------- void Animator::Impl::CrossFade(std::string const& stateName, Duration const& transitionDuration) { if (nextAnimation) { return; } POMDOG_ASSERT(transitionDuration > Duration::zero()); POMDOG_ASSERT(!std::isnan(transitionDuration.count())); auto iter = FindState(animationGraph->States, stateName); POMDOG_ASSERT(iter != std::end(animationGraph->States)); if (iter == std::end(animationGraph->States)) { // Error: Cannot find the state return; } POMDOG_ASSERT(iter->Tree); nextAnimation = SkeletonAnimationState{}; nextAnimation->Node = std::shared_ptr<AnimationNode>(animationGraph, iter->Tree.get()); nextAnimation->Name = stateName; auto crossFade = std::make_shared<AnimationCrossFadeNode>(currentAnimation, *nextAnimation, transitionDuration, time); currentAnimation.Node = crossFade; time = AnimationTimeInterval::zero(); }
void AChickenPlayer::MorphPlayerThink () { if (health > 0) { // Handle beak movement P_UpdateBeak (this); } if (player->morphTics & 15) { return; } if (Vel.X == 0 && Vel.Y == 0 && pr_chickenplayerthink () < 160) { // Twitch view angle Angles.Yaw += pr_chickenplayerthink.Random2() * (360. / 256. / 32.); } if ((Z() <= floorz) && (pr_chickenplayerthink() < 32)) { // Jump and noise Vel.Z += JumpZ; FState * painstate = FindState(NAME_Pain); if (painstate != NULL) SetState (painstate); } if (pr_chickenplayerthink () < 48) { // Just noise S_Sound (this, CHAN_VOICE, "chicken/active", 1, ATTN_NORM); } }
void AInventory::GoAwayAndDie () { if (!GoAway ()) { flags &= ~MF_SPECIAL; SetState (FindState("HoldAndDestroy")); } }
void PushState(KEY key, StateCallback callback) { typename States::iterator it = FindState(key); if (it == states.end()) states.push_back(State(key, callback)); else Exception<StateRunner>::Raise(this, "Trying to register the same state twice"); }
void ATeleportFog::PostBeginPlay () { Super::PostBeginPlay (); S_Sound (this, CHAN_BODY, "misc/teleport", 1, ATTN_NORM); switch (gameinfo.gametype) { case GAME_Hexen: case GAME_Heretic: SetState(FindState(NAME_Raven)); break; case GAME_Strife: SetState(FindState(NAME_Strife)); break; default: break; } }
bool AWeapon::TryPickup (AActor *&toucher) { FState * ReadyState = FindState(NAME_Ready); if (ReadyState != NULL && ReadyState->GetFrame() < sprites[ReadyState->sprite].numframes) { return Super::TryPickup (toucher); } return false; }
void AInventory::Hide () { FState *HideSpecialState = NULL, *HideDoomishState = NULL; flags = (flags & ~MF_SPECIAL) | MF_NOGRAVITY; renderflags |= RF_INVISIBLE; if (gameinfo.gametype & GAME_Raven) { HideSpecialState = FindState("HideSpecial"); if (HideSpecialState == NULL) { HideDoomishState = FindState("HideDoomish"); } } else { HideDoomishState = FindState("HideDoomish"); if (HideDoomishState == NULL) { HideSpecialState = FindState("HideSpecial"); } } assert(HideDoomishState != NULL || HideSpecialState != NULL); if (HideSpecialState != NULL) { SetState (HideSpecialState); tics = 1400; if (PickupFlash != NULL) tics += 30; } else if (HideDoomishState != NULL) { SetState (HideDoomishState); tics = 1050; } if (RespawnTics != 0) { tics = RespawnTics; } }
void Run(EVENT_TYPE event) { typename States::iterator it = FindState(current_state); if (it != states.end()) { State& state = *it; state.callback(event); } }
//--------------------------------------------------------------------------- void __fastcall TOrdEntryForm::StateFieldUserValidation(TObject *Sender, WORD &ErrorCode) { String CurState; if (ErrorCode != 0) return; CurState = StateField->Text; if (CurState != "") if (FindState(CurState) == -1) ErrorCode = (Word)StateError; }
BOOL WIZARD::Template_ForwardMessage (HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) { HWND hRHS; if ((hRHS = GetRightHandWindow()) != NULL) return (BOOL)SendMessage (hRHS, msg, wp, lp); LPWIZARD_STATE pState; if ((pState = FindState (m_stCurrent)) != NULL) return (BOOL)CallWindowProc ((WNDPROC)(pState->dlgproc), hWnd, msg, wp, lp); return FALSE; }
BOOL WIZARD::SendStateCommand (int st, WIZARD_COMMAND wc) { BOOL rc = FALSE; LPWIZARD_STATE pState; if ((pState = FindState (st)) != NULL) { rc = (BOOL)CallWindowProc ((WNDPROC)(pState->dlgproc), NULL, WM_COMMAND, MAKEWPARAM(IDC_WIZARD,(WORD)wc), (LPARAM)this); } return rc; }
void PushChildren(const node& goal,const node& parent_node,OpenSetType* open_set, std::set<node>* closed_set) { node temp_node; temp_node.parent = parent_node.state; //look at each neighbor and if that action is in action && not in visited //then push it into the frontier and visited for(int direction=0;direction<8;direction++) { temp_node.state = parent_node.state+Direction(direction); //calculate the heuristic and path costs temp_node.path_cost = parent_node.path_cost+sqrt(pow(Direction(direction).x,2)+pow(Direction(direction).y,2)); if(parent_node.action[direction]==1) { //lookup the child in the closed list std::multiset<node,heuristic_comparison>::iterator found_at_frontier = FindState(temp_node.state,open_set); std::set<node>::iterator found_at = FindState(temp_node.state,closed_set); if(!(found_at==closed_set->end()) && (temp_node.path_cost > parent_node.path_cost)) { continue; } if(found_at_frontier==open_set->end() || (temp_node.path_cost < parent_node.path_cost)) { temp_node.parent = parent_node.state; int x_distance = goal.state.x-temp_node.state.x, y_distance = goal.state.y-temp_node.state.y; temp_node.heuristic_cost= sqrt(pow(x_distance,2)+pow(y_distance,2)); if(found_at_frontier!=open_set->end()) { open_set->erase(found_at_frontier); open_set->insert(temp_node); } else { open_set->insert(temp_node); } } } } }
bool AWeapon::CheckAmmo (int fireMode, bool autoSwitch, bool requireAmmo) { int altFire; int count1, count2; int enough, enoughmask; if ((dmflags & DF_INFINITE_AMMO) || (Owner->player->cheats & CF_INFINITEAMMO)) { return true; } if (fireMode == EitherFire) { bool gotSome = CheckAmmo (PrimaryFire, false) || CheckAmmo (AltFire, false); if (!gotSome && autoSwitch) { barrier_cast<APlayerPawn *>(Owner)->PickNewWeapon (NULL); } return gotSome; } altFire = (fireMode == AltFire); if (!requireAmmo && (WeaponFlags & (WIF_AMMO_OPTIONAL << altFire))) { return true; } count1 = (Ammo1 != NULL) ? Ammo1->Amount : 0; count2 = (Ammo2 != NULL) ? Ammo2->Amount : 0; enough = (count1 >= AmmoUse1) | ((count2 >= AmmoUse2) << 1); if (WeaponFlags & (WIF_PRIMARY_USES_BOTH << altFire)) { enoughmask = 3; } else { enoughmask = 1 << altFire; } if (altFire && FindState(NAME_AltFire) == NULL) { // If this weapon has no alternate fire, then there is never enough ammo for it enough &= 1; } if (((enough & enoughmask) == enoughmask) || (enough && (WeaponFlags & WIF_AMMO_CHECKBOTH))) { return true; } // out of ammo, pick a weapon to change to if (autoSwitch) { barrier_cast<APlayerPawn *>(Owner)->PickNewWeapon (NULL); } return false; }
void WIZARD::Refresh (DWORD dwRefFlags) { if (dwRefFlags & REFRESH_LEFT_PANE) { HWND hLHS; if ((hLHS = GetDlgItem (m_hWnd, m_idcLeftPane)) != NULL) { RECT rr; GetClientRect (hLHS, &rr); InvalidateRect (hLHS, &rr, TRUE); UpdateWindow (hLHS); } } if (dwRefFlags & REFRESH_RIGHT_PANE) { HWND hRHS; if ((hRHS = GetDlgItem (m_hWnd, m_idcRightPane)) != NULL) { HWND hOld = GetRightHandWindow(); LPWIZARD_STATE pState; if ((pState = FindState (m_stCurrent)) != NULL) { int stCurrent = m_stCurrent; HWND hNew; if ((hNew = ModelessDialogParam (pState->idd, m_hWnd, pState->dlgproc, pState->lp)) != NULL) { if (stCurrent != m_stCurrent) DestroyWindow (hNew); else { RECT rRHS; GetRectInParent (hRHS, &rRHS); SetWindowPos (hNew, NULL, rRHS.left, rRHS.top, cxRECT(rRHS), cyRECT(rRHS), SWP_NOZORDER | SWP_NOACTIVATE); SetWindowLong (hNew, GWL_ID, pState->idd); ShowWindow (hNew, SW_SHOW); ShowWindow (hRHS, SW_HIDE); } } } if (hOld != NULL) DestroyWindow (hOld); } } }
void AInventory::BecomeItem () { if (!(flags & (MF_NOBLOCKMAP|MF_NOSECTOR))) { UnlinkFromWorld (nullptr); flags |= MF_NOBLOCKMAP|MF_NOSECTOR; LinkToWorld (nullptr); } RemoveFromHash (); flags &= ~MF_SPECIAL; ChangeStatNum(STAT_INVENTORY); // stop all sounds this item is playing. for(int i = 1;i<=7;i++) S_StopSound(this, i); SetState (FindState("Held")); }
void AInventory::BecomeItem () { if (!(flags & (MF_NOBLOCKMAP|MF_NOSECTOR))) { UnlinkFromWorld (); if (sector_list) { P_DelSeclist (sector_list); sector_list = NULL; } flags |= MF_NOBLOCKMAP|MF_NOSECTOR; LinkToWorld (); } RemoveFromHash (); flags &= ~MF_SPECIAL; SetState (FindState("Held")); }
void WIZARD::Background_OnClose (void) { LPWIZARD_STATE pState; if (m_hWnd && IsWindow (m_hWnd)) { PostMessage (m_hWnd, WM_COMMAND, MAKEWPARAM(IDCANCEL,BN_CLICKED), (LPARAM)GetDlgItem(m_hWnd,IDCANCEL)); } else if ((pState = FindState (m_stCurrent)) != NULL) { CallWindowProc ((WNDPROC)(pState->dlgproc), m_hBkg, WM_COMMAND, MAKEWPARAM(IDCANCEL,BN_CLICKED), 0); } else { ShowBackground (FALSE); } }
//----------------------------------------------------------------------- void Animator::Impl::Play(std::string const& stateName) { POMDOG_ASSERT(animationGraph); POMDOG_ASSERT(!animationGraph->States.empty()); auto iter = FindState(animationGraph->States, stateName); POMDOG_ASSERT(iter != std::end(animationGraph->States)); if (iter == std::end(animationGraph->States)) { // Error: Cannot find the state return; } POMDOG_ASSERT(iter->Tree); currentAnimation.Node = std::shared_ptr<AnimationNode>(animationGraph, iter->Tree.get()); currentAnimation.Name = stateName; time = AnimationTimeInterval::zero(); }
void EpsilonClosure( Context* con, Node *dfa_node, State* s ) { if ( s == NULL ) return; DestorySSE(); while ( s != NULL ) { PushSSE( s ); s = s->next; } while ( ssetop != NULL ) { State* st = PopSSE(); StateEdge* se = sequeue; while ( se != NULL ) { if ( se->w == EPSILON && se->from->dummy == st->dummy && !FindState( dfa_node, se->to ) ) { AddState( dfa_node, MakeDfaState( con, se->to->dummy ) ); PushSSE( se->to ); } se = se->next; } } return; }
void ASwitchableDecoration::Deactivate (AActor *activator) { SetState (FindState(NAME_Inactive)); }
FState *AWeapon::GetStateForButtonName (FName button) { return FindState(button); }