IsHostile

From ZDoom Wiki
Jump to navigation Jump to search

Actor

native clearscope bool IsHostile(Actor other) const

Usage

Checks if the calling actor is hostile to the other actor. This is meant to be run on monsters to determine their allegiance.

This is not a direct opposite of IsFriend, since the set of checks is slightly different.

Parameters

  • Actor other
Pointer to the actor, whose allegiance should be compared to.

Return values

First, checks whether the actors have the FRIENDLY flag:

  • Neither has it — function returns false
  • Only one has it — function returns true
Note: PlayerPawn actually does have the FRIENDLY flag by default (this flag is sometimes overlooked), so this function CAN be used on player pawns.


If both actors have the FRIENDLY flag, the function performs a series of checks based on current gamemode:

If the mode is specifically team deathmatch, returns true if
  • the actors are not teammates (determined by calling IsTeammate)
  • OR the caller does not have a friendplayer (its FriendPlayer field is 0)
  • OR the other actor does not have a friendplayer (its FriendPlayer field is 0)
  • OR both actors have friendplayers but those players are not teammates
If all of the checks above fail, the function returns false.
In other game modes, the function returns true if
  • the game mode is some other kind of deathmatch
  • AND the calling actor has a friendplayer
  • AND the other actor has a friendplayer
  • AND those friendplayers are different players and not teammates
If at least one of the checks above fails, the function returns false.

As a diagram:

Does the caller have the FRIENDLY flag?
 └─ No →
     Does other have the FRIENDLY flag?
      └─ No → return FALSE
      └─ Yes → return TRUE
 └─ Yes →
   Does other have the FRIENDLY flag?
    └─ No → return TRUE
    └─ Yes →
        Is the game mode Team deathmatch?
         └─ Yes →
             Are the actors teammates?
              └─ Yes → return FALSE
              └─ No →
                  Do both actors have friendplayers?
                   └─ No → return TRUE
                   └─ Yes →
                       Are those friendplayers teammates?
                        └─ No → return TRUE
                        └─ Yes → return FALSE     
         └─ No →
             Is the game mode any other kind of deathmatch?
              └─ No → return FALSE
              └─ Yes →
                  Do actors have the same friendplayer?
                   └─ Yes → return FALSE
                   └─ No →
                      Does the caller have friendplayer?
                       └─ No → return FALSE
                       └─ Yes →
                           Does other have friendplayer?
                            └─ No → return FALSE
                            └─ Yes →
                               └─ Are those friendplayers teammates?
                                   └─ Yes → return FALSE
                                   └─ No → return TRUE

Examples

Note: This article lists no examples. If you make use of this feature in your own project(s) or know of any basic examples that could be shared, please add them. This will make it easier to understand for future authors seeking assistance. Your contributions are greatly appreciated.


See also