Structs:State

From ZDoom Wiki
Jump to navigation Jump to search
Note: This feature is for ZScript only.

States are what store information about the current animation and logical state of an Actor or overlay. A state is not the entire sequence of a label but the single frame that defines what something is doing at that very moment. For instance:

Fire:
  PISG A 4;
  PISG B 6 A_FirePistol;
  PISG C 4;
  PISG B 5 A_ReFire;
  Goto Ready;

In the above case, there's not one state, but four. PISG A, B, C, and then B again all define separate states. They are all combined under one state sequence with the first being given the state label Fire. This also applies for stacked frames:

Ready:
  WEAP AAA 4 A_WeaponReady;
  WEAP BCB 4 A_WeaponReady;
  Loop;

The above has six states, WEAP A, A, A, B, C, and B. When using a function like ResolveState, the state returned is the one defined at the given label. For instance, calling ResolveState("Fire") would return the state PISG A 4;

An Actor's state can be gotten at any time via its curstate field, e.g. myActorPointer.curstate.

A PSprite current state can be obtained by first obtaining the PSprite pointer with FindPSprite on a PlayerInfo pointer, e.g. <PlayerPawn pointer>.player.FindPSprite(<layer number>), and from there PSprite's current state is its curstate field.

Fields

Note: All fields are defined as readonly.

  • State NextState
Stores a pointer to the next state in the sequence. If null, the Actor/PSprite is set to terminate after this state.
  • int sprite
The index of the sprite to use for this state. This is the same as GetSpriteIndex with the name of the sprite the state uses. This has a few notable base values:
  • 0 - Sprite is set to TNT1
  • 1 - State is set to be fixed i.e. doesn't change sprite or frame
  • 2 - Sprite is set to use the same sprite as the previous state
  • int16 Tics
The base duration of the state measured in tics.
  • uint16 TicRange
If non-zero, defines a random range for the duration. This is done via Tics + Random2[StateTics]() % (TicRange + 1)
  • uint8 Frame
The frame id to use for this state e.g. A = 0, B = 1, etc.
  • uint8 UseFlags
Defines where the state can be used e.g. in weapon overlays, in CustomInventory overlays, etc.
  • int Misc1
The x offset to give a PSprite layer via the Offset keyword.
  • int Misc2
The y offset to give an PSprite layer via the Offset keyword.
  • uint16 bSlow
The state is marked with the Slow keyword.
  • uint16 bFast
The state is marked with the Fast keyword.
  • bool bFullbright
The state is marked with the Bright keyword.
  • bool bNoDelay
The state is marked with the NoDelay keyword. This only has effect in the first state of the Spawn sequence.
  • bool bSameFrame
The state uses the same frame as the previous state.
  • bool bCanRaise
The state is marked with the CanRaise keyword.
  • bool bDehacked
The state has been replaced via DeHackEd.

Methods

Non-static

  • int DistanceTo(State other)
Returns the number of states from the current state to another state. (Verification needed)
  • bool ValidateSpriteFrame()
Returns true if the sprite for the state is valid (uses an existing graphic or TNT1). This is usually similar to calling GetSpriteTexture() and then calling IsValid() on the result, however, IsValid() returns true for TNT1A0, whereas ValidateSpriteFrame doesn't. Among other things, this is important when checking sprites on actors who were spawned dynamically (i.e. through Actor.Spawn or derivative functions) but have no valid sprites: when that happens, all their sprites are remapped to TNT1A0 so that the actor can exist but not render. ValidateSpriteName will catch these cases and report sprites as missing.
  • TextureID, bool, Vector2 GetSpriteTexture(int rotation, int skin = 0, Vector2 scale = (0,0))
Returns a TextureID of the sprite used in the calling state. The rotation argument is a value from 0 to 16 to account for sprite rotations (which support up to 16 angles), with 0 meaning "front", 8 meaning "back" and so on. Since states are available in static context, this doesn't require an actor pointer. For example, this is valid:
state s = GetDefaultByType("Cacodemon").spawnstate;
TextureID stex = s.GetSpriteTexture(8);
// stex now contains a TextureID for the HEADA5 sprite
  • bool InStateSequence(State base)
A non-static version of InStateSequence that can be called directly on a state.

See also