namespace AcDream.Core.Physics;
///
/// Per-entity flags driving the retail-faithful PvP / Player /
/// Impenetrable exemption logic in FindObjCollisions. Decoded
/// from PublicWeenieDesc._bitfield at CreateObject time.
///
///
/// Bit positions (verified against
/// docs/research/named-retail/acclient_2013_pseudo_c.txt:406898-406918
/// where ACCWeenieObject::IsPK/IsPKLite/IsImpenetrable read directly
/// from this->pwd._bitfield):
///
///
/// - BF_PLAYER = 0x8 (bit 3) →
/// - BF_PLAYER_KILLER = 0x20 (bit 5) →
/// - BF_FREE_PKSTATUS = 0x200000 (bit 21) →
/// - BF_PKLITE_PKSTATUS = 0x2000000 (bit 25) →
///
///
///
/// is NOT a PWD bit — retail derives it from
/// PublicWeenieDesc._type matching ITEM_TYPE_CREATURE
/// (acclient.h ITEM_TYPE enum). Set at registration time by callers that
/// already know the item type.
///
///
[Flags]
public enum EntityCollisionFlags : byte
{
None = 0x00,
/// Set when BF_PLAYER (0x8) is set in pwd._bitfield.
IsPlayer = 0x01,
/// Derived from ItemType.Creature on the spawn payload.
IsCreature = 0x02,
/// Set when BF_PLAYER_KILLER (0x20) is set.
IsPK = 0x04,
/// Set when BF_PKLITE_PKSTATUS (0x2000000) is set.
IsPKLite = 0x08,
/// Set when BF_FREE_PKSTATUS (0x200000) is set (a.k.a. "Free" PK status — cannot be PKed).
IsImpenetrable = 0x10,
}
/// Helpers to convert raw retail bitfields into .
public static class EntityCollisionFlagsExt
{
///
/// Decode the player/PK/PKLite/Impenetrable bits from a
/// PublicWeenieDesc._bitfield value (the WeenieHeader trailer
/// field acdream's parser surfaces as ObjectDescriptionFlags).
///
/// Bit positions per
/// docs/research/named-retail/acclient.h:6431-6463
/// (PublicWeenieDesc::BitfieldIndex) and
/// acclient_2013_pseudo_c.txt:441868-441890
/// (PublicWeenieDesc::SetPlayerKillerStatus).
///
public static EntityCollisionFlags FromPwdBitfield(uint bitfield)
{
var flags = EntityCollisionFlags.None;
if ((bitfield & 0x8u) != 0) flags |= EntityCollisionFlags.IsPlayer;
if ((bitfield & 0x20u) != 0) flags |= EntityCollisionFlags.IsPK;
if ((bitfield & 0x200000u) != 0) flags |= EntityCollisionFlags.IsImpenetrable;
if ((bitfield & 0x2000000u) != 0) flags |= EntityCollisionFlags.IsPKLite;
return flags;
}
}