Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 33 additions & 31 deletions Game.Server/AI_BaseNPC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,22 +75,6 @@ public struct AI_SchedLoadStatus

public static class AI_BaseNPCGlobals
{
// TODO: Enum these
// need a good name for its enum type
public const int SF_NPC_WAIT_TILL_SEEN = 1 << 0;
public const int SF_NPC_GAG = 1 << 1;
public const int SF_NPC_FALL_TO_GROUND = 1 << 2;
public const int SF_NPC_DROP_HEALTHKIT = 1 << 3;
public const int SF_NPC_START_EFFICIENT = 1 << 4;
public const int SF_NPC_WAIT_FOR_SCRIPT = 1 << 7;
public const int SF_NPC_LONG_RANGE = 1 << 8;
public const int SF_NPC_FADE_CORPSE = 1 << 9;
public const int SF_NPC_ALWAYSTHINK = 1 << 10;
public const int SF_NPC_TEMPLATE = 1 << 11;
public const int SF_NPC_ALTCOLLISION = 1 << 12;
public const int SF_NPC_NO_WEAPON_DROP = 1 << 13;
public const int SF_NPC_NO_PLAYER_PUSHAWAY = 1 << 14;

public const string PLAYER_SQUADNAME = "player_squad";

public static readonly ConVar ai_show_think_tolerance = new("ai_show_think_tolerance", "0");
Expand Down Expand Up @@ -334,6 +318,24 @@ public bool EnumEntity(IHandleEntity? handleEntity) {
[NetworkName("CAI_BaseNPC")]
public class AI_BaseNPC : BaseCombatCharacter, IAI_MovementSink
{
[Flags]
public enum SF
{
WaitTillSeen = 1 << 0,
Gag = 1 << 1,
FallToGround = 1 << 2,
DropHealthkit = 1 << 3,
StartEfficient = 1 << 4,
WaitForScript = 1 << 7,
LongRange = 1 << 8,
FadeCorpse = 1 << 9,
AlwaysThink = 1 << 10,
Template = 1 << 11,
AltCollision = 1 << 12,
NoWeaponDrop = 1 << 13,
NoPlayerPushaway = 1 << 14,
}

public static ReadOnlySpan<char> GetActivityName(Activity actID) {
if (actID == Activity.ACT_INVALID)
return "ACT_INVALID";
Expand Down Expand Up @@ -2638,7 +2640,7 @@ public static void InitSchedulingTables() {

public NPCState GetIdealState() => IdealNPCState;

public override bool IsTemplate() => HasSpawnFlags(SF_NPC_TEMPLATE);
public override bool IsTemplate() => HasSpawnFlags(SF.Template);

public static bool FindSpotForNPCInRadius(out Vector3 result, in Vector3 startPos, AI_BaseNPC npc, float radius, bool outOfPlayerViewcone = false) {
BasePlayer? player = npc.AI_GetClosestPlayer();
Expand Down Expand Up @@ -2699,7 +2701,7 @@ public bool CineCleanup() {
throw new NotImplementedException();

if (oldCine != null && !string.IsNullOrEmpty(oldCine.Play) && oldCine.PlayedSequence()) {
if (!oldCine.HasSpawnFlags(AI_ScriptedSequence.SF_SCRIPT_DONT_TELEPORT_AT_END)) {
if (!oldCine.HasSpawnFlags(AI_ScriptedSequence.SF.DontTeleportAtEnd)) {
GetBonePosition(0, out Vector3 newOrigin, out _);

Vector3 oldOrigin = GetLocalOrigin();
Expand Down Expand Up @@ -2757,7 +2759,7 @@ public bool CineCleanup() {
SetCondition((int)SCOND_t.COND_LIGHT_DAMAGE);
}

RemoveSpawnFlags(SF_NPC_WAIT_FOR_SCRIPT);
RemoveSpawnFlags(SF.WaitForScript);

if (destroyCine)
Util.Remove(oldCine);
Expand Down Expand Up @@ -3584,7 +3586,7 @@ public void UnlockBestSound() {
public AI_MoveEfficiency GetMoveEfficiency() => MoveEfficiency;
public void SetMoveEfficiency(AI_MoveEfficiency efficiency) => MoveEfficiency = efficiency;

public bool IsFlaggedEfficient() => HasSpawnFlags(SF_NPC_START_EFFICIENT);
public bool IsFlaggedEfficient() => HasSpawnFlags(SF.StartEfficient);

public void RemoveSleepFlags(AI_SleepFlags flags) => SleepFlags &= ~flags;
public bool HasSleepFlags(AI_SleepFlags flags) => (SleepFlags & flags) == flags;
Expand Down Expand Up @@ -5956,7 +5958,7 @@ public virtual bool ShouldPlayerAvoid() {
if (IsInLockedScene() == true)
return true;

if (HasSpawnFlags(SF_NPC_ALTCOLLISION))
if (HasSpawnFlags(SF.AltCollision))
return true;

return false;
Expand Down Expand Up @@ -7168,7 +7170,7 @@ public void CheckOnGround() {

public virtual bool ShouldPlayIdleSound() {
if ((NPCState == NPCState.Idle || NPCState == NPCState.Alert) &&
RandomInt(0, 99) == 0 && !HasSpawnFlags(SF_NPC_GAG)) {
RandomInt(0, 99) == 0 && !HasSpawnFlags(SF.Gag)) {
return true;
}

Expand All @@ -7187,7 +7189,7 @@ public bool FOkToMakeSound(SentencePriority soundPriority = SentencePriority.Nor
}
}

if (HasSpawnFlags(SF_NPC_GAG) && (NPCState != NPCState.Combat))
if (HasSpawnFlags(SF.Gag) && (NPCState != NPCState.Combat))
return false;

return true;
Expand All @@ -7205,7 +7207,7 @@ public virtual void DeathSound(in TakeDamageInfo info) { }
public virtual void LostEnemySound() { }
public virtual void FoundEnemySound() { }

public virtual bool ShouldAlwaysThink() => HasSpawnFlags(SF_NPC_ALWAYSTHINK);
public virtual bool ShouldAlwaysThink() => HasSpawnFlags(SF.AlwaysThink);

static readonly int[] SenseConditionsToClear = [
(int)SCOND_t.COND_SEE_HATE,
Expand Down Expand Up @@ -7522,7 +7524,7 @@ public virtual void NPCInit() {
DistTooFar = 1024.0f;
SetDistLook(2048.0f);

if (HasSpawnFlags(SF_NPC_LONG_RANGE)) {
if (HasSpawnFlags(SF.LongRange)) {
DistTooFar = 1e9f;
SetDistLook(6000.0f);
}
Expand Down Expand Up @@ -7553,15 +7555,15 @@ public virtual void NPCInit() {

ForceGatherConditions();

if (HasSpawnFlags(SF_NPC_WAIT_FOR_SCRIPT)) {
if (HasSpawnFlags(SF.WaitForScript)) {
string? startSequence = AI_ScriptedSequence.GetSpawnPreIdleSequenceForScript(this);
if (startSequence != null)
SetSequence(LookupSequence(startSequence));
}

CreateVPhysics();

if (HasSpawnFlags(SF_NPC_START_EFFICIENT))
if (HasSpawnFlags(SF.StartEfficient))
SetEfficiency(AI_Efficiency.Efficient);

FadeCorpse = ShouldFadeOnDeath();
Expand Down Expand Up @@ -7606,7 +7608,7 @@ public virtual void PostNPCInit() { }
public virtual void StartNPC() {
if ((GetMoveType() != Source.MoveType.Fly) && (GetMoveType() != Source.MoveType.FlyGravity) &&
(CapabilitiesGet() & Server.Capability.MoveFly) == 0 &&
!HasSpawnFlags(SF_NPC_FALL_TO_GROUND) && !IsWaitingToRappel() && GetMoveParent() == null) {
!HasSpawnFlags(SF.FallToGround) && !IsWaitingToRappel() && GetMoveParent() == null) {
Vector3 origin = GetLocalOrigin();

if (!GetMoveProbe()!.FloorPoint(origin + new Vector3(0, 0, 0.1f), Mask.NPCSolid, 0, -2048, out origin)) {
Expand Down Expand Up @@ -7649,7 +7651,7 @@ public virtual void StartNPC() {
ScriptArrivalActivity = AIN_DEF_ACTIVITY;
ScriptArrivalSequence = null;

if (HasSpawnFlags(SF_NPC_WAIT_FOR_SCRIPT)) {
if (HasSpawnFlags(SF.WaitForScript)) {
SetState(NPCState.Idle);
Activity = IdealActivity;
IdealSequence = GetSequence();
Expand Down Expand Up @@ -8172,7 +8174,7 @@ public bool ConditionInterruptsCurSchedule(int condition) {
}

public void TestPlayerPushing(BaseEntity? entity) {
if (HasSpawnFlags(SF_NPC_NO_PLAYER_PUSHAWAY))
if (HasSpawnFlags(SF.NoPlayerPushaway))
return;

BasePlayer? player = ToBasePlayer(entity);
Expand Down Expand Up @@ -8846,7 +8848,7 @@ public void UpdateSleepState(bool inPVS) {
}
}

if ((GetSoundInterests() & (int)SoundInstanceType.Danger) != 0 && !HasSpawnFlags(SF_NPC_WAIT_TILL_SEEN)) {
if ((GetSoundInterests() & (int)SoundInstanceType.Danger) != 0 && !HasSpawnFlags(SF.WaitTillSeen)) {
int sound = SoundEnt.ActiveList();

while (sound != SOUNDLIST_EMPTY) {
Expand Down
12 changes: 8 additions & 4 deletions Game.Server/AI_GoalPolice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ namespace Game.Server;
[LinkEntityToClass("ai_goal_police")]
public class AI_PoliceGoal : BaseEntity
{
public const int SF_POLICE_GOAL_KNOCKOUT_BEHIND = 1 << 1;
public const int SF_POLICE_GOAL_DO_NOT_LEAVE_POST = 1 << 2;
[Flags]
public enum SF
{
KnockoutBehind = 1 << 1,
DoNotLeavePost = 1 << 2,
}

public static readonly new DataMap DataDesc = new(typeof(AI_PoliceGoal), BaseEntity.DataDesc, [
DEFINE.KEYFIELD(nameof(Radius), FieldType.Float, "PoliceRadius"),
Expand Down Expand Up @@ -59,7 +63,7 @@ public bool ShouldKnockOutTarget(in Vector3 targetPos, bool targetVisible) {
if (OverrideKnockOut)
return true;

if (HasSpawnFlags(SF_POLICE_GOAL_KNOCKOUT_BEHIND) == false)
if (HasSpawnFlags(SF.KnockoutBehind) == false)
return false;

if (!targetVisible)
Expand All @@ -78,7 +82,7 @@ public bool ShouldKnockOutTarget(in Vector3 targetPos, bool targetVisible) {

public void KnockOutTarget(BaseEntity? target) => OnKnockOut.FireOutput(target, this);

public bool ShouldRemainAtPost() => HasSpawnFlags(SF_POLICE_GOAL_DO_NOT_LEAVE_POST);
public bool ShouldRemainAtPost() => HasSpawnFlags(SF.DoNotLeavePost);

public void FireWarningLevelOutput(int level) {
switch (level) {
Expand Down
6 changes: 5 additions & 1 deletion Game.Server/AI_Hint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,11 @@ static bool InZone(List<HintZone> zone, in Vector3 testPosition) {
[LinkEntityToClass("ai_hint")]
public class AI_Hint : ServerOnlyEntity
{
public const int SF_ALLOW_JUMP_UP = 65536;
[Flags]
public enum SF
{
AllowJumpUp = 65536,
}

public static readonly new DataMap DataDesc = new(typeof(AI_Hint), BaseEntity.DataDesc, [
DEFINE.EMBEDDED(nameof(NodeData)),
Expand Down
2 changes: 1 addition & 1 deletion Game.Server/AI_Pathfinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ public bool IsLinkUsable(ref AI_Link link, int startID) {
if (startHint != null && endHint != null) {
if (startHint.HintType() == Hint.JumpOverride &&
endHint.HintType() == Hint.JumpOverride &&
(((startHint.SpawnFlags | endHint.SpawnFlags) & AI_Hint.SF_ALLOW_JUMP_UP) != 0 || startHint.GetAbsOrigin().Z > endHint.GetAbsOrigin().Z)) {
(startHint.HasSpawnFlags(AI_Hint.SF.AllowJumpUp) || endHint.HasSpawnFlags(AI_Hint.SF.AllowJumpUp) ||startHint.GetAbsOrigin().Z > endHint.GetAbsOrigin().Z)) {
if (!startNode.IsLocked()) {
if (startHint.GetTargetNode() == -1 || startHint.GetTargetNode() == endID)
moveType = Capability.MoveJump;
Expand Down
8 changes: 6 additions & 2 deletions Game.Server/AI_ScriptConditions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ public class AI_ScriptConditionsElement
[LinkEntityToClass("ai_script_conditions")]
public class AI_ScriptConditions : BaseEntity, IEntityListener
{
const int SF_ACTOR_AS_ACTIVATOR = 1 << 0;
[Flags]
public enum SF
{
ActorAsActivator = 1 << 0,
}

static readonly ConVar debugscriptconditions = new("ai_debugscriptconditions", "0");

Expand Down Expand Up @@ -419,7 +423,7 @@ void EvaluationThink() {
BaseEntity activator = this;

#if HL2_EPISODIC
if (actor != null && HasSpawnFlags(SF_ACTOR_AS_ACTIVATOR))
if (actor != null && HasSpawnFlags(SF.ActorAsActivator))
activator = actor;
#endif

Expand Down
8 changes: 4 additions & 4 deletions Game.Server/AI_Senses.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void Listen() {

int soundMask = GetOuter()!.GetSoundInterests();

if (soundMask != (int)SoundInstanceType.None && !GetOuter()!.HasSpawnFlags(SF_NPC_WAIT_TILL_SEEN)) {
if (soundMask != (int)SoundInstanceType.None && !GetOuter()!.HasSpawnFlags(AI_BaseNPC.SF.WaitTillSeen)) {
int iSound = SoundEnt.ActiveList();

while (iSound != SOUNDLIST_EMPTY) {
Expand Down Expand Up @@ -115,7 +115,7 @@ public bool ShouldSeeEntity(BaseEntity sightEnt) {
if (sightEnt.IsPlayer() && g_IgnorePlayers.GetBool())
return false;

if ((sightEnt.SpawnFlags & SF_NPC_WAIT_TILL_SEEN) != 0)
if (sightEnt.HasSpawnFlags(AI_BaseNPC.SF.WaitTillSeen))
return false;

if (!sightEnt.CanBeSeenBy(GetOuter()!))
Expand Down Expand Up @@ -151,13 +151,13 @@ void NoteSeenEntity(BaseEntity sightEnt) {
}

bool WaitingUntilSeen(BaseEntity sightEnt) {
if ((GetOuter()!.SpawnFlags & SF_NPC_WAIT_TILL_SEEN) != 0) {
if (GetOuter()!.HasSpawnFlags(AI_BaseNPC.SF.WaitTillSeen)) {
if (sightEnt.IsPlayer()) {
BasePlayer? player = ToBasePlayer(sightEnt);
if (player != null
&& player.FInViewCone(GetOuter()!)
&& FBoxVisible(sightEnt, GetOuter()!, out _)) {
GetOuter()!.SpawnFlags &= ~SF_NPC_WAIT_TILL_SEEN;
GetOuter()!.RemoveSpawnFlags(AI_BaseNPC.SF.WaitTillSeen);
return false;
}
}
Expand Down
6 changes: 3 additions & 3 deletions Game.Server/AI_Sentence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ bool MatchesCriteria(SentenceCriteria criteria) {
return true;

case SentenceCriteria.Normal:
return (GetOuter()!.GetState() == NPCState.Combat) || (GetOuter()!.HasSpawnFlags(SF_NPC_GAG) == false);
return (GetOuter()!.GetState() == NPCState.Combat) || (GetOuter()!.HasSpawnFlags(AI_BaseNPC.SF.Gag) == false);

case SentenceCriteria.InSquad:
if ((GetOuter()!.GetState() != NPCState.Combat) && GetOuter()!.HasSpawnFlags(SF_NPC_GAG))
if ((GetOuter()!.GetState() != NPCState.Combat) && GetOuter()!.HasSpawnFlags(AI_BaseNPC.SF.Gag))
return false;
return GetOuter()!.GetSquad() != null && (GetOuter()!.GetSquad()!.NumMembers() > 1);

case SentenceCriteria.SquadLeader: {
if ((GetOuter()!.GetState() != NPCState.Combat) && GetOuter()!.HasSpawnFlags(SF_NPC_GAG))
if ((GetOuter()!.GetState() != NPCState.Combat) && GetOuter()!.HasSpawnFlags(AI_BaseNPC.SF.Gag))
return false;

AI_Squad? squad = GetOuter()!.GetSquad();
Expand Down
4 changes: 2 additions & 2 deletions Game.Server/BaseCombatCharacter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ public bool Weapon_IsOnGround(BaseCombatWeapon weapon) {

float curDist = (weapon.GetLocalOrigin() - GetLocalOrigin()).Length();

if (weapon.HasSpawnFlags(BaseCombatWeapon.SF_WEAPON_NO_PLAYER_PICKUP))
if (weapon.HasSpawnFlags(BaseCombatWeapon.SF.NoPlayerPickup))
curDist *= 0.5f;

if (bestWeapon != null) {
Expand Down Expand Up @@ -584,7 +584,7 @@ public virtual void Weapon_Equip(BaseCombatWeapon weapon) {
}

if (IsPlayer() == false) {
if (HasSpawnFlags(AI_BaseNPCGlobals.SF_NPC_LONG_RANGE)) {
if (HasSpawnFlags(AI_BaseNPC.SF.LongRange)) {
ActiveWeapon.Get()!.MaxRange1 = 999999999;
ActiveWeapon.Get()!.MaxRange2 = 999999999;
}
Expand Down
4 changes: 2 additions & 2 deletions Game.Server/BaseCombatWeapon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static int GetAvailableWeaponsInBox(Span<BaseCombatWeapon?> list, in Vect

public override EntityCapabilities ObjectCaps() {
EntityCapabilities caps = base.ObjectCaps();
if (!IsFollowingEntity() && !HasSpawnFlags(SF_WEAPON_NO_PLAYER_PICKUP))
if (!IsFollowingEntity() && !HasSpawnFlags(BaseCombatWeapon.SF.NoPlayerPickup))
caps |= EntityCapabilities.ImpulseUse;

return caps;
Expand Down Expand Up @@ -234,7 +234,7 @@ public void Materialize() {
DoMuzzleFlash();
}

if (HasSpawnFlags(BasePlayer.SF_NORESPAWN) == false) {
if (HasSpawnFlags(BasePlayer.SF.NoRespawn) == false) {
VPhysicsInitNormal(SolidType.BBox, GetSolidFlags() | SolidFlags.Trigger, false);
SetMoveType(Source.MoveType.VPhysics);
}
Expand Down
10 changes: 9 additions & 1 deletion Game.Server/BaseEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,7 @@ private ref QAngle UseStepSimulationNetworkAngles(out bool ok) {
if (Physics.g_bTestMoveTypeStepSimulation && GetMoveType() == Source.MoveType.Step && HasDataObjectType(DataObjectType.StepSimulation)) {
ref StepSimulationData step = ref GetDataObject<StepSimulationData>(DataObjectType.StepSimulation);
ComputeStepSimulationNetwork(ref step);

ok = step.AnglesActive;
return ref step.NetworkAngles;
}
Expand Down Expand Up @@ -2719,6 +2719,8 @@ public static void PrecacheModelComponents(int modelIndex) {

public bool HasSpawnFlags(int flags) => (SpawnFlags & flags) != 0;

public bool HasSpawnFlags<T>(T flags) where T : unmanaged, Enum => HasSpawnFlags(Unsafe.As<T, int>(ref flags));

public int GetModelIndex() => ModelIndex;

/// <summary>
Expand Down Expand Up @@ -3117,7 +3119,13 @@ public virtual Vector3 GetSmoothedVelocity() {
public virtual void PostClientActive() { }

public void AddSpawnFlags(int flags) => SpawnFlags |= flags;

public void AddSpawnFlags<T>(T flags) where T : unmanaged, Enum => AddSpawnFlags(Unsafe.As<T, int>(ref flags));

public void RemoveSpawnFlags(int flags) => SpawnFlags &= ~flags;

public void RemoveSpawnFlags<T>(T flags) where T : unmanaged, Enum => RemoveSpawnFlags(Unsafe.As<T, int>(ref flags));

public void SetFriction(float friction) => Friction = friction;

public TimeUnit_t GetNextThink(ReadOnlySpan<char> context = default) {
Expand Down
Loading
Loading