From 1c2859a59dc84e94fdabc9210dc2c75a14a357f5 Mon Sep 17 00:00:00 2001 From: Walter Julius Hennecke Date: Wed, 29 Apr 2015 22:34:44 +0200 Subject: [PATCH] Various actor related updates --- dlls/game/RageAI.cpp | 4 +- dlls/game/actor.cpp | 378 ++--- dlls/game/actor_combatsubsystem.cpp | 6 +- dlls/game/actor_enemymanager.cpp | 10 +- dlls/game/actor_headwatcher.cpp | 510 ++++--- dlls/game/actor_headwatcher.h | 120 +- dlls/game/actor_locomotion.cpp | 1890 ++++++++++++------------- dlls/game/actor_locomotion.h | 348 ++--- dlls/game/actor_posturecontroller.cpp | 22 +- dlls/game/actor_posturecontroller.hpp | 63 +- dlls/game/actor_sensoryperception.cpp | 248 ++-- dlls/game/actor_sensoryperception.h | 161 ++- dlls/game/actorgamecomponents.cpp | 6 +- dlls/game/actorgamecomponents.h | 54 +- dlls/game/actorincludes.h | 557 ++++---- dlls/game/actorstrategies.cpp | 4 +- dlls/game/behavior.cpp | 122 +- dlls/game/behaviors_general.cpp | 28 +- dlls/game/player.cpp | 8 +- dlls/game/sentient.cpp | 6 +- dlls/game/snipeEnemy.cpp | 12 +- dlls/game/talk.cpp | 6 +- dlls/game/torsoAimAndFireWeapon.cpp | 14 +- 23 files changed, 2203 insertions(+), 2374 deletions(-) diff --git a/dlls/game/RageAI.cpp b/dlls/game/RageAI.cpp index 15e353b..edb8ec5 100644 --- a/dlls/game/RageAI.cpp +++ b/dlls/game/RageAI.cpp @@ -310,8 +310,8 @@ void DefaultStrategos::_CheckForInTheWay() if ( (relativeYaw <= _checkYawMax) && (relativeYaw >= _checkYawMin ) ) { - act->AddStateFlag( STATE_FLAG_TOUCHED_BY_PLAYER ); - act->AddStateFlag( STATE_FLAG_IN_THE_WAY ); + act->AddStateFlag( StateFlagTouchedByPlayer ); + act->AddStateFlag( StateFlagInTheWay ); } } diff --git a/dlls/game/actor.cpp b/dlls/game/actor.cpp index 398eb82..593dcfd 100644 --- a/dlls/game/actor.cpp +++ b/dlls/game/actor.cpp @@ -3024,12 +3024,12 @@ void Actor::Init() // General Data takedamage = DamageAim; deadflag = DeadNo; - mode = ACTOR_MODE_AI; //ACTOR_MODE_IDLE; + mode = ActorModeAi; //ActorModeIdle; max_inactive_time = MAX_INACTIVE_TIME; newanimevent = nullptr; newTorsoAnimEvent = nullptr; groundentity = nullptr; - saved_mode = ACTOR_MODE_NONE; + saved_mode = ActorModeNone; showStates = DEBUG_NONE; talkMode = TALK_TURNTO; @@ -3671,16 +3671,16 @@ turnTowardsEntity( ent, extraYaw ); */ TurnTo* turnTo; - if (!ModeAllowed(ACTOR_MODE_SCRIPT)) + if (!ModeAllowed(ActorModeScript)) { - if (mode == ACTOR_MODE_TALK) + if (mode == ActorModeTalk) RepostEvent(ev, EV_Actor_TurnTo); - else if (mode == ACTOR_MODE_AI) + else if (mode == ActorModeAi) SendMoveDone(ev->GetThread()); return; } - StartMode(ACTOR_MODE_SCRIPT); + StartMode(ActorModeScript); turnTo = new TurnTo; turnTo->SetTarget(ev->GetEntity(1)); @@ -3697,9 +3697,9 @@ void Actor::GoIdle(Event* ev) { const char* state_name; - if (!ModeAllowed(ACTOR_MODE_IDLE)) + if (!ModeAllowed(ActorModeIdle)) { - if (mode == ACTOR_MODE_TALK) + if (mode == ActorModeTalk) RepostEvent(ev, EV_Actor_Idle); return; } @@ -3711,7 +3711,7 @@ void Actor::GoIdle(Event* ev) SetState(state_name); - StartMode(ACTOR_MODE_IDLE); + StartMode(ActorModeIdle); } @@ -3731,16 +3731,16 @@ void Actor::LookAt(Event* ev) Entity* ent; TurnTo* turnTo; - if (!ModeAllowed(ACTOR_MODE_SCRIPT)) + if (!ModeAllowed(ActorModeScript)) { - if (mode == ACTOR_MODE_TALK) + if (mode == ActorModeTalk) RepostEvent(ev, EV_Actor_LookAt); - else if (mode == ACTOR_MODE_AI) + else if (mode == ActorModeAi) SendMoveDone(ev->GetThread()); return; } - StartMode(ACTOR_MODE_SCRIPT); + StartMode(ActorModeScript); ent = ev->GetEntity(1); if (ent && ent != world) @@ -3761,16 +3761,16 @@ void Actor::TurnToEvent(Event* ev) { TurnTo* turnTo; - if (!ModeAllowed(ACTOR_MODE_SCRIPT)) + if (!ModeAllowed(ActorModeScript)) { - if (mode == ACTOR_MODE_TALK) + if (mode == ActorModeTalk) RepostEvent(ev, EV_Actor_TurnTo); - else if (mode == ACTOR_MODE_AI) + else if (mode == ActorModeAi) SendMoveDone(ev->GetThread()); return; } - StartMode(ACTOR_MODE_SCRIPT); + StartMode(ActorModeScript); turnTo = new TurnTo; turnTo->SetDirection(ev->GetFloat(1)); @@ -3792,16 +3792,16 @@ void Actor::HeadAndEyeWatchEvent(Event* ev) { Event* event; - if (!ModeAllowed(ACTOR_MODE_SCRIPT)) + if (!ModeAllowed(ActorModeScript)) { - if (mode == ACTOR_MODE_TALK) + if (mode == ActorModeTalk) RepostEvent(ev, EV_Actor_HeadWatch); - else if (mode == ACTOR_MODE_AI) + else if (mode == ActorModeAi) SendMoveDone(ev->GetThread()); return; } - StartMode(ACTOR_MODE_SCRIPT); + StartMode(ActorModeScript); event = new Event(EV_Behavior_Args); event->AddEntity(ev->GetEntity(1)); @@ -3823,16 +3823,16 @@ void Actor::HeadWatchEvent(Event* ev) { //Event *event; - if (!ModeAllowed(ACTOR_MODE_SCRIPT)) + if (!ModeAllowed(ActorModeScript)) { - if (mode == ACTOR_MODE_TALK) + if (mode == ActorModeTalk) RepostEvent(ev, EV_Actor_HeadWatch); - else if (mode == ACTOR_MODE_AI) + else if (mode == ActorModeAi) SendMoveDone(ev->GetThread()); return; } - StartMode(ACTOR_MODE_SCRIPT); + StartMode(ActorModeScript); /*event = new Event( EV_Behavior_Args ); event->AddEntity( ev->GetEntity( 1 ) ); @@ -3864,16 +3864,16 @@ void Actor::ResetHeadEvent(Event* ev) { //Event *event; - if (!ModeAllowed(ACTOR_MODE_SCRIPT)) + if (!ModeAllowed(ActorModeScript)) { - if (mode == ACTOR_MODE_TALK) + if (mode == ActorModeTalk) RepostEvent(ev, EV_Actor_ResetHead); - else if (mode == ACTOR_MODE_AI) + else if (mode == ActorModeAi) SendMoveDone(ev->GetThread()); return; } - StartMode(ACTOR_MODE_SCRIPT); + StartMode(ActorModeScript); /* event = new Event( EV_Behavior_Args ); @@ -3898,16 +3898,16 @@ void Actor::EyeWatchEvent(Event* ev) { Event* event; - if (!ModeAllowed(ACTOR_MODE_SCRIPT)) + if (!ModeAllowed(ActorModeScript)) { - if (mode == ACTOR_MODE_TALK) + if (mode == ActorModeTalk) RepostEvent(ev, EV_Actor_EyeWatch); - else if (mode == ACTOR_MODE_AI) + else if (mode == ActorModeAi) SendMoveDone(ev->GetThread()); return; } - StartMode(ACTOR_MODE_SCRIPT); + StartMode(ActorModeScript); event = new Event(EV_Behavior_Args); event->AddEntity(ev->GetEntity(1)); @@ -3928,16 +3928,16 @@ void Actor::ResetEyeEvent(Event* ev) { Event* event; - if (!ModeAllowed(ACTOR_MODE_SCRIPT)) + if (!ModeAllowed(ActorModeScript)) { - if (mode == ACTOR_MODE_TALK) + if (mode == ActorModeTalk) RepostEvent(ev, EV_Actor_ResetEye); - else if (mode == ACTOR_MODE_AI) + else if (mode == ActorModeAi) SendMoveDone(ev->GetThread()); return; } - StartMode(ACTOR_MODE_SCRIPT); + StartMode(ActorModeScript); event = new Event(EV_Behavior_Args); event->AddEntity(nullptr); @@ -3959,11 +3959,11 @@ void Actor::ResetTorsoEvent(Event*) /* Event *event; -if ( !ModeAllowed( ACTOR_MODE_SCRIPT ) ) +if ( !ModeAllowed( ActorModeScript ) ) { -if ( mode == ACTOR_MODE_TALK ) +if ( mode == ActorModeTalk ) RepostEvent( ev, EV_Actor_ResetTorso ); -else if ( mode == ACTOR_MODE_AI ) +else if ( mode == ActorModeAi ) SendMoveDone( ev->GetThread() ); return; } @@ -3978,8 +3978,8 @@ event->AddInteger( 0 ); SetEyeBehavior( new TorsoTurn, event, ev->GetThread() ); */ - SetControllerTag(ACTOR_TORSO_TAG, gi.Tag_NumForName(edict->s.modelindex, "Bip01 Spine1")); - SetControllerAngles(ACTOR_TORSO_TAG, vec_zero); + SetControllerTag(ActorTorsoTag, gi.Tag_NumForName(edict->s.modelindex, "Bip01 Spine1")); + SetControllerAngles(ActorTorsoTag, vec_zero); } @@ -3994,16 +3994,16 @@ void Actor::FallToDeathEvent(Event* ev) { Event* e; - if (!ModeAllowed(ACTOR_MODE_SCRIPT)) + if (!ModeAllowed(ActorModeScript)) { - if (mode == ACTOR_MODE_TALK) + if (mode == ActorModeTalk) RepostEvent(ev, EV_Actor_FallToDeath); - else if (mode == ACTOR_MODE_AI) + else if (mode == ActorModeAi) SendMoveDone(ev->GetThread()); return; } - StartMode(ACTOR_MODE_SCRIPT); + StartMode(ActorModeScript); e = new Event(EV_Behavior_Args); @@ -4037,16 +4037,16 @@ void Actor::WalkTo(Event* ev) Event* e; //HelperNode *node; - if (!ModeAllowed(ACTOR_MODE_SCRIPT)) + if (!ModeAllowed(ActorModeScript)) { - if (mode == ACTOR_MODE_TALK) + if (mode == ActorModeTalk) RepostEvent(ev, EV_Actor_WalkTo); - else if (mode == ACTOR_MODE_AI) + else if (mode == ActorModeAi) SendMoveDone(ev->GetThread()); return; } - StartMode(ACTOR_MODE_SCRIPT); + StartMode(ActorModeScript); e = new Event(EV_Behavior_Args); @@ -4096,19 +4096,19 @@ void Actor::WalkTo(Event* ev) // void Actor::BlindlyFollowPath(Event* ev) { - if (!ModeAllowed(ACTOR_MODE_SCRIPT)) + if (!ModeAllowed(ActorModeScript)) { - if (mode == ACTOR_MODE_TALK) + if (mode == ActorModeTalk) { RepostEvent(ev, EV_Actor_BlindlyFollowPath); - } else if (mode == ACTOR_MODE_AI) + } else if (mode == ActorModeAi) { SendMoveDone(ev->GetThread()); } return; } - StartMode(ACTOR_MODE_SCRIPT); + StartMode(ActorModeScript); auto e = new Event(EV_Behavior_Args); @@ -4152,16 +4152,16 @@ void Actor::FollowWayPoints(Event* ev) Event* e; - if (!ModeAllowed(ACTOR_MODE_SCRIPT)) + if (!ModeAllowed(ActorModeScript)) { - if (mode == ACTOR_MODE_TALK) + if (mode == ActorModeTalk) RepostEvent(ev, EV_Actor_WalkTo); - else if (mode == ACTOR_MODE_AI) + else if (mode == ActorModeAi) SendMoveDone(ev->GetThread()); return; } - StartMode(ACTOR_MODE_SCRIPT); + StartMode(ActorModeScript); e = new Event(EV_Behavior_Args); @@ -4204,16 +4204,16 @@ void Actor::WalkWatch(Event* ev) if (ev->NumArgs() < 2) return; - if (!ModeAllowed(ACTOR_MODE_SCRIPT)) + if (!ModeAllowed(ActorModeScript)) { - if (mode == ACTOR_MODE_TALK) + if (mode == ActorModeTalk) RepostEvent(ev, EV_Actor_WalkWatch); - else if (mode == ACTOR_MODE_AI) + else if (mode == ActorModeAi) SendMoveDone(ev->GetThread()); return; } - StartMode(ACTOR_MODE_SCRIPT); + StartMode(ActorModeScript); e = new Event(EV_Behavior_Args); @@ -4252,9 +4252,9 @@ void Actor::WarpTo(Event* ev) { PathNode* goal_node; - if (!ModeAllowed(ACTOR_MODE_SCRIPT)) + if (!ModeAllowed(ActorModeScript)) { - if (mode == ACTOR_MODE_TALK) + if (mode == ActorModeTalk) RepostEvent(ev, EV_Actor_WarpTo); return; } @@ -4289,16 +4289,16 @@ void Actor::PickupEnt(Event* ev) { Event* e; - if (!ModeAllowed(ACTOR_MODE_SCRIPT)) + if (!ModeAllowed(ActorModeScript)) { - if (mode == ACTOR_MODE_TALK) + if (mode == ActorModeTalk) RepostEvent(ev, EV_Actor_PickupEnt); - else if (mode == ACTOR_MODE_AI) + else if (mode == ActorModeAi) SendMoveDone(ev->GetThread()); return; } - StartMode(ACTOR_MODE_SCRIPT); + StartMode(ActorModeScript); e = new Event(EV_Behavior_Args); @@ -4326,16 +4326,16 @@ void Actor::ThrowEnt(Event* ev) { Event* e; - if (!ModeAllowed(ACTOR_MODE_SCRIPT)) + if (!ModeAllowed(ActorModeScript)) { - if (mode == ACTOR_MODE_TALK) + if (mode == ActorModeTalk) RepostEvent(ev, EV_Actor_ThrowEnt); - else if (mode == ACTOR_MODE_AI) + else if (mode == ActorModeAi) SendMoveDone(ev->GetThread()); return; } - StartMode(ACTOR_MODE_SCRIPT); + StartMode(ActorModeScript); e = new Event(EV_Behavior_Args); @@ -4383,7 +4383,7 @@ void Actor::AttackEntity(Event* ev) return; } - sensoryPerception->Stimuli(STIMULI_SIGHT, target); + sensoryPerception->Stimuli(StimuliSight, target); if (enemyManager->IsInHateList(target)) { @@ -4433,16 +4433,16 @@ void Actor::JumpToEvent(Event* ev) int i; int n; - if (!ModeAllowed(ACTOR_MODE_SCRIPT)) + if (!ModeAllowed(ActorModeScript)) { - if (mode == ACTOR_MODE_TALK) + if (mode == ActorModeTalk) PostEvent(*ev, FRAMETIME); - else if (mode == ACTOR_MODE_AI) + else if (mode == ActorModeAi) SendMoveDone(ev->GetThread()); return; } - StartMode(ACTOR_MODE_SCRIPT); + StartMode(ActorModeScript); e = new Event(EV_Behavior_Args); @@ -5076,7 +5076,7 @@ void Actor::ProcessActorStateMachine(void) if (deadflag || !currentState) return; - if (mode != ACTOR_MODE_AI && mode != ACTOR_MODE_IDLE) + if (mode != ActorModeAi && mode != ActorModeIdle) return; do @@ -5328,7 +5328,7 @@ void Actor::ProcessMasterStateMachine(void) if (deadflag || !currentMasterState) return; - if (mode != ACTOR_MODE_AI && mode != ACTOR_MODE_IDLE) + if (mode != ActorModeAi && mode != ActorModeIdle) return; auto count = 0; @@ -6325,11 +6325,11 @@ void Actor::SetAnim(Event* ev) void Actor::Anim(Event* ev) { - if (!ModeAllowed(ACTOR_MODE_SCRIPT)) + if (!ModeAllowed(ActorModeScript)) { - if (mode == ACTOR_MODE_TALK) + if (mode == ActorModeTalk) PostEvent(*ev, FRAMETIME); - else if (mode == ACTOR_MODE_AI) + else if (mode == ActorModeAi) SendMoveDone(ev->GetThread()); return; } @@ -6345,7 +6345,7 @@ void Actor::Anim(Event* ev) if (ev->GetSource() == EV_FROM_SCRIPT) { - StartMode(ACTOR_MODE_SCRIPT); + StartMode(ActorModeScript); e->SetThread(ev->GetThread()); e->SetLineNumber(ev->GetLineNumber()); @@ -6498,7 +6498,7 @@ void Actor::HeardSound(Event* ev) } - sensoryPerception->Stimuli(STIMULI_SOUND, ev->GetVector(2), soundType); + sensoryPerception->Stimuli(StimuliSound, ev->GetVector(2), soundType); if (GetActorFlag(ACTOR_FLAG_NOISE_HEARD)) { enemyManager->TryToAddToHateList(theEntity); @@ -6593,7 +6593,7 @@ void Actor::Pain(Event* ev) // Determine which pain flags to set - AddStateFlag(STATE_FLAG_SMALL_PAIN); + AddStateFlag(StateFlagSmallPain); if (damage < pain_threshold) { @@ -6601,15 +6601,15 @@ void Actor::Pain(Event* ev) { if (means_of_death == MOD_SWORD || means_of_death == MOD_AXE || means_of_death == MOD_FIRESWORD || means_of_death == MOD_ELECTRICSWORD) - pain_type = PAIN_BIG; + pain_type = PainBig; else - pain_type = PAIN_SMALL; - AddStateFlag(STATE_FLAG_IN_PAIN); + pain_type = PainSmall; + AddStateFlag(StateFlagInPain); } } else { - pain_type = PAIN_BIG; - AddStateFlag(STATE_FLAG_IN_PAIN); + pain_type = PainBig; + AddStateFlag(StateFlagInPain); } //------------------------------------------------------------------- @@ -6652,7 +6652,7 @@ void Actor::Pain(Event* ev) { next_pain_time = level.time + min_pain_time; next_forced_pain_time = level.time + max_pain_time; - AddStateFlag(STATE_FLAG_SHOW_PAIN); + AddStateFlag(StateFlagShowPain); } @@ -6906,20 +6906,20 @@ void Actor::Killed(Event* ev) // Make sure all bones are put back in their normal positions - if (edict->s.bone_tag[ACTOR_MOUTH_TAG] != -1) - SetControllerAngles(ACTOR_MOUTH_TAG, vec_zero); + if (edict->s.bone_tag[ActorMouthTag] != -1) + SetControllerAngles(ActorMouthTag, vec_zero); - if (edict->s.bone_tag[ACTOR_HEAD_TAG] != -1) - SetControllerAngles(ACTOR_HEAD_TAG, vec_zero); + if (edict->s.bone_tag[ActorHeadTag] != -1) + SetControllerAngles(ActorHeadTag, vec_zero); - if (edict->s.bone_tag[ACTOR_TORSO_TAG] != -1) - SetControllerAngles(ACTOR_TORSO_TAG, vec_zero); + if (edict->s.bone_tag[ActorTorsoTag] != -1) + SetControllerAngles(ActorTorsoTag, vec_zero); - if (edict->s.bone_tag[ACTOR_LEYE_TAG] != -1) - SetControllerAngles(ACTOR_LEYE_TAG, vec_zero); + if (edict->s.bone_tag[ActorLeyeTag] != -1) + SetControllerAngles(ActorLeyeTag, vec_zero); - if (edict->s.bone_tag[ACTOR_REYE_TAG] != -1) - SetControllerAngles(ACTOR_REYE_TAG, vec_zero); + if (edict->s.bone_tag[ActorReyeTag] != -1) + SetControllerAngles(ActorReyeTag, vec_zero); ClassDef* cls; @@ -7793,13 +7793,13 @@ void Actor::ShowInfo(void) else gi.Printf("Think is OFF\n"); - if (mode == ACTOR_MODE_IDLE) + if (mode == ActorModeIdle) gi.Printf("Mode : IDLE\n"); - else if (mode == ACTOR_MODE_AI) + else if (mode == ActorModeAi) gi.Printf("Mode : AI\n"); - else if (mode == ACTOR_MODE_SCRIPT) + else if (mode == ActorModeScript) gi.Printf("Mode : SCRIPT\n"); - else if (mode == ACTOR_MODE_TALK) + else if (mode == ActorModeTalk) gi.Printf("Mode : TALK\n"); gi.Printf("\n"); @@ -7893,10 +7893,10 @@ void Actor::TurnAIOn(void) SetActorFlag(ACTOR_FLAG_AI_ON, true); if (sensoryPerception) - sensoryPerception->RespondTo(STIMULI_ALL, true); + sensoryPerception->RespondTo(StimuliAll, true); EndMode(); - mode = ACTOR_MODE_AI; + mode = ActorModeAi; Wakeup(); } @@ -7909,9 +7909,9 @@ void Actor::TurnAIOff(void) { SetActorFlag(ACTOR_FLAG_AI_ON, false); if (sensoryPerception) - sensoryPerception->RespondTo(STIMULI_NONE, true); + sensoryPerception->RespondTo(StimuliNone, true); - if (mode == ACTOR_MODE_AI) + if (mode == ActorModeAi) { // Ai is currently on, get out of AI mode //gi.WDPrintf( "Forcing an actor (#%d, %s) out of AI mode, this can be dangerous.\n", entnum, name.c_str() ); @@ -7929,16 +7929,16 @@ void Actor::ActivateAI(void) last_time_active = level.time; - if (mode == ACTOR_MODE_AI || mode == ACTOR_MODE_TALK) + if (mode == ActorModeAi || mode == ActorModeTalk) return; - StartMode(ACTOR_MODE_AI); + StartMode(ActorModeAi); if (fuzzyEngine) SetState("START"); if (sensoryPerception) - sensoryPerception->RespondTo(STIMULI_ALL, true); + sensoryPerception->RespondTo(StimuliAll, true); if (activate_thread.length()) RunThread(activate_thread); @@ -7996,7 +7996,7 @@ Player* GetPlayer(int index) // Temporary qboolean Actor::checkInAIMode(Conditional&) { - return mode == ACTOR_MODE_AI; + return mode == ActorModeAi; } @@ -8370,12 +8370,12 @@ qboolean Actor::checkcanflytoenemy(Conditional&) qboolean Actor::checkinpain(Conditional&) { - return state_flags & STATE_FLAG_IN_PAIN; + return state_flags & StateFlagInPain; } qboolean Actor::checksmallpain(Conditional&) { - return state_flags & STATE_FLAG_SMALL_PAIN; + return state_flags & StateFlagSmallPain; } qboolean Actor::checkpainyaw(Conditional& condition) @@ -8408,12 +8408,12 @@ qboolean Actor::checkfinished(Conditional&) qboolean Actor::checkmeleehit(Conditional&) { - return state_flags & STATE_FLAG_MELEE_HIT; + return state_flags & StateFlagMeleeHit; } qboolean Actor::checkblockedhit(Conditional&) { - return state_flags & STATE_FLAG_BLOCKED_HIT; + return state_flags & StateFlagBlockedHit; } qboolean Actor::checkblocked(Conditional&) @@ -8434,17 +8434,17 @@ qboolean Actor::checkonfire(Conditional&) qboolean Actor::checkotherdied(Conditional&) { - return state_flags & STATE_FLAG_OTHER_DIED; + return state_flags & StateFlagOtherDied; } qboolean Actor::checkstuck(Conditional&) { - return state_flags & STATE_FLAG_STUCK; + return state_flags & StateFlagStuck; } qboolean Actor::checknopath(Conditional&) { - return state_flags & STATE_FLAG_NO_PATH; + return state_flags & StateFlagNoPath; } qboolean Actor::checkbehaviordone(Conditional&) @@ -8804,25 +8804,25 @@ qboolean Actor::checkpartflag(Conditional& condition) if (stricmp(flag_name, "pain") == 0) { - flag = STATE_FLAG_IN_PAIN; + flag = StateFlagInPain; } else if (stricmp(flag_name, "small_pain") == 0) { - flag = STATE_FLAG_SMALL_PAIN; + flag = StateFlagSmallPain; } else if (stricmp(flag_name, "melee_hit") == 0) { - flag = STATE_FLAG_MELEE_HIT; + flag = StateFlagMeleeHit; } else if (stricmp(flag_name, "touched") == 0) { - flag = STATE_FLAG_TOUCHED; + flag = StateFlagTouched; } else if (stricmp(flag_name, "activated") == 0) { - flag = STATE_FLAG_ACTIVATED; + flag = StateFlagActivated; } else if (stricmp(flag_name, "used") == 0) { - flag = STATE_FLAG_USED; + flag = StateFlagUsed; } else if (stricmp(flag_name, "twitch") == 0) { - flag = STATE_FLAG_TWITCH; + flag = StateFlagTwitch; } else { gi.WDPrintf("Unknown flag name (%s) in checkpartflag.", flag_name.c_str()); @@ -8870,7 +8870,7 @@ qboolean Actor::checkcommand(Conditional& condition) qboolean Actor::checktouched(Conditional&) { - return state_flags & STATE_FLAG_TOUCHED; + return state_flags & StateFlagTouched; } qboolean Actor::checktouchedbyplayer(Conditional&) @@ -8880,7 +8880,7 @@ qboolean Actor::checktouchedbyplayer(Conditional&) qboolean Actor::checktouchedbyplayer() { - return state_flags & STATE_FLAG_TOUCHED_BY_PLAYER; + return state_flags & StateFlagTouchedByPlayer; } qboolean Actor::checkInTheWay(Conditional&) @@ -8890,10 +8890,10 @@ qboolean Actor::checkInTheWay(Conditional&) qboolean Actor::checkInTheWay() { - if (state_flags & STATE_FLAG_IN_THE_WAY) + if (state_flags & StateFlagInTheWay) return true; - if (state_flags & STATE_FLAG_TOUCHED_BY_PLAYER) + if (state_flags & StateFlagTouchedByPlayer) return true; return false; @@ -8901,17 +8901,17 @@ qboolean Actor::checkInTheWay() qboolean Actor::checkactivated(Conditional&) { - return state_flags & STATE_FLAG_ACTIVATED; + return state_flags & StateFlagActivated; } qboolean Actor::checkused(Conditional&) { - return state_flags & STATE_FLAG_USED; + return state_flags & StateFlagUsed; } qboolean Actor::checktwitch(Conditional&) { - return state_flags & STATE_FLAG_TWITCH; + return state_flags & StateFlagTwitch; } qboolean Actor::checkhealth(Conditional& condition) @@ -10188,7 +10188,7 @@ void Actor::PlayDialog(Sentient* user, float volume, float min_dist, const char* if (state_name != nullptr && currentState) { - if (mode == ACTOR_MODE_SCRIPT || mode == ACTOR_MODE_IDLE) + if (mode == ActorModeScript || mode == ActorModeIdle) { dialog_old_state_name = currentState->getName(); dialog_state_name = state_name; @@ -10244,7 +10244,7 @@ void Actor::PlayDialog(Sentient* user, float volume, float min_dist, const char* } else if (strnicmp(morph_target_name, "anm_", 4) == 0) { // Make sure we don't screw things up if we're in TALK_MODE - if (mode != ACTOR_MODE_TALK) + if (mode != ActorModeTalk) { // Change the animation new_event = new Event(EV_Actor_Anim); @@ -10613,7 +10613,7 @@ void Actor::DialogDone(Event*) { dialog_state_name = ""; - if (mode != ACTOR_MODE_AI && mode != ACTOR_MODE_TALK) + if (mode != ActorModeAi && mode != ActorModeTalk) { if (dialog_old_state_name.length()) SetState(dialog_old_state_name.c_str()); @@ -10641,12 +10641,12 @@ void Actor::SetMouthAngle(Event* ev) if (tag_num != -1) { - SetControllerTag(ACTOR_MOUTH_TAG, tag_num); + SetControllerTag(ActorMouthTag, tag_num); mouth_angles = vec_zero; mouth_angles[PITCH] = max_mouth_angle * angle_percent; - SetControllerAngles(ACTOR_MOUTH_TAG, mouth_angles); + SetControllerAngles(ActorMouthTag, mouth_angles); } } @@ -10667,17 +10667,17 @@ qboolean Actor::ModeAllowed(int new_mode) if (deadflag && actortype != IS_INANIMATE) return false; - if (new_mode == ACTOR_MODE_SCRIPT || new_mode == ACTOR_MODE_IDLE) + if (new_mode == ActorModeScript || new_mode == ActorModeIdle) { - if (mode == ACTOR_MODE_AI || mode == ACTOR_MODE_TALK) + if (mode == ActorModeAi || mode == ActorModeTalk) return false; - } else if (new_mode == ACTOR_MODE_TALK) + } else if (new_mode == ActorModeTalk) { //Check if we're already speaking if (GetActorFlag(ACTOR_FLAG_DIALOG_PLAYING)) return false; - if (/*mode == ACTOR_MODE_AI ||*/ mode == ACTOR_MODE_TALK || actortype == IS_ENEMY || !GetActorFlag(ACTOR_FLAG_ALLOW_TALK) || + if (/*mode == ActorModeAi ||*/ mode == ActorModeTalk || actortype == IS_ENEMY || !GetActorFlag(ACTOR_FLAG_ALLOW_TALK) || !dialog_list || level.cinematic) return false; } @@ -10687,7 +10687,7 @@ qboolean Actor::ModeAllowed(int new_mode) void Actor::StartMode(int new_mode) { - if (new_mode == ACTOR_MODE_TALK) + if (new_mode == ActorModeTalk) { SaveMode(); CancelEventsOfType(EV_Actor_EndBehavior); @@ -10702,7 +10702,7 @@ void Actor::StartMode(int new_mode) void Actor::EndMode(void) { - if (mode == ACTOR_MODE_AI) + if (mode == ActorModeAi) { if (GetActorFlag(ACTOR_FLAG_UPDATE_BOSS_HEALTH) && max_boss_health) { @@ -10711,7 +10711,7 @@ void Actor::EndMode(void) gi.cvar_set("bosshealth", bosshealth_string); } - mode = ACTOR_MODE_IDLE; + mode = ActorModeIdle; ProcessEvent(EV_Actor_Idle); if (currentState) @@ -10723,7 +10723,7 @@ void Actor::EndMode(void) } enemyManager->ClearCurrentEnemy(); - } else if (mode == ACTOR_MODE_TALK) + } else if (mode == ActorModeTalk) { next_player_near = level.time + 5.0f; RestoreMode(); @@ -10732,25 +10732,25 @@ void Actor::EndMode(void) void Actor::SaveMode(void) { - if (mode == ACTOR_MODE_IDLE) + if (mode == ActorModeIdle) { - saved_mode = ACTOR_MODE_IDLE; + saved_mode = ActorModeIdle; if (currentState) saved_state_name = currentState->getName(); else saved_state_name = ""; - } else if (mode == ACTOR_MODE_AI) + } else if (mode == ActorModeAi) { - saved_mode = ACTOR_MODE_AI; + saved_mode = ActorModeAi; if (currentState) saved_state_name = currentState->getName(); else saved_state_name = ""; - } else if (mode == ACTOR_MODE_SCRIPT) + } else if (mode == ActorModeScript) { - saved_mode = ACTOR_MODE_SCRIPT; + saved_mode = ActorModeScript; saved_behavior = behavior; saved_headBehavior = headBehavior; saved_eyeBehavior = eyeBehavior; @@ -10784,22 +10784,22 @@ void Actor::RestoreMode(void) { Event* idle_event; - if (saved_mode == ACTOR_MODE_IDLE) + if (saved_mode == ActorModeIdle) { - mode = ACTOR_MODE_IDLE; + mode = ActorModeIdle; idle_event = new Event(EV_Actor_Idle); idle_event->AddString(saved_state_name); ProcessEvent(idle_event); } - if (saved_mode == ACTOR_MODE_AI) + if (saved_mode == ActorModeAi) { - mode = ACTOR_MODE_AI; + mode = ActorModeAi; SetState(saved_state_name); - } else if (saved_mode == ACTOR_MODE_SCRIPT) + } else if (saved_mode == ActorModeScript) { - StartMode(ACTOR_MODE_SCRIPT); + StartMode(ActorModeScript); behavior = saved_behavior; headBehavior = saved_headBehavior; @@ -10838,7 +10838,7 @@ currentEyeBehavior = ""; gi.WDPrintf("Can't restore specified mode: %d\n", saved_mode); } - saved_mode = ACTOR_MODE_NONE; + saved_mode = ActorModeNone; } @@ -11472,7 +11472,7 @@ void Actor::NotifyOthersOfDeath(void) //if ( name.length() && name == act->name && Vector( act->origin - origin ).length() < 1000 ) if (name.length() && name == act->name) - act->AddStateFlag(STATE_FLAG_OTHER_DIED); + act->AddStateFlag(StateFlagOtherDied); } } @@ -11712,7 +11712,7 @@ void Actor::TriggerTouched(Event* ev) other->movetype != MOVETYPE_STATIONARY && IsEntityAlive(other) ) - AddStateFlag(STATE_FLAG_TOUCHED); + AddStateFlag(StateFlagTouched); } void Actor::AddStateFlag(unsigned int flag) @@ -11814,7 +11814,7 @@ void Actor::ActivateEvent(Event*) ProcessEvent(EV_Actor_AttackPlayer); - AddStateFlag(STATE_FLAG_ACTIVATED); + AddStateFlag(StateFlagActivated); } void Actor::UseEvent(Event* ev) @@ -11839,7 +11839,7 @@ void Actor::UseEvent(Event* ev) last_used_time = level.time; - AddStateFlag(STATE_FLAG_USED); + AddStateFlag(StateFlagUsed); if (onuse_thread_name.length() > 0) { @@ -11856,10 +11856,10 @@ void Actor::StartTalkBehavior(Sentient* user) { Talk* talk; - if (!ModeAllowed(ACTOR_MODE_TALK)) + if (!ModeAllowed(ActorModeTalk)) return; - StartMode(ACTOR_MODE_TALK); + StartMode(ActorModeTalk); talk = new Talk; talk->SetUser(user); @@ -12295,7 +12295,7 @@ void Actor::TryTalkToPlayer(void) if (level.cinematic) next_player_near = level.time + 5.0f; - if (deadflag || actortype != IS_FRIEND || next_player_near > level.time || !ModeAllowed(ACTOR_MODE_TALK)) + if (deadflag || actortype != IS_FRIEND || next_player_near > level.time || !ModeAllowed(ActorModeTalk)) return; next_player_near = level.time + .2f + G_Random(.1f); @@ -12347,7 +12347,7 @@ void Actor::TryTalkToPlayer(void) // Go to talk mode - StartMode(ACTOR_MODE_TALK); + StartMode(ActorModeTalk); talk = new Talk; talk->SetUser(user); @@ -12470,11 +12470,11 @@ void Actor::Touched(Event* ev) other = ev->GetEntity(1); - sensoryPerception->Stimuli(STIMULI_SIGHT, other); + sensoryPerception->Stimuli(StimuliSight, other); if (other->isSubclassOf(Player)) { - AddStateFlag(STATE_FLAG_TOUCHED_BY_PLAYER); + AddStateFlag(StateFlagTouchedByPlayer); } } @@ -12505,7 +12505,7 @@ int Actor::NotifyFlag_string_to_int(const str& notifyflagstr) void Actor::ArmorDamage(Event* ev) { - AddStateFlag(STATE_FLAG_ATTACKED); + AddStateFlag(StateFlagAttacked); //if (!TakeDamage()) // return; @@ -12519,10 +12519,10 @@ void Actor::ArmorDamage(Event* ev) { auto MOD = ev->GetInteger(9); if (MOD != MOD_EXPLOSION) - AddStateFlag(STATE_FLAG_ATTACKED_BY_PLAYER); + AddStateFlag(StateFlagAttackedByPlayer); } else { - AddStateFlag(STATE_FLAG_ATTACKED_BY_PLAYER); + AddStateFlag(StateFlagAttackedByPlayer); } } @@ -12532,7 +12532,7 @@ void Actor::ArmorDamage(Event* ev) ::Damage damage(ev); // Only react to an attack if we respond to pain - if (sensoryPerception && sensoryPerception->ShouldRespondToStimuli(STIMULI_PAIN)) + if (sensoryPerception && sensoryPerception->ShouldRespondToStimuli(StimuliPain)) { enemyManager->TryToAddToHateList(enemy); } @@ -12596,7 +12596,7 @@ return; Sentient::ArmorDamage(damage); - sensoryPerception->Stimuli(STIMULI_PAIN, enemy); + sensoryPerception->Stimuli(StimuliPain, enemy); } @@ -13420,7 +13420,7 @@ void Actor::MeleeEvent(Event* ev) if (success) { - AddStateFlag(STATE_FLAG_MELEE_HIT); + AddStateFlag(StateFlagMeleeHit); RunCustomThread("meleehit"); @@ -14937,7 +14937,7 @@ void Actor::_notifyGroupOfEnemy() if (act->GetGroupID() == GetGroupID()) { - act->sensoryPerception->Stimuli(STIMULI_ALL); + act->sensoryPerception->Stimuli(StimuliAll); act->enemyManager->TryToAddToHateList(currentEnemy); act->enemyManager->SetCurrentEnemy(currentEnemy); act->personality->SetAggressiveness(1.0f); @@ -14950,7 +14950,7 @@ void Actor::_notifyGroupOfEnemy() if (act->GetGroupID() == GetGroupID()) { - act->sensoryPerception->Stimuli(STIMULI_ALL); + act->sensoryPerception->Stimuli(StimuliAll); act->enemyManager->TryToAddToHateList(currentEnemy); act->enemyManager->SetCurrentEnemy(currentEnemy); act->personality->SetAggressiveness(1.0f); @@ -15704,7 +15704,7 @@ qboolean Actor::checkWeaponIsMelee(Conditional&) qboolean Actor::checkWeaponChanged(Conditional&) { - return state_flags & STATE_FLAG_CHANGED_WEAPON; + return state_flags & StateFlagChangedWeapon; } //---------------------------------------------------------------- @@ -16605,7 +16605,7 @@ qboolean Actor::checkDamageThresholdExceeded(Conditional&) //-------------------------------------------------------------- qboolean Actor::checkDamageThresholdExceeded() { - return state_flags & STATE_FLAG_DAMAGE_THRESHOLD_EXCEEDED; + return state_flags & StateFlagDamageThresholdExceeded; } //-------------------------------------------------------------- @@ -16901,7 +16901,7 @@ qboolean Actor::checkAttacked(Conditional&) qboolean Actor::checkAttacked() { - return state_flags & STATE_FLAG_ATTACKED; + return state_flags & StateFlagAttacked; } qboolean Actor::checkAttackedByPlayer(Conditional&) @@ -16911,7 +16911,7 @@ qboolean Actor::checkAttackedByPlayer(Conditional&) qboolean Actor::checkAttackedByPlayer() { - return state_flags & STATE_FLAG_ATTACKED_BY_PLAYER; + return state_flags & StateFlagAttackedByPlayer; } qboolean Actor::checkShowPain(Conditional&) @@ -16921,7 +16921,7 @@ qboolean Actor::checkShowPain(Conditional&) qboolean Actor::checkShowPain() { - return state_flags & STATE_FLAG_SHOW_PAIN; + return state_flags & StateFlagShowPain; } qboolean Actor::checkPropEnemyRange(Conditional& condition) @@ -17843,7 +17843,7 @@ void Actor::DebugEvent(Event*) qboolean Actor::checkSteeringFailed(Conditional&) { - return state_flags & STATE_FLAG_STEERING_FAILED; + return state_flags & StateFlagSteeringFailed; } qboolean Actor::checkHavePathToEnemy(Conditional&) @@ -17901,14 +17901,14 @@ void Actor::UnreserveCurrentHelperNode() qboolean Actor::checkBlockedByEnemy(Conditional&) { - if (!(state_flags & STATE_FLAG_BLOCKED_BY_ENTITY)) + if (!(state_flags & StateFlagBlockedByEntity)) return false; auto blockingEntity = movementSubsystem->getBlockingEntity(); if (!blockingEntity) return false; - sensoryPerception->Stimuli(STIMULI_SIGHT, blockingEntity); + sensoryPerception->Stimuli(StimuliSight, blockingEntity); if (enemyManager->Hates(blockingEntity)) @@ -17926,7 +17926,7 @@ void Actor::ProjectileClose(Event* ev) if (enemyManager->Hates(owner)) { - AddStateFlag(STATE_FLAG_ENEMY_PROJECTILE_CLOSE); + AddStateFlag(StateFlagEnemyProjectileClose); } } @@ -17937,7 +17937,7 @@ qboolean Actor::checkEnemyProjectileClose(Conditional&) qboolean Actor::checkEnemyProjectileClose() { - return state_flags & STATE_FLAG_ENEMY_PROJECTILE_CLOSE; + return state_flags & StateFlagEnemyProjectileClose; } void Actor::SaveOffLastHitBone(Event*) @@ -18181,7 +18181,7 @@ qboolean Actor::checkTalking(Conditional&) qboolean Actor::checkTalking() { - if (mode == ACTOR_MODE_TALK) + if (mode == ActorModeTalk) return true; return false; diff --git a/dlls/game/actor_combatsubsystem.cpp b/dlls/game/actor_combatsubsystem.cpp index 6a82a45..6a3660f 100644 --- a/dlls/game/actor_combatsubsystem.cpp +++ b/dlls/game/actor_combatsubsystem.cpp @@ -74,7 +74,7 @@ void CombatSubsystem::UseActorWeapon(const str& weaponName, weaponhand_t hand) act->DeactivateWeapon(WEAPON_LEFT); act->DeactivateWeapon(WEAPON_RIGHT); act->DeactivateWeapon(WEAPON_DUAL); - act->AddStateFlag(STATE_FLAG_CHANGED_WEAPON); + act->AddStateFlag(StateFlagChangedWeapon); act->ClearTorsoAnim(); _activeWeapon.weapon = nullptr; @@ -97,7 +97,7 @@ void CombatSubsystem::UseActorWeapon(const str& weaponName, weaponhand_t hand) _activeWeapon.hand = hand; _activeWeapon.weapon->SetOwner(act); act->ActivateWeapon(weapon, hand); - act->AddStateFlag(STATE_FLAG_CHANGED_WEAPON); + act->AddStateFlag(StateFlagChangedWeapon); return; } @@ -115,7 +115,7 @@ void CombatSubsystem::UseActorWeapon(const str& weaponName, weaponhand_t hand) _activeWeapon.hand = hand; _activeWeapon.weapon->SetOwner(act); act->ActivateWeapon(weapon, hand); - act->AddStateFlag(STATE_FLAG_CHANGED_WEAPON); + act->AddStateFlag(StateFlagChangedWeapon); } // diff --git a/dlls/game/actor_enemymanager.cpp b/dlls/game/actor_enemymanager.cpp index e5d225b..74b3254 100644 --- a/dlls/game/actor_enemymanager.cpp +++ b/dlls/game/actor_enemymanager.cpp @@ -628,7 +628,7 @@ void EnemyManager::Update() act->sensoryPerception->SenseEnemies(); - if (GetCurrentEnemy() || act->GetActorFlag(ACTOR_FLAG_INVESTIGATING) || act->mode == ACTOR_MODE_SCRIPT || act->mode == ACTOR_MODE_TALK) + if (GetCurrentEnemy() || act->GetActorFlag(ACTOR_FLAG_INVESTIGATING) || act->mode == ActorModeScript || act->mode == ActorModeTalk) act->last_time_active = level.time; // Take care of enemies @@ -912,7 +912,7 @@ void EnemyManager::TrySleep(void) if (player) { //We should NOT fall asleep if: - // our mode is ACTOR_MODE_IDLE _AND_ player flags are not equal to FlagNotarget + // our mode is ActorModeIdle _AND_ player flags are not equal to FlagNotarget // OR // Player is within our vision distance // OR @@ -920,19 +920,19 @@ void EnemyManager::TrySleep(void) // // 7/15/02 -- SK - // Added via && the "gi.inPVS( player->centroid, act->centroid )" to the ACTOR_MODE_IDLE + // Added via && the "gi.inPVS( player->centroid, act->centroid )" to the ActorModeIdle // checks because, without it, all AI_OFF'd actors would still be considered "active" // and this was ruining the framerate... I do not believe this is going to have any // detrimental side effects. // - if (act->mode == ACTOR_MODE_IDLE && !(player->flags & FlagNotarget) && gi.inPVS(player->centroid, act->centroid) || act->sensoryPerception->WithinVisionDistance(player) || gi.inPVS(player->centroid, act->centroid)) + if (act->mode == ActorModeIdle && !(player->flags & FlagNotarget) && gi.inPVS(player->centroid, act->centroid) || act->sensoryPerception->WithinVisionDistance(player) || gi.inPVS(player->centroid, act->centroid)) { act->last_time_active = level.time; } else { - if (act->mode == ACTOR_MODE_AI) + if (act->mode == ActorModeAi) { act->EndMode(); diff --git a/dlls/game/actor_headwatcher.cpp b/dlls/game/actor_headwatcher.cpp index 8f3d0f9..2bcf367 100644 --- a/dlls/game/actor_headwatcher.cpp +++ b/dlls/game/actor_headwatcher.cpp @@ -13,317 +13,285 @@ // // -#include "_pch_cpp.h" #include "actor_enemymanager.h" -#include "player.h" -#include "object.h" +#include "_pch_cpp.h" HeadWatcher::HeadWatcher() { - // Should always use other constructor - gi.Error( ERR_FATAL, "HeadWatcher::HeadWatcher -- Default Constructor Called" ); - - + // Should always use other constructor + gi.Error(ERR_FATAL, "HeadWatcher::HeadWatcher -- Default Constructor Called"); + + } -HeadWatcher::HeadWatcher( Actor *actor ) +HeadWatcher::HeadWatcher(Actor *actor) { - //Initialize our Actor - if ( actor ) - act = actor; - else - gi.Error( ERR_DROP, "HeadWatcher::HeadWatcher -- actor is NULL" ); - - _init(); - + //Initialize our Actor + if (actor) + act = actor; + else + gi.Error(ERR_DROP, "HeadWatcher::HeadWatcher -- actor is NULL"); + + _init(); + } HeadWatcher::~HeadWatcher() { - + } void HeadWatcher::_init() { - act->SetControllerTag( ACTOR_HEAD_TAG, gi.Tag_NumForName( act->edict->s.modelindex, "Bip01 Head" ) ); - - _currentHeadAngles = act->GetControllerAngles( ACTOR_HEAD_TAG ); - _watchTarget = NULL; - - // Numbers here for testing, should come from events so they can be set via tiki or script - _maxHeadTurnSpeed = 30.0f; - _turnThreshold = 0.0f; - _maxHeadYaw = 60.0f; - _maxHeadPitch = 45.0f; - - _twitchHead = false; - _nextTwitchHeadTime = 0.0f; - _maxDistance = -1.0; + act->SetControllerTag(ActorHeadTag, gi.Tag_NumForName(act->edict->s.modelindex, "Bip01 Head")); - _explicitSet = false; - _ignoreWatchTarget = false; + _currentHeadAngles = act->GetControllerAngles(ActorHeadTag); + _watchTarget = nullptr; + + // Numbers here for testing, should come from events so they can be set via tiki or script + _maxHeadTurnSpeed = 30.0f; + _turnThreshold = 0.0f; + _maxHeadYaw = 60.0f; + _maxHeadPitch = 45.0f; + + _twitchHead = false; + _nextTwitchHeadTime = 0.0f; + _maxDistance = -1.0; + + _explicitSet = false; + _ignoreWatchTarget = false; } -void HeadWatcher::SetWatchTarget( Entity *ent ) +void HeadWatcher::SetWatchTarget(Entity *ent) { - _watchTarget = ent; - _explicitSet = true; + _watchTarget = ent; + _explicitSet = true; } -void HeadWatcher::SetWatchTarget( const str &targetName ) +void HeadWatcher::SetWatchTarget(const str &targetName) { - TargetList *tlist; - int numObjects; - - - tlist = world->GetTargetList( targetName ); - numObjects = tlist->list.NumObjects(); - - if ( numObjects == 0 ) - { - //Hey, No targets with that name - gi.WDPrintf( "No target with target name %s specified\n", targetName.c_str() ); - return; - } - else if ( numObjects > 1 ) - { - //Uh Oh... We have more than one target... Let's throw up an error - gi.WDPrintf( "More than one target with target name %s specified, grabbing first one\n", targetName.c_str() ); - } - - _watchTarget = tlist->list.ObjectAt( 1 ); - _explicitSet = true; + auto tlist = world->GetTargetList(targetName); + auto numObjects = tlist->list.NumObjects(); + + if (numObjects == 0) + { + //Hey, No targets with that name + gi.WDPrintf("No target with target name %s specified\n", targetName.c_str()); + return; + } + if (numObjects > 1) + { + //Uh Oh... We have more than one target... Let's throw up an error + gi.WDPrintf("More than one target with target name %s specified, grabbing first one\n", targetName.c_str()); + } + + _watchTarget = tlist->list.ObjectAt(1); + _explicitSet = true; } -void HeadWatcher::SetWatchSpeed( float speed ) +void HeadWatcher::SetWatchSpeed(float speed) { - _maxHeadTurnSpeed = speed; + _maxHeadTurnSpeed = speed; } void HeadWatcher::ClearWatchTarget() { - _watchTarget = NULL; - _explicitSet = false; + _watchTarget = nullptr; + _explicitSet = false; } Entity *HeadWatcher::GetWatchTarget() { - return _watchTarget; + return _watchTarget; } void HeadWatcher::HeadWatchTarget() { - int tagNum; - Vector tagPos; - Vector watchPosition; - Actor *actTarget; - actTarget = NULL; - - - tagNum = gi.Tag_NumForName( act->edict->s.modelindex, "Bip01 Head" ); - - if ( tagNum < 0 ) - return; - - //Check if we even have an animation set yet - if ( act->animate->CurrentAnim(legs) < 0 ) - return; + auto tagNum = gi.Tag_NumForName(act->edict->s.modelindex, "Bip01 Head"); - act->GetTag( "Bip01 Head", &tagPos ); - - if ( !_watchTarget || _ignoreWatchTarget ) - { - if ( _twitchHead ) - { - twitchHead(); - return; - } - else - { - LerpHeadBySpeed( vec_zero , false ); - return; - } - } + if (tagNum < 0) + return; - if (act->GetActorFlag( ACTOR_FLAG_DIALOG_PLAYING ) && act->GetActorFlag(ACTOR_FLAG_USING_HUD) ) - { - LerpHeadBySpeed( vec_zero , false ); - return; - } + //Check if we even have an animation set yet + if (act->animate->CurrentAnim(legs) < 0) + return; - // Check if our _watchTarget is within distance ) - if ( _maxDistance > 0 ) - { - Vector selfToTarget = _watchTarget->origin - act->origin; - float dist = selfToTarget.length(); + Vector tagPos; + act->GetTag("Bip01 Head", &tagPos); - if ( dist > _maxDistance ) - { - LerpHeadBySpeed( vec_zero , false ); - return; - } - } + if (!_watchTarget || _ignoreWatchTarget) + { + if (_twitchHead) + { + twitchHead(); + return; + } + LerpHeadBySpeed(vec_zero, false); + return; + } + + if (act->GetActorFlag(ACTOR_FLAG_DIALOG_PLAYING) && act->GetActorFlag(ACTOR_FLAG_USING_HUD)) + { + LerpHeadBySpeed(vec_zero, false); + return; + } + + // Check if our _watchTarget is within distance ) + if (_maxDistance > 0) + { + auto selfToTarget = _watchTarget->origin - act->origin; + auto dist = selfToTarget.length(); + + if (dist > _maxDistance) + { + LerpHeadBySpeed(vec_zero, false); + return; + } + } + + Actor* actTarget = nullptr; + if (_watchTarget->isSubclassOf(Actor)) + { + actTarget = dynamic_cast(static_cast(_watchTarget)); + + // Don't watch if the target is dead. + if (!actTarget->isThinkOn()) + { + _watchTarget = nullptr; + return; + } + } + + Vector watchPosition; + if (actTarget && actTarget->watch_offset != vec_zero) + { + MatrixTransformVector(actTarget->watch_offset, _watchTarget->orientation, watchPosition); + watchPosition += _watchTarget->origin; + } else + { + tagNum = gi.Tag_NumForName(_watchTarget->edict->s.modelindex, "Bip01 Head"); + + if (tagNum < 0) + watchPosition = _watchTarget->centroid; + else + { + _watchTarget->GetTag("Bip01 Head", &watchPosition); + } + } + + + AdjustHeadAngles(tagPos, watchPosition); - if ( _watchTarget->isSubclassOf( Actor ) ) - { - actTarget = (Actor *)(Entity *)_watchTarget; - - // Don't watch if the target is dead. - if ( !actTarget->isThinkOn() ) - { - _watchTarget = NULL; - actTarget = NULL; - return; - } - } - - if ( actTarget && ( actTarget->watch_offset != vec_zero ) ) - { - MatrixTransformVector( actTarget->watch_offset, _watchTarget->orientation, watchPosition ); - watchPosition += _watchTarget->origin; - } - else - { - tagNum = gi.Tag_NumForName( _watchTarget->edict->s.modelindex, "Bip01 Head" ); - - if ( tagNum < 0 ) - watchPosition = _watchTarget->centroid; - else - { - _watchTarget->GetTag( "Bip01 Head", &watchPosition ); - } - } - - - AdjustHeadAngles( tagPos , watchPosition ); - } -void HeadWatcher::AdjustHeadAngles( const Vector &tagPos , const Vector &watchPosition ) +void HeadWatcher::AdjustHeadAngles(const Vector &tagPos, const Vector &watchPosition) { - Vector dir; - Vector angles; - Vector anglesDiff; - float yawChange; - float pitchChange; - - - dir = watchPosition - tagPos; - angles = dir.toAngles(); - - anglesDiff = angles - act->angles; - - - anglesDiff[YAW] = AngleNormalize180( anglesDiff[YAW] ); - anglesDiff[PITCH] = AngleNormalize180( anglesDiff[PITCH] ); - - yawChange = anglesDiff[YAW]; - pitchChange = anglesDiff[PITCH]; - - if ( _turnThreshold && ( yawChange < _turnThreshold ) && ( yawChange > -_turnThreshold ) && ( pitchChange < _turnThreshold ) && ( pitchChange > -_turnThreshold ) ) - { - return; - } - - - // Make sure we don't turn neck too far - if ( anglesDiff[YAW] < -_maxHeadYaw ) - anglesDiff[YAW] = -_maxHeadYaw; - else if ( anglesDiff[YAW] > _maxHeadYaw ) - anglesDiff[YAW] = _maxHeadYaw; - - if ( anglesDiff[PITCH] < -_maxHeadPitch ) - anglesDiff[PITCH] = -_maxHeadPitch; - else if ( anglesDiff[PITCH] > _maxHeadPitch ) - anglesDiff[PITCH] = _maxHeadPitch; - - anglesDiff[ROLL] = 0.0f; - - - LerpHeadBySpeed( anglesDiff ); - + auto dir = watchPosition - tagPos; + auto angles = dir.toAngles(); + auto anglesDiff = angles - act->angles; + + + anglesDiff[YAW] = AngleNormalize180(anglesDiff[YAW]); + anglesDiff[PITCH] = AngleNormalize180(anglesDiff[PITCH]); + + auto yawChange = anglesDiff[YAW]; + auto pitchChange = anglesDiff[PITCH]; + + if (_turnThreshold && yawChange < _turnThreshold && yawChange > -_turnThreshold && pitchChange < _turnThreshold && pitchChange > -_turnThreshold) + { + return; + } + + + // Make sure we don't turn neck too far + if (anglesDiff[YAW] < -_maxHeadYaw) + anglesDiff[YAW] = -_maxHeadYaw; + else if (anglesDiff[YAW] > _maxHeadYaw) + anglesDiff[YAW] = _maxHeadYaw; + + if (anglesDiff[PITCH] < -_maxHeadPitch) + anglesDiff[PITCH] = -_maxHeadPitch; + else if (anglesDiff[PITCH] > _maxHeadPitch) + anglesDiff[PITCH] = _maxHeadPitch; + + anglesDiff[ROLL] = 0.0f; + + + LerpHeadBySpeed(anglesDiff); + } -void HeadWatcher::LerpHeadBySpeed( const Vector &angleDelta , bool useTorsoAngles ) +void HeadWatcher::LerpHeadBySpeed(const Vector &angleDelta, bool useTorsoAngles) { - Vector anglesDiff; - Vector change; - Vector finalAngles; - Vector currentTorsoAngles; - - anglesDiff = angleDelta; - - // Get our Torso Angles - act->SetControllerTag( ACTOR_TORSO_TAG , gi.Tag_NumForName( act->edict->s.modelindex, "Bip01 Spine1" ) ); - currentTorsoAngles = act->GetControllerAngles( ACTOR_TORSO_TAG ); - - //Reset our Controller Tag - act->SetControllerTag( ACTOR_HEAD_TAG, gi.Tag_NumForName( act->edict->s.modelindex, "Bip01 Head" ) ); - - - // Make sure we don't change our head angles too much at once - change = anglesDiff - _currentHeadAngles; - - if ( change[YAW] > _maxHeadTurnSpeed ) - anglesDiff[YAW] = _currentHeadAngles[YAW] + _maxHeadTurnSpeed; - else if ( change[YAW] < -_maxHeadTurnSpeed ) - anglesDiff[YAW] = _currentHeadAngles[YAW] - _maxHeadTurnSpeed; - - if ( change[PITCH] > _maxHeadTurnSpeed ) - anglesDiff[PITCH] = _currentHeadAngles[PITCH] + _maxHeadTurnSpeed; - else if ( change[PITCH] < -_maxHeadTurnSpeed ) - anglesDiff[PITCH] = _currentHeadAngles[PITCH] - _maxHeadTurnSpeed; - - if ( change[ROLL] > _maxHeadTurnSpeed ) - anglesDiff[ROLL] = _currentHeadAngles[ROLL] + _maxHeadTurnSpeed; - else if ( change[ROLL] < -_maxHeadTurnSpeed ) - anglesDiff[ROLL] = _currentHeadAngles[ROLL] - _maxHeadTurnSpeed; - - - finalAngles = anglesDiff; - - if ( useTorsoAngles ) - finalAngles[YAW] = anglesDiff[YAW] - currentTorsoAngles[YAW]; - else - finalAngles[YAW] = anglesDiff[YAW]; - - act->SetControllerAngles( ACTOR_HEAD_TAG, finalAngles ); - act->real_head_pitch = anglesDiff[PITCH]; - - _currentHeadAngles = anglesDiff; - + auto anglesDiff = angleDelta; + + // Get our Torso Angles + act->SetControllerTag(ActorTorsoTag, gi.Tag_NumForName(act->edict->s.modelindex, "Bip01 Spine1")); + auto currentTorsoAngles = act->GetControllerAngles(ActorTorsoTag); + + //Reset our Controller Tag + act->SetControllerTag(ActorHeadTag, gi.Tag_NumForName(act->edict->s.modelindex, "Bip01 Head")); + + + // Make sure we don't change our head angles too much at once + auto change = anglesDiff - _currentHeadAngles; + + if (change[YAW] > _maxHeadTurnSpeed) + anglesDiff[YAW] = _currentHeadAngles[YAW] + _maxHeadTurnSpeed; + else if (change[YAW] < -_maxHeadTurnSpeed) + anglesDiff[YAW] = _currentHeadAngles[YAW] - _maxHeadTurnSpeed; + + if (change[PITCH] > _maxHeadTurnSpeed) + anglesDiff[PITCH] = _currentHeadAngles[PITCH] + _maxHeadTurnSpeed; + else if (change[PITCH] < -_maxHeadTurnSpeed) + anglesDiff[PITCH] = _currentHeadAngles[PITCH] - _maxHeadTurnSpeed; + + if (change[ROLL] > _maxHeadTurnSpeed) + anglesDiff[ROLL] = _currentHeadAngles[ROLL] + _maxHeadTurnSpeed; + else if (change[ROLL] < -_maxHeadTurnSpeed) + anglesDiff[ROLL] = _currentHeadAngles[ROLL] - _maxHeadTurnSpeed; + + + auto finalAngles = anglesDiff; + + if (useTorsoAngles) + finalAngles[YAW] = anglesDiff[YAW] - currentTorsoAngles[YAW]; + else + finalAngles[YAW] = anglesDiff[YAW]; + + act->SetControllerAngles(ActorHeadTag, finalAngles); + act->real_head_pitch = anglesDiff[PITCH]; + + _currentHeadAngles = anglesDiff; + } -void HeadWatcher::setHeadTwitch( bool twitchHead ) +void HeadWatcher::setHeadTwitch(bool twitchHead) { - _twitchHead = twitchHead; + _twitchHead = twitchHead; - if ( _twitchHead ) - { - _nextTwitchHeadTime = 0.0f; - } + if (_twitchHead) + { + _nextTwitchHeadTime = 0.0f; + } } -void HeadWatcher::twitchHead( void ) +void HeadWatcher::twitchHead(void) { - Vector headAngles; - float oldMaxHeadTurnSpeed; + if (level.time > _nextTwitchHeadTime) + { + _headTwitchAngles = Vector(G_CRandom(4.0f), G_CRandom(4.0f), G_CRandom(4.0f)); + _nextTwitchHeadTime = level.time + 1.0f + G_CRandom(0.5f); + } - if ( level.time > _nextTwitchHeadTime ) - { - _headTwitchAngles = Vector( G_CRandom( 4.0f ), G_CRandom( 4.0f ), G_CRandom( 4.0f ) ); + auto oldMaxHeadTurnSpeed = _maxHeadTurnSpeed; - _nextTwitchHeadTime = level.time + 1.0f + G_CRandom( 0.5f ); - } + _maxHeadTurnSpeed = 0.25f; - oldMaxHeadTurnSpeed = _maxHeadTurnSpeed; + LerpHeadBySpeed(_headTwitchAngles, false); - _maxHeadTurnSpeed = 0.25f; - - LerpHeadBySpeed( _headTwitchAngles, false ); - - _maxHeadTurnSpeed = oldMaxHeadTurnSpeed; + _maxHeadTurnSpeed = oldMaxHeadTurnSpeed; } @@ -333,14 +301,14 @@ void HeadWatcher::twitchHead( void ) // Actor *actor // Description: Sets the Actor Pointer and Calls Archive() // -void HeadWatcher::DoArchive( Archiver &arc , Actor *actor ) +void HeadWatcher::DoArchive(Archiver &arc, Actor *actor) { - Archive( arc ); - if ( actor ) - act = actor; - else - gi.Error( ERR_FATAL, "HeadWatcher::DoArchive -- actor is NULL" ); - + Archive(arc); + if (actor) + act = actor; + else + gi.Error(ERR_FATAL, "HeadWatcher::DoArchive -- actor is NULL"); + } // @@ -348,18 +316,18 @@ void HeadWatcher::DoArchive( Archiver &arc , Actor *actor ) // Parameters: Archiver &arc // Description: Archives Class Data // -void HeadWatcher::Archive( Archiver &arc ) +void HeadWatcher::Archive(Archiver &arc) { - arc.ArchiveSafePointer( &_watchTarget ); - arc.ArchiveVector( &_currentHeadAngles ); - arc.ArchiveFloat( &_maxHeadTurnSpeed ); - arc.ArchiveFloat( &_turnThreshold ); - arc.ArchiveBoolean( &_explicitSet ); - arc.ArchiveFloat( &_maxHeadYaw ); - arc.ArchiveFloat( &_maxHeadPitch ); - arc.ArchiveBool( &_twitchHead ); - arc.ArchiveFloat( &_nextTwitchHeadTime ); - arc.ArchiveVector( &_headTwitchAngles ); - arc.ArchiveFloat( &_maxDistance ); - arc.ArchiveBool( &_ignoreWatchTarget ); + arc.ArchiveSafePointer(&_watchTarget); + arc.ArchiveVector(&_currentHeadAngles); + arc.ArchiveFloat(&_maxHeadTurnSpeed); + arc.ArchiveFloat(&_turnThreshold); + arc.ArchiveBoolean(&_explicitSet); + arc.ArchiveFloat(&_maxHeadYaw); + arc.ArchiveFloat(&_maxHeadPitch); + arc.ArchiveBool(&_twitchHead); + arc.ArchiveFloat(&_nextTwitchHeadTime); + arc.ArchiveVector(&_headTwitchAngles); + arc.ArchiveFloat(&_maxDistance); + arc.ArchiveBool(&_ignoreWatchTarget); } diff --git a/dlls/game/actor_headwatcher.h b/dlls/game/actor_headwatcher.h index 2a223db..e545a36 100644 --- a/dlls/game/actor_headwatcher.h +++ b/dlls/game/actor_headwatcher.h @@ -20,82 +20,78 @@ #ifndef __ACTOR_HEADWATCHER_H__ #define __ACTOR_HEADWATCHER_H__ -#include "actor.h" -#include "actorincludes.h" -#include "weapon.h" - //============================ // Class HeadWatcher //============================ class HeadWatcher - { - public: - HeadWatcher(); - HeadWatcher( Actor *actor ); - ~HeadWatcher(); - - void SetWatchTarget( Entity *ent ); - void SetWatchTarget( const str &targetName ); - void SetWatchSpeed ( float speed ); - void SetMaxHeadYaw ( float max ); - void SetMaxHeadPitch ( float max ); - void SetMaxDistance( float distance ); - void SetIgnoreWatchTarget( bool ignore ); - - Entity* GetWatchTarget(); - - void ClearWatchTarget(); - void HeadWatchTarget(); - void AdjustHeadAngles( const Vector &tagPos , const Vector &watchPosition ); - void LerpHeadBySpeed( const Vector &angleDelta , bool useTorsoAngles = true ); - - void setHeadTwitch( bool twitchHead ); - void twitchHead( void ); - - // Archiving - virtual void Archive( Archiver &arc ); - void DoArchive( Archiver &arc , Actor *actor ); - - protected: - void _init(); - - private: - EntityPtr _watchTarget; - Vector _currentHeadAngles; - float _maxHeadTurnSpeed; - float _turnThreshold; - qboolean _explicitSet; - float _maxHeadYaw; - float _maxHeadPitch; - - bool _twitchHead; - float _nextTwitchHeadTime; - Vector _headTwitchAngles; - float _maxDistance; - bool _ignoreWatchTarget; - - Actor *act; - - }; - -inline void HeadWatcher::SetMaxHeadPitch( float max ) { - _maxHeadPitch = max; +public: + HeadWatcher(); + explicit HeadWatcher(Actor *actor); + virtual ~HeadWatcher(); + + void SetWatchTarget(Entity *ent); + void SetWatchTarget(const str &targetName); + void SetWatchSpeed(float speed); + void SetMaxHeadYaw(float max); + void SetMaxHeadPitch(float max); + void SetMaxDistance(float distance); + void SetIgnoreWatchTarget(bool ignore); + + Entity* GetWatchTarget(); + + void ClearWatchTarget(); + void HeadWatchTarget(); + void AdjustHeadAngles(const Vector &tagPos, const Vector &watchPosition); + void LerpHeadBySpeed(const Vector &angleDelta, bool useTorsoAngles = true); + + void setHeadTwitch(bool twitchHead); + void twitchHead(void); + + // Archiving + virtual void Archive(Archiver &arc); + void DoArchive(Archiver &arc, Actor *actor); + +protected: + void _init(); + +private: + EntityPtr _watchTarget; + Vector _currentHeadAngles; + float _maxHeadTurnSpeed; + float _turnThreshold; + qboolean _explicitSet; + float _maxHeadYaw; + float _maxHeadPitch; + + bool _twitchHead; + float _nextTwitchHeadTime; + Vector _headTwitchAngles; + float _maxDistance; + bool _ignoreWatchTarget; + + Actor *act; + +}; + +inline void HeadWatcher::SetMaxHeadPitch(float max) +{ + _maxHeadPitch = max; } -inline void HeadWatcher::SetMaxHeadYaw( float max ) +inline void HeadWatcher::SetMaxHeadYaw(float max) { - _maxHeadYaw = max; + _maxHeadYaw = max; } -inline void HeadWatcher::SetMaxDistance( float distance ) +inline void HeadWatcher::SetMaxDistance(float distance) { - _maxDistance = distance; + _maxDistance = distance; } -inline void HeadWatcher::SetIgnoreWatchTarget( bool ignore ) +inline void HeadWatcher::SetIgnoreWatchTarget(bool ignore) { - _ignoreWatchTarget = ignore; + _ignoreWatchTarget = ignore; } #endif /* __ACTOR_HEADWATCHER_H__ */ diff --git a/dlls/game/actor_locomotion.cpp b/dlls/game/actor_locomotion.cpp index 059d762..ae4837d 100644 --- a/dlls/game/actor_locomotion.cpp +++ b/dlls/game/actor_locomotion.cpp @@ -13,9 +13,6 @@ // #include "_pch_cpp.h" -#include "actor_locomotion.h" -#include "player.h" -#include "object.h" //====================================== // LocomotionController Implementation @@ -34,30 +31,8 @@ // LocomotionController::LocomotionController() { - // Should always use other constructor - gi.Error( ERR_FATAL, "LocomotionController::LocomotionController -- Default Constructor Called" ); -} - - -// -// Name: LocomotionController() -// Class: LocomotionController -// -// Description: Default Constructor -// -// Parameters: Actor *actor -// -// Returns: None -// -LocomotionController::LocomotionController( Actor *actor ) -{ - //Initialize our Actor - if ( actor ) - act = actor; - else - gi.Error( ERR_DROP, "LocomotionController::LocomotionController -- actor is NULL" ); - - _init(); + // Should always use other constructor + gi.Error(ERR_FATAL, "LocomotionController::LocomotionController -- Default Constructor Called"); } @@ -73,7 +48,7 @@ LocomotionController::LocomotionController( Actor *actor ) // LocomotionController::~LocomotionController() { - + } @@ -89,7 +64,7 @@ LocomotionController::~LocomotionController() // void LocomotionController::Begin() { - _chase.Begin( *act ); + _chase.Begin(*act); } @@ -105,7 +80,7 @@ void LocomotionController::Begin() // void LocomotionController::Evaluate() { - _chase.Evaluate( *act ); + _chase.Evaluate(*act); } @@ -121,7 +96,7 @@ void LocomotionController::Evaluate() // void LocomotionController::End() { - _chase.End( *act ); + _chase.End(*act); } @@ -135,9 +110,9 @@ void LocomotionController::End() // // Returns: None // -void LocomotionController::SetMovementStyle( MovementStyle style ) +void LocomotionController::SetMovementStyle(MovementStyle style) { - _movementStyle = style; + _movementStyle = style; } @@ -153,7 +128,7 @@ void LocomotionController::SetMovementStyle( MovementStyle style ) // MovementStyle LocomotionController::GetMovementStyle() { - return _movementStyle; + return _movementStyle; } @@ -168,13 +143,13 @@ MovementStyle LocomotionController::GetMovementStyle() // // Returns: None // -void LocomotionController::DoArchive( Archiver &arc , Actor *actor ) +void LocomotionController::DoArchive(Archiver &arc, Actor *actor) { - Archive( arc ); - if ( actor ) - act = actor; - else - gi.Error( ERR_FATAL, "LocomotionController::DoArchive -- actor is NULL" ); + Archive(arc); + if (actor) + act = actor; + else + gi.Error(ERR_FATAL, "LocomotionController::DoArchive -- actor is NULL"); } // @@ -187,10 +162,10 @@ void LocomotionController::DoArchive( Archiver &arc , Actor *actor ) // // Returns: None // -void LocomotionController::Archive( Archiver &arc ) -{ - ArchiveEnum( _movementStyle, MovementStyle ); - arc.ArchiveObject( &_chase ); +void LocomotionController::Archive(Archiver &arc) +{ + ArchiveEnum(_movementStyle, MovementStyle); + arc.ArchiveObject(&_chase); } @@ -205,8 +180,8 @@ void LocomotionController::Archive( Archiver &arc ) // Returns: None // void LocomotionController::_init() -{ - _movementStyle = MOVEMENT_STYLE_NONE; +{ + _movementStyle = MOVEMENT_STYLE_NONE; } @@ -218,7 +193,7 @@ void LocomotionController::_init() //===================================== // Init Static Vars -Vector MovementSubsystem::_step = Vector( 0.0f, 0.0f, STEPSIZE ); +Vector MovementSubsystem::_step = Vector(0.0f, 0.0f, STEPSIZE); // @@ -233,8 +208,8 @@ Vector MovementSubsystem::_step = Vector( 0.0f, 0.0f, STEPSIZE ); // MovementSubsystem::MovementSubsystem() { - // Should always use other constructor - gi.Error( ERR_FATAL, "MovementSubsystem::MovementSubsystem -- Default Constructor Called" ); + // Should always use other constructor + gi.Error(ERR_FATAL, "MovementSubsystem::MovementSubsystem -- Default Constructor Called"); } @@ -248,15 +223,15 @@ MovementSubsystem::MovementSubsystem() // // Returns: None // -MovementSubsystem::MovementSubsystem( Actor *actor ) +MovementSubsystem::MovementSubsystem(Actor *actor) { - //Initialize our Actor - if ( actor ) - act = actor; - else - gi.Error( ERR_DROP, "MovementSubsystem::MovementSubsystem -- actor is NULL" ); - - _init(); + //Initialize our Actor + if (actor) + act = actor; + else + gi.Error(ERR_DROP, "MovementSubsystem::MovementSubsystem -- actor is NULL"); + + _init(); } @@ -272,11 +247,11 @@ MovementSubsystem::MovementSubsystem( Actor *actor ) // MovementSubsystem::~MovementSubsystem() { - if ( _path ) - { - delete _path; - _path = NULL; - } + if (_path) + { + delete _path; + _path = nullptr; + } } @@ -290,9 +265,9 @@ MovementSubsystem::~MovementSubsystem() // // Returns: True or False // -qboolean MovementSubsystem::CanMoveTo ( const Vector &pos ) +qboolean MovementSubsystem::CanMoveTo(const Vector &pos) { - return _canMoveSimplePath( act->mins, act->maxs , pos ); + return _canMoveSimplePath(act->mins, act->maxs, pos); } @@ -307,13 +282,13 @@ qboolean MovementSubsystem::CanMoveTo ( const Vector &pos ) // Returns: whether the direction is clear and has a floor // -bool MovementSubsystem::CanWalkTowardsPoint( const Vector &goalPoint, const int mask ) +bool MovementSubsystem::CanWalkTowardsPoint(const Vector &goalPoint, const int mask) { - Vector step( goalPoint - act->origin ); - const float distance = Vector::Distance( goalPoint, act->origin ); - step.normalize(); - step *= min( distance, max ( 64.0f, Vector::Distance( act->origin, act->last_origin ) ) ); - return CanWalkTo( act->origin + step, 0, ENTITYNUM_NONE, mask ) == 1; + auto step(goalPoint - act->origin); + auto distance = Vector::Distance(goalPoint, act->origin); + step.normalize(); + step *= min(distance, max(64.0f, Vector::Distance(act->origin, act->last_origin))); + return CanWalkTo(act->origin + step, 0, ENTITYNUM_NONE, mask) == 1; } @@ -329,9 +304,9 @@ bool MovementSubsystem::CanWalkTowardsPoint( const Vector &goalPoint, const int // // Returns: // -qboolean MovementSubsystem::CanWalkTo( const Vector &pos, float bounding_box_extra, int entnum, const int mask ) +qboolean MovementSubsystem::CanWalkTo(const Vector &pos, float bounding_box_extra, int entnum, const int mask) { - return CanWalkToFrom( act->origin, pos, bounding_box_extra, entnum, mask ); + return CanWalkToFrom(act->origin, pos, bounding_box_extra, entnum, mask); } @@ -348,43 +323,29 @@ qboolean MovementSubsystem::CanWalkTo( const Vector &pos, float bounding_box_ext // // Returns: True or False // -qboolean MovementSubsystem::CanWalkToFrom ( const Vector &origin, const Vector &pos, float bounding_box_extra, int entnum, const int mask ) +qboolean MovementSubsystem::CanWalkToFrom(const Vector &origin, const Vector &pos, float bounding_box_extra, int entnum, const int mask) { - Vector real_pos; - Vector test_mins; - Vector test_maxs; - - - // Setup bounding box - test_mins = act->mins; - test_maxs = act->maxs; - - test_mins.x -= bounding_box_extra; - test_mins.y -= bounding_box_extra; - - test_maxs.x += bounding_box_extra; - test_maxs.y += bounding_box_extra; - - - // Calculate the real position we have to get to - if ( entnum != ENTITYNUM_NONE ) - real_pos = _getRealDestinationPosition( pos ); - else - real_pos = pos; - - Vector startPos; - startPos = act->origin; - startPos.z += 15; - - // Do simple CanWalkTo if specified - - if ( act->GetActorFlag( ACTOR_FLAG_SIMPLE_PATHFINDING ) ) - return _canMoveSimplePath( test_mins, test_maxs, real_pos ); - - // Check to make sure the ground is good each step of the move - return _checkHaveGroundEachStep( origin, real_pos, test_mins, test_maxs, mask ); - - + // Setup bounding box + auto test_mins = act->mins; + auto test_maxs = act->maxs; + + test_mins.x -= bounding_box_extra; + test_mins.y -= bounding_box_extra; + + test_maxs.x += bounding_box_extra; + test_maxs.y += bounding_box_extra; + + + // Calculate the real position we have to get to + auto real_pos = entnum != ENTITYNUM_NONE ? _getRealDestinationPosition(pos) : pos; + + // Do simple CanWalkTo if specified + + if (act->GetActorFlag(ACTOR_FLAG_SIMPLE_PATHFINDING)) + return _canMoveSimplePath(test_mins, test_maxs, real_pos); + + // Check to make sure the ground is good each step of the move + return _checkHaveGroundEachStep(origin, real_pos, test_mins, test_maxs, mask); } @@ -398,166 +359,161 @@ qboolean MovementSubsystem::CanWalkToFrom ( const Vector &origin, const Vector & // // Returns: None // -void MovementSubsystem::Accelerate( const Vector &original_steering ) +void MovementSubsystem::Accelerate(const Vector &original_steering) { - Vector steering = original_steering; - Vector newDir = _movedir.toAngles(); - - - // If we didn't move last frame ( stopped ) then we can just set our moveDir to where we - // want to go, however, if we are moving, we want to adjust our turning based on our turnspeed - // so that we can't just turn 90 degrees at a snap - - if ( !act->GetActorFlag(ACTOR_FLAG_HAVE_MOVED) ) - { - /* if ( steering.y > _turnspeed ) - steering.y = _turnspeed; - else if ( steering.y < -_turnspeed ) - steering.y = -_turnspeed; - */ - } - - if( steering.x ) - steering.x = steering.x; - - if( steering.y ) - newDir.y += steering.y; - - newDir.EulerNormalize(); - - - if ( act->animate->frame_delta.x > 4.0f ) - { - // make him lean into the turn a bit - newDir.z = _movespeed * ( 0.4f / 320.0f ) * steering.y; - - if ( ( act->flags & FlagFly ) || ( ( act->flags & FlagSwim ) && act->waterlevel > 0 ) ) - newDir.z = bound( act->angles.z, -2.0f, 2.0f ); - else - newDir.z = bound( act->angles.z, -5.0f, 5.0f ); - } - else - newDir.z = 0.0f; - - /* - if ( _movingBackwards ) - newDir[YAW] = AngleNormalize180( newDir[YAW] - 180.0f ); - */ - - newDir.AngleVectors( &_movedir ); - - //Set my turn angles; - Vector newAng = _animdir.toAngles(); - - float newDirYaw; - if ( act->bind_info && act->bind_info->bindmaster ) - { - float orientation[3][3]; - float parentOrientation[3][3]; - float mat[3][3]; - AnglesToAxis( newDir, mat ); - Vector parentAngles; - - MatrixToEulerAngles( act->bind_info->bindmaster->orientation, parentAngles ); - parentAngles[ YAW ] = AngleNormalize180( -parentAngles[ YAW ] ); - AnglesToAxis( parentAngles, parentOrientation ); - - R_ConcatRotations( mat, parentOrientation, orientation ); - MatrixToEulerAngles( orientation, newDir ); - - - AnglesToAxis( newAng, mat ); - R_ConcatRotations( mat, parentOrientation, orientation ); - MatrixToEulerAngles( orientation, newAng ); - } - - newDirYaw = AngleNormalize180(newDir.yaw() ); - float newAngYaw = AngleNormalize180(newAng.yaw() ); - - - if ( _movingBackwards ) - newDirYaw = AngleNormalize180( newDirYaw - 180.0f ); - - - float AngleDiff = newDirYaw - newAngYaw; - AngleDiff = AngleNormalize180(AngleDiff); - - //First check if we're close enough just to set our angles - if ( ( ( AngleDiff >= 0.0f ) && ( AngleDiff < _turnspeed ) ) || ( ( AngleDiff <= 0.0f ) && ( AngleDiff > -_turnspeed ) ) ) - { - newAng[YAW] = AngleNormalize360(newDirYaw); - - if ( _faceEnemy ) - { - Entity *currentEnemy; - currentEnemy = act->enemyManager->GetCurrentEnemy(); - - if ( !currentEnemy ) - { - act->enemyManager->FindHighestHateEnemy(); - currentEnemy = act->enemyManager->GetCurrentEnemy(); - } - - if ( currentEnemy ) - { - Vector selfToEnemy; - selfToEnemy = currentEnemy->origin - act->origin; - selfToEnemy = selfToEnemy.toAngles(); - selfToEnemy[PITCH] = 0.0f; - - newAng = selfToEnemy; - } - } - - if ( _adjustAnimDir ) - act->setAngles( newAng ); - return; - } - - //Update our angles - if ( AngleDiff > 0.0f ) - newAng[YAW] = AngleNormalize360( newAng[YAW] += _turnspeed ); - else - newAng[YAW] = AngleNormalize360( newAng[YAW] -= _turnspeed ); - - - - /* - if ( _fliplegs ) - newAng[YAW] += 180; - */ - - - - if ( _movingBackwards ) - newAng[YAW] = AngleNormalize180( newDir[YAW] - 180.0f ); - - - if ( _faceEnemy ) - { - Entity *currentEnemy; - currentEnemy = act->enemyManager->GetCurrentEnemy(); - - if ( !currentEnemy ) - { - act->enemyManager->FindHighestHateEnemy(); - currentEnemy = act->enemyManager->GetCurrentEnemy(); - } - - if ( currentEnemy ) - { - Vector selfToEnemy; - selfToEnemy = currentEnemy->origin - act->origin; - selfToEnemy = selfToEnemy.toAngles(); - selfToEnemy[PITCH] = 0.0f; - - newAng = selfToEnemy; - } - } - - if ( _adjustAnimDir ) - act->setAngles( newAng ); - + auto steering = original_steering; + auto newDir = _movedir.toAngles(); + + + // If we didn't move last frame ( stopped ) then we can just set our moveDir to where we + // want to go, however, if we are moving, we want to adjust our turning based on our turnspeed + // so that we can't just turn 90 degrees at a snap + + if (!act->GetActorFlag(ACTOR_FLAG_HAVE_MOVED)) + { + /* if ( steering.y > _turnspeed ) + steering.y = _turnspeed; + else if ( steering.y < -_turnspeed ) + steering.y = -_turnspeed; + */ + } + + if (steering.x) + steering.x = steering.x; + + if (steering.y) + newDir.y += steering.y; + + newDir.EulerNormalize(); + + + if (act->animate->frame_delta.x > 4.0f) + { + // make him lean into the turn a bit + newDir.z = _movespeed * (0.4f / 320.0f) * steering.y; + + if (act->flags & FlagFly || act->flags & FlagSwim && act->waterlevel > 0) + newDir.z = bound(act->angles.z, -2.0f, 2.0f); + else + newDir.z = bound(act->angles.z, -5.0f, 5.0f); + } else + newDir.z = 0.0f; + + /* + if ( _movingBackwards ) + newDir[YAW] = AngleNormalize180( newDir[YAW] - 180.0f ); + */ + + newDir.AngleVectors(&_movedir); + + //Set my turn angles; + auto newAng = _animdir.toAngles(); + + if (act->bind_info && act->bind_info->bindmaster) + { + float orientation[3][3]; + float parentOrientation[3][3]; + float mat[3][3]; + AnglesToAxis(newDir, mat); + Vector parentAngles; + + MatrixToEulerAngles(act->bind_info->bindmaster->orientation, parentAngles); + parentAngles[YAW] = AngleNormalize180(-parentAngles[YAW]); + AnglesToAxis(parentAngles, parentOrientation); + + R_ConcatRotations(mat, parentOrientation, orientation); + MatrixToEulerAngles(orientation, newDir); + + + AnglesToAxis(newAng, mat); + R_ConcatRotations(mat, parentOrientation, orientation); + MatrixToEulerAngles(orientation, newAng); + } + + auto newDirYaw = AngleNormalize180(newDir.yaw()); + auto newAngYaw = AngleNormalize180(newAng.yaw()); + + + if (_movingBackwards) + newDirYaw = AngleNormalize180(newDirYaw - 180.0f); + + + auto AngleDiff = AngleNormalize180(newDirYaw - newAngYaw); + + //First check if we're close enough just to set our angles + if (AngleDiff >= 0.0f && AngleDiff < _turnspeed || AngleDiff <= 0.0f && AngleDiff > -_turnspeed) + { + newAng[YAW] = AngleNormalize360(newDirYaw); + + if (_faceEnemy) + { + Entity *currentEnemy; + currentEnemy = act->enemyManager->GetCurrentEnemy(); + + if (!currentEnemy) + { + act->enemyManager->FindHighestHateEnemy(); + currentEnemy = act->enemyManager->GetCurrentEnemy(); + } + + if (currentEnemy) + { + Vector selfToEnemy; + selfToEnemy = currentEnemy->origin - act->origin; + selfToEnemy = selfToEnemy.toAngles(); + selfToEnemy[PITCH] = 0.0f; + + newAng = selfToEnemy; + } + } + + if (_adjustAnimDir) + act->setAngles(newAng); + return; + } + + //Update our angles + if (AngleDiff > 0.0f) + newAng[YAW] = AngleNormalize360(newAng[YAW] += _turnspeed); + else + newAng[YAW] = AngleNormalize360(newAng[YAW] -= _turnspeed); + + + + /* + if ( _fliplegs ) + newAng[YAW] += 180; + */ + + + + if (_movingBackwards) + newAng[YAW] = AngleNormalize180(newDir[YAW] - 180.0f); + + + if (_faceEnemy) + { + Entity* currentEnemy = act->enemyManager->GetCurrentEnemy(); + + if (!currentEnemy) + { + act->enemyManager->FindHighestHateEnemy(); + currentEnemy = act->enemyManager->GetCurrentEnemy(); + } + + if (currentEnemy) + { + auto selfToEnemy = currentEnemy->origin - act->origin; + selfToEnemy = selfToEnemy.toAngles(); + selfToEnemy[PITCH] = 0.0f; + + newAng = selfToEnemy; + } + } + + if (_adjustAnimDir) + act->setAngles(newAng); + } //-------------------------------------------------------------- @@ -570,41 +526,40 @@ void MovementSubsystem::Accelerate( const Vector &original_steering ) // // Returns: None //-------------------------------------------------------------- -void MovementSubsystem::CalcMove ( void ) +void MovementSubsystem::CalcMove(void) { - - // Use total_delta from the animation if we can, but - // over-ride it if we set a forward speed ( When the - // new animation stuff is availiable ) - _totallen = 0; - - if ( act->total_delta != vec_zero ) - _totallen = act->total_delta.length(); - - if ( _forwardspeed ) - { - _totallen = _forwardspeed; - } - - if ( _movementType == MOVEMENT_TYPE_ANIM ) - { - MatrixTransformVector( act->total_delta, act->orientation, _move ); - } - else - { - _movedir.normalize(); - _move = _movedir; - _move *= _totallen; - } - - // If we are not allowed to move, make sure we set the length of our - // movement vector to 0.0 - if ( act->movetype == MOVETYPE_NONE ) - _move *= 0.0f; - - act->total_delta = vec_zero; - _animdir = act->orientation[0]; - + + // Use total_delta from the animation if we can, but + // over-ride it if we set a forward speed ( When the + // new animation stuff is available ) + _totallen = 0; + + if (act->total_delta != vec_zero) + _totallen = act->total_delta.length(); + + if (_forwardspeed) + { + _totallen = _forwardspeed; + } + + if (_movementType == MOVEMENT_TYPE_ANIM) + { + MatrixTransformVector(act->total_delta, act->orientation, _move); + } else + { + _movedir.normalize(); + _move = _movedir; + _move *= _totallen; + } + + // If we are not allowed to move, make sure we set the length of our + // movement vector to 0.0 + if (act->movetype == MOVETYPE_NONE) + _move *= 0.0f; + + act->total_delta = vec_zero; + _animdir = act->orientation[0]; + } @@ -618,41 +573,36 @@ void MovementSubsystem::CalcMove ( void ) // // Returns: stepmoveresult_t // -stepmoveresult_t MovementSubsystem::WaterMove ( void ) +stepmoveresult_t MovementSubsystem::WaterMove(void) { - Vector oldorg; - Vector neworg; - trace_t trace; - int oldwater; - - if ( ( _totallen <= 0.01f ) || ( _move == vec_zero ) ) - { - return STEPMOVE_OK; - } - - // try the move - oldorg = act->origin; - neworg = act->origin + _move; - - trace = G_Trace( oldorg, act->mins, act->maxs, neworg, act, act->edict->clipmask, false, "Actor::WaterMove 1" ); - if ( trace.fraction == 0.0f ) - return STEPMOVE_STUCK; - - oldwater = act->waterlevel; - - act->setOrigin( trace.endpos ); - - CheckWater(); - - // swim monsters don't exit water voluntarily - if ( ( oldwater > 1 ) && ( act->waterlevel < 2 ) ) - { - act->waterlevel = oldwater; - act->setOrigin( oldorg ); - return STEPMOVE_STUCK; - } - - return STEPMOVE_OK; + if (_totallen <= 0.01f || _move == vec_zero) + { + return STEPMOVE_OK; + } + + // try the move + auto oldorg = act->origin; + auto neworg = act->origin + _move; + + auto trace = G_Trace(oldorg, act->mins, act->maxs, neworg, act, act->edict->clipmask, false, "Actor::WaterMove 1"); + if (trace.fraction == 0.0f) + return STEPMOVE_STUCK; + + auto oldwater = act->waterlevel; + + act->setOrigin(trace.endpos); + + CheckWater(); + + // swim monsters don't exit water voluntarily + if (oldwater > 1 && act->waterlevel < 2) + { + act->waterlevel = oldwater; + act->setOrigin(oldorg); + return STEPMOVE_STUCK; + } + + return STEPMOVE_OK; } @@ -666,46 +616,41 @@ stepmoveresult_t MovementSubsystem::WaterMove ( void ) // // Returns: stepmoveresult_t // -stepmoveresult_t MovementSubsystem::AirMove ( void ) +stepmoveresult_t MovementSubsystem::AirMove(void) { - Vector oldorg; - Vector neworg; - trace_t trace; - int oldwater; - - if ( ( _totallen <= 0.01f ) || ( _move == vec_zero ) ) - { - return STEPMOVE_OK; - } - - // try the move - oldorg = act->origin; - neworg = act->origin + _move; - - trace = G_Trace( oldorg, act->mins, act->maxs, neworg, act, act->edict->clipmask, false, "Actor::AirMove 1" ); - if ( trace.fraction < 0.0001f ) - { - return STEPMOVE_BLOCKED_BY_WATER; - } - - oldwater = act->waterlevel; - - act->setOrigin( trace.endpos ); - - if ( !act->GetActorFlag( ACTOR_FLAG_IGNORE_WATER ) ) - { - CheckWater(); - - // fly monsters don't enter water voluntarily - if ( !oldwater && act->waterlevel ) - { - act->waterlevel = oldwater; - act->setOrigin( oldorg ); - return STEPMOVE_STUCK; - } - } - - return STEPMOVE_OK; + if (_totallen <= 0.01f || _move == vec_zero) + { + return STEPMOVE_OK; + } + + // try the move + auto oldorg = act->origin; + auto neworg = act->origin + _move; + + auto trace = G_Trace(oldorg, act->mins, act->maxs, neworg, act, act->edict->clipmask, false, "Actor::AirMove 1"); + if (trace.fraction < 0.0001f) + { + return STEPMOVE_BLOCKED_BY_WATER; + } + + auto oldwater = act->waterlevel; + + act->setOrigin(trace.endpos); + + if (!act->GetActorFlag(ACTOR_FLAG_IGNORE_WATER)) + { + CheckWater(); + + // fly monsters don't enter water voluntarily + if (!oldwater && act->waterlevel) + { + act->waterlevel = oldwater; + act->setOrigin(oldorg); + return STEPMOVE_STUCK; + } + } + + return STEPMOVE_OK; } @@ -719,77 +664,76 @@ stepmoveresult_t MovementSubsystem::AirMove ( void ) // // Returns: stepmoveresult_t // -stepmoveresult_t MovementSubsystem::IsMoveValid( trace_t &horizontalTrace, trace_t &verticalTrace, const Vector &moveBegin, const Vector &moveEnd ) +stepmoveresult_t MovementSubsystem::IsMoveValid(trace_t &horizontalTrace, trace_t &verticalTrace, const Vector &moveBegin, const Vector &moveEnd) { - horizontalTrace = act->Trace( moveBegin, moveEnd, "MovementSubsystem::IsMoveValid" ); - - if ( horizontalTrace.startsolid ) - { - horizontalTrace = G_Trace( moveBegin, act->mins, act->maxs, moveBegin + _move, act, act->edict->clipmask, false, "MovementSubsystem::IsMoveValid2" ); - } - - if ( horizontalTrace.startsolid || ( horizontalTrace.fraction < 0.0001f ) ) - return STEPMOVE_STUCK; - - // See if we are blocked by a door - if ( _isBlockedByDoor(horizontalTrace) ) - return STEPMOVE_BLOCKED_BY_DOOR; - - // Don't step down an extra step if gravity is turned off for this actor right now or the actor is dead - if ( !act->GetActorFlag( ACTOR_FLAG_USE_GRAVITY ) || (act->gravity == 0) || act->deadflag ) - { - return _noGravityTryMove( horizontalTrace.endpos, verticalTrace ); - } - - stepmoveresult_t result = STEPMOVE_OK; - if ( horizontalTrace.fraction < 1.0f ) - { - if ( horizontalTrace.entityNum == ENTITYNUM_WORLD ) - { - result = STEPMOVE_BLOCKED_BY_WORLD; - } - else - { - result = STEPMOVE_BLOCKED_BY_ENTITY; - _blockingEntity = horizontalTrace.ent->entity; - //if ( _blockingEntity->isSubclassOf( Player ) ) - // act->InContext( "blockedbyplayer" ); - - act->AddStateFlag(STATE_FLAG_BLOCKED_BY_ENTITY); - } - } - - // Phase 2: Send a trace down from the end of the first trace to try and found ground -- and thus - // what should be our new origin - Vector traceBegin( horizontalTrace.endpos ); - Vector traceEnd( traceBegin - ( _step * 2.0f ) ); - - verticalTrace = G_Trace( traceBegin, act->mins, act->maxs, traceEnd, act, act->edict->clipmask, false, "MovementSubsystem::IsMoveValid3" ); - // Check if we are blocked by a fall - if ( _isBlockedByFall( verticalTrace ) ) - return STEPMOVE_BLOCKED_BY_FALL; - - - // If the feet width is set make sure the actor's feet are really on the ground - if ( act->feet_width ) - { - verticalTrace = _feetWidthTrace( verticalTrace.endpos , verticalTrace.endpos - ( _step * 3.0f ) , verticalTrace.endpos, act->edict->clipmask ); - - // Check if we are blocked by a fall - if ( _isBlockedByFall( verticalTrace ) ) - return STEPMOVE_BLOCKED_BY_FALL; - - } - - /* Experiment to deal with uneven floor geometry - if ( result == STEPMOVE_OK ) - { - if ( !_checkHaveGroundEachStep ( moveBegin , moveEnd , act->mins , act->maxs )) - return STEPMOVE_BLOCKED_BY_FALL; - } - */ - - return result; + horizontalTrace = act->Trace(moveBegin, moveEnd, "MovementSubsystem::IsMoveValid"); + + if (horizontalTrace.startsolid) + { + horizontalTrace = G_Trace(moveBegin, act->mins, act->maxs, moveBegin + _move, act, act->edict->clipmask, false, "MovementSubsystem::IsMoveValid2"); + } + + if (horizontalTrace.startsolid || horizontalTrace.fraction < 0.0001f) + return STEPMOVE_STUCK; + + // See if we are blocked by a door + if (_isBlockedByDoor(horizontalTrace)) + return STEPMOVE_BLOCKED_BY_DOOR; + + // Don't step down an extra step if gravity is turned off for this actor right now or the actor is dead + if (!act->GetActorFlag(ACTOR_FLAG_USE_GRAVITY) || act->gravity == 0 || act->deadflag) + { + return _noGravityTryMove(horizontalTrace.endpos, verticalTrace); + } + + auto result = STEPMOVE_OK; + if (horizontalTrace.fraction < 1.0f) + { + if (horizontalTrace.entityNum == ENTITYNUM_WORLD) + { + result = STEPMOVE_BLOCKED_BY_WORLD; + } else + { + result = STEPMOVE_BLOCKED_BY_ENTITY; + _blockingEntity = horizontalTrace.ent->entity; + //if ( _blockingEntity->isSubclassOf( Player ) ) + // act->InContext( "blockedbyplayer" ); + + act->AddStateFlag(StateFlagBlockedByEntity); + } + } + + // Phase 2: Send a trace down from the end of the first trace to try and found ground -- and thus + // what should be our new origin + Vector traceBegin(horizontalTrace.endpos); + auto traceEnd(traceBegin - _step * 2.0f); + + verticalTrace = G_Trace(traceBegin, act->mins, act->maxs, traceEnd, act, act->edict->clipmask, false, "MovementSubsystem::IsMoveValid3"); + // Check if we are blocked by a fall + if (_isBlockedByFall(verticalTrace)) + return STEPMOVE_BLOCKED_BY_FALL; + + + // If the feet width is set make sure the actor's feet are really on the ground + if (act->feet_width) + { + verticalTrace = _feetWidthTrace(verticalTrace.endpos, verticalTrace.endpos - _step * 3.0f, verticalTrace.endpos, act->edict->clipmask); + + // Check if we are blocked by a fall + if (_isBlockedByFall(verticalTrace)) + return STEPMOVE_BLOCKED_BY_FALL; + + } + + /* Experiment to deal with uneven floor geometry + if ( result == STEPMOVE_OK ) + { + if ( !_checkHaveGroundEachStep ( moveBegin , moveEnd , act->mins , act->maxs )) + return STEPMOVE_BLOCKED_BY_FALL; + } + */ + + return result; } // // Name: TryMove() @@ -801,40 +745,39 @@ stepmoveresult_t MovementSubsystem::IsMoveValid( trace_t &horizontalTrace, trace // // Returns: stepmoveresult_t // -stepmoveresult_t MovementSubsystem::TryMove ( void ) +stepmoveresult_t MovementSubsystem::TryMove(void) { - - // See if we should bother doing any movement - if ( !_shouldTryMove() ) - return STEPMOVE_OK; - - - // Phase 1: Send a trace out from our origin ( plus stepsize ) along our move Vector. - Vector moveBegin = act->origin; - - trace_t horizontalTrace; - trace_t verticalTrace; - verticalTrace.ent = 0 ; - stepmoveresult_t returnValue = IsMoveValid( horizontalTrace, verticalTrace, moveBegin, moveBegin + _move ); - if ( returnValue == STEPMOVE_OK ) - { - // The move is ok - act->setOrigin( verticalTrace.endpos ); - - // Save the ground information now so we don't have to do it later - if ( verticalTrace.fraction < 1.0f ) - _saveGroundInformation( verticalTrace ); - - - act->flags &= ~FlagPartialground; // set in ActorThink - CheckWater(); - - } - else if ( returnValue == STEPMOVE_BLOCKED_BY_FALL ) - { - act->AddStateFlag( STATE_FLAG_STUCK ); - } - return returnValue; + + // See if we should bother doing any movement + if (!_shouldTryMove()) + return STEPMOVE_OK; + + + // Phase 1: Send a trace out from our origin ( plus stepsize ) along our move Vector. + auto moveBegin = act->origin; + + trace_t horizontalTrace; + trace_t verticalTrace; + verticalTrace.ent = nullptr; + auto returnValue = IsMoveValid(horizontalTrace, verticalTrace, moveBegin, moveBegin + _move); + if (returnValue == STEPMOVE_OK) + { + // The move is ok + act->setOrigin(verticalTrace.endpos); + + // Save the ground information now so we don't have to do it later + if (verticalTrace.fraction < 1.0f) + _saveGroundInformation(verticalTrace); + + + act->flags &= ~FlagPartialground; // set in ActorThink + CheckWater(); + + } else if (returnValue == STEPMOVE_BLOCKED_BY_FALL) + { + act->AddStateFlag(StateFlagStuck); + } + return returnValue; } @@ -848,19 +791,19 @@ stepmoveresult_t MovementSubsystem::TryMove ( void ) // // Returns: stepmoveresult_t // -stepmoveresult_t MovementSubsystem::SimpleMove( const bool stickToGround ) +stepmoveresult_t MovementSubsystem::SimpleMove(const bool stickToGround) { - Vector newPosition ( act->origin + _move ); - if ( stickToGround ) - { - Vector traceBegin( newPosition + _step ); - Vector traceEnd( traceBegin - ( _step * 2.0f ) ); - - trace_t trace = G_Trace( traceBegin, act->mins, act->maxs, traceEnd, act, MASK_PATHSOLID, false, "MovementSubsystem::SimpleMove" ); - newPosition = trace.endpos; - } - act->setOrigin( newPosition ); - return STEPMOVE_OK; + auto newPosition(act->origin + _move); + if (stickToGround) + { + auto traceBegin(newPosition + _step); + auto traceEnd(traceBegin - _step * 2.0f); + + auto trace = G_Trace(traceBegin, act->mins, act->maxs, traceEnd, act, MASK_PATHSOLID, false, "MovementSubsystem::SimpleMove"); + newPosition = trace.endpos; + } + act->setOrigin(newPosition); + return STEPMOVE_OK; } @@ -874,62 +817,57 @@ stepmoveresult_t MovementSubsystem::SimpleMove( const bool stickToGround ) // // Returns: True or False // -qboolean MovementSubsystem::Push ( const Vector &dir ) +qboolean MovementSubsystem::Push(const Vector &dir) { - Vector oldorg; - Vector neworg; - trace_t trace; - int i; - - - if ( !act->GetActorFlag( ACTOR_FLAG_PUSHABLE ) ) - return false; - - for( i = 0 ; i < 5 ; i++ ) - { - oldorg = act->origin + _step; - neworg = oldorg + dir; - - trace = G_Trace( oldorg, act->mins, act->maxs, neworg, act, act->edict->clipmask, false, "Actor::Push 1" ); - - if ( trace.startsolid ) - { - oldorg = act->origin; - neworg = oldorg + dir; - - trace = G_Trace( oldorg, act->mins, act->maxs, neworg, act, act->edict->clipmask, false, "Actor::Push 2" ); - - if ( trace.startsolid ) - return false; - } - - if ( trace.ent && trace.ent->entity->isSubclassOf( Actor ) ) - { - Actor *actor = (Actor *) trace.ent->entity; - actor->Push( dir ); - continue; - } - else - break; - } - - if ( trace.endpos == oldorg ) - return false; - - // Step down to a step height below our original height to account for gravity - - oldorg = trace.endpos; - - if ( act->flags & FlagFly ) - neworg = oldorg - _step; - else - neworg = oldorg - _step * 2.0f; - - trace = G_Trace( oldorg, act->mins, act->maxs, neworg, act, act->edict->clipmask, false, "Actor::Push 3" ); - - act->setOrigin( trace.endpos ); - - return true; + Vector oldorg; + Vector neworg; + trace_t trace; + + + if (!act->GetActorFlag(ACTOR_FLAG_PUSHABLE)) + return false; + + for (auto i = 0; i < 5; i++) + { + oldorg = act->origin + _step; + neworg = oldorg + dir; + + trace = G_Trace(oldorg, act->mins, act->maxs, neworg, act, act->edict->clipmask, false, "Actor::Push 1"); + + if (trace.startsolid) + { + oldorg = act->origin; + neworg = oldorg + dir; + + trace = G_Trace(oldorg, act->mins, act->maxs, neworg, act, act->edict->clipmask, false, "Actor::Push 2"); + + if (trace.startsolid) + return false; + } + + if (trace.ent && trace.ent->entity->isSubclassOf(Actor)) + { + auto actor = dynamic_cast(trace.ent->entity); + actor->Push(dir); + continue; + } + + break; + } + + if (trace.endpos == oldorg) + return false; + + // Step down to a step height below our original height to account for gravity + + oldorg = trace.endpos; + neworg = act->flags & FlagFly ? oldorg - _step : oldorg - _step * 2.0f; + + trace = G_Trace(oldorg, act->mins, act->maxs, neworg, act, act->edict->clipmask, false, "Actor::Push 3"); + + act->setOrigin(trace.endpos); + + return true; } @@ -947,41 +885,38 @@ qboolean MovementSubsystem::Push ( const Vector &dir ) // // Returns: None // -void MovementSubsystem::CheckWater( void ) +void MovementSubsystem::CheckWater(void) { - Vector sample[3]; - int cont; - - // - // get waterlevel and type - // - act->waterlevel = 0; - act->watertype = 0; - - sample[ 0 ] = act->origin; - sample[ 2 ] = act->EyePosition(); - sample[ 1 ] = ( sample[ 0 ] + sample[ 2 ] ) * 0.5f; - - cont = gi.pointcontents( sample[ 0 ], 0 ); - - if ( ( cont != -1 ) && ( cont & MASK_WATER ) ) - { - act->watertype = cont; - act->waterlevel = 1; - cont = gi.pointcontents( sample[ 2 ], 0 ); - if (cont & MASK_WATER) - { - act->waterlevel = 3; - } - else - { - cont = gi.pointcontents( sample[ 1 ], 0 ); - if (cont & MASK_WATER) - { - act->waterlevel = 2; - } - } - } + // + // get waterlevel and type + // + act->waterlevel = 0; + act->watertype = 0; + + Vector sample[3]; + sample[0] = act->origin; + sample[2] = act->EyePosition(); + sample[1] = (sample[0] + sample[2]) * 0.5f; + + auto cont = gi.pointcontents(sample[0], 0); + + if (cont != -1 && cont & MASK_WATER) + { + act->watertype = cont; + act->waterlevel = 1; + cont = gi.pointcontents(sample[2], 0); + if (cont & MASK_WATER) + { + act->waterlevel = 3; + } else + { + cont = gi.pointcontents(sample[1], 0); + if (cont & MASK_WATER) + { + act->waterlevel = 2; + } + } + } } @@ -997,18 +932,18 @@ void MovementSubsystem::CheckWater( void ) // // Returns: float traveltime // -float MovementSubsystem::JumpTo( const Vector &targetPosition, const Angle angle ) +float MovementSubsystem::JumpTo(const Vector &targetPosition, const Angle angle) { - Trajectory trajectory( act->origin, targetPosition, angle, act->gravity * -sv_currentGravity->value ); - act->velocity = trajectory.GetInitialVelocity(); - - Vector directionXY( targetPosition - act->origin ); - directionXY.z = 0.0f; - act->setAngles( directionXY.toAngles() ); - _movedir = directionXY; - - act->groundentity = NULL; - return trajectory.GetTravelTime(); + Trajectory trajectory(act->origin, targetPosition, angle, act->gravity * -sv_currentGravity->value); + act->velocity = trajectory.GetInitialVelocity(); + + auto directionXY(targetPosition - act->origin); + directionXY.z = 0.0f; + act->setAngles(directionXY.toAngles()); + _movedir = directionXY; + + act->groundentity = nullptr; + return trajectory.GetTravelTime(); } @@ -1024,14 +959,13 @@ float MovementSubsystem::JumpTo( const Vector &targetPosition, const Angle angle // // Returns: float JumpTo result // -float MovementSubsystem::JumpTo ( PathNode *goal, const Angle angle ) +float MovementSubsystem::JumpTo(PathNode *goal, const Angle angle) { - if ( goal ) - return JumpTo( goal->origin, angle ); - else - return 0; -} + if (goal) + return JumpTo(goal->origin, angle); + return 0; +} // @@ -1046,12 +980,12 @@ float MovementSubsystem::JumpTo ( PathNode *goal, const Angle angle ) // // Returns: float JumpTo result // -float MovementSubsystem::JumpTo ( Entity *goal, const Angle angle ) +float MovementSubsystem::JumpTo(Entity *goal, const Angle angle) { - if ( goal ) - return JumpTo( goal->origin, angle ); - else - return 0; + if (goal) + return JumpTo(goal->origin, angle); + + return 0; } // @@ -1079,37 +1013,38 @@ float MovementSubsystem::JumpTo ( Entity *goal, const Angle angle ) // // // -const Vector MovementSubsystem::SteerTowardsPoint( const Vector &targetPosition, const Vector &targetVelocity, const Vector &moveDirection, const float maxSpeed, const bool adjustSpeed) +Vector MovementSubsystem::SteerTowardsPoint(const Vector &targetPosition, const Vector &targetVelocity, const Vector &moveDirection, const float maxSpeed, const bool adjustSpeed) { - assert(act != NULL); - Vector myPosition (act->origin); - Vector predictedPosition = targetPosition + targetVelocity * ( Vector::Distance(targetPosition, myPosition) / maxSpeed ); - Vector desiredDirection = predictedPosition - myPosition; - - Vector newSteeringForce = Vector::AnglesBetween(desiredDirection, moveDirection); - newSteeringForce[ROLL]=0.0f; - newSteeringForce.EulerNormalize(); - - if ( adjustSpeed ) - { - const float currentSpeed = _forwardspeed; - const float turnRate = _turnspeed; - const float turnRadius = currentSpeed / turnRate; - - Vector right; - right.CrossProduct( moveDirection, Vector( 0, 0, 1 ) ); - const Vector centerOfTurn( myPosition + ( right * DotProduct( right, desiredDirection ) ) ); - - const float forwardComponent = DotProduct( desiredDirection, moveDirection ); - const float rightComponent = DotProduct( desiredDirection, right ); - - if ( Vector::DistanceXY( centerOfTurn, predictedPosition ) < turnRadius ) - { - const float newTurnRadius = ( ( rightComponent * rightComponent ) + ( forwardComponent * forwardComponent ) ) / ( 2.0f * rightComponent ); - _forwardspeed = 2.0f * turnRate * newTurnRadius; - } - } - return newSteeringForce; + assert(act != NULL); + auto myPosition(act->origin); + auto predictedPosition = targetPosition + targetVelocity * (Vector::Distance(targetPosition, myPosition) / maxSpeed); + auto desiredDirection = predictedPosition - myPosition; + + auto newSteeringForce = Vector::AnglesBetween(desiredDirection, moveDirection); + newSteeringForce[ROLL] = 0.0f; + newSteeringForce.EulerNormalize(); + + if (adjustSpeed) + { + auto currentSpeed = _forwardspeed; + auto turnRate = _turnspeed; + auto turnRadius = currentSpeed / turnRate; + + Vector right; + right.CrossProduct(moveDirection, Vector(0, 0, 1)); + auto centerOfTurn(myPosition + right * DotProduct(right, desiredDirection)); + + auto forwardComponent = DotProduct(desiredDirection, moveDirection); + auto rightComponent = DotProduct(desiredDirection, right); + + if (Vector::DistanceXY(centerOfTurn, predictedPosition) < turnRadius) + { + auto newTurnRadius = (rightComponent * rightComponent + forwardComponent * forwardComponent) / (2.0f * rightComponent); + _forwardspeed = 2.0f * turnRate * newTurnRadius; + } + } + + return newSteeringForce; } // @@ -1124,15 +1059,15 @@ const Vector MovementSubsystem::SteerTowardsPoint( const Vector &targetPosition, // // Returns: True or False // -qboolean MovementSubsystem::_canMoveSimplePath( const Vector &mins, const Vector &maxs , const Vector &pos ) const +qboolean MovementSubsystem::_canMoveSimplePath(const Vector &mins, const Vector &maxs, const Vector &pos) const { - Q_UNUSED(maxs); Q_UNUSED(mins); + Q_UNUSED(maxs); Q_UNUSED(mins); - trace_t trace = act->Trace( act->origin + _step, pos + _step, "Actor::_canMoveSimplePath" ); - if ( trace.fraction == 1.0f ) - return true; - - return false; + auto trace = act->Trace(act->origin + _step, pos + _step, "Actor::_canMoveSimplePath"); + if (trace.fraction == 1.0f) + return true; + + return false; } @@ -1146,20 +1081,20 @@ qboolean MovementSubsystem::_canMoveSimplePath( const Vector &mins, const Vector // // Returns: Vector target destination // -Vector MovementSubsystem::_getRealDestinationPosition( const Vector &pos ) const +Vector MovementSubsystem::_getRealDestinationPosition(const Vector &pos) const { - Vector temp_dir = pos - act->origin; - float temp_length = temp_dir.length(); - - temp_length -= sqrt( act->maxs.x * act->maxs.x * 2.0f ) + 5.0f; - - if ( temp_length < 0.0f ) - temp_length = 0.0f; - - temp_dir.normalize(); - temp_dir *= temp_length; - - return act->origin + temp_dir; + auto temp_dir = pos - act->origin; + auto temp_length = temp_dir.length(); + + temp_length -= sqrt(act->maxs.x * act->maxs.x * 2.0f) + 5.0f; + + if (temp_length < 0.0f) + temp_length = 0.0f; + + temp_dir.normalize(); + temp_dir *= temp_length; + + return act->origin + temp_dir; } @@ -1176,27 +1111,25 @@ Vector MovementSubsystem::_getRealDestinationPosition( const Vector &pos ) const // // Returns: trace_t trace // -trace_t MovementSubsystem::_feetWidthTrace( const Vector ¤tLoc, const Vector &bottom, const Vector &endPos, const int mask ) const +trace_t MovementSubsystem::_feetWidthTrace(const Vector ¤tLoc, const Vector &bottom, const Vector &endPos, const int mask) const { - trace_t trace; - Vector temp_mins; - Vector temp_maxs; - Vector saved_endpos; - - temp_mins[0] = -act->feet_width; - temp_mins[1] = -act->feet_width; - temp_mins[2] = act->mins[2]; - - temp_maxs[0] = act->feet_width; - temp_maxs[1] = act->feet_width; - temp_maxs[2] = act->maxs[2]; - - trace = G_Trace( currentLoc, temp_mins, temp_maxs, bottom, act, mask, false, "Actor::CanWalkTo2" ); - - saved_endpos = endPos; - saved_endpos.copyTo( trace.endpos ); - - return trace; + Vector temp_mins; + Vector temp_maxs; + + temp_mins[0] = -act->feet_width; + temp_mins[1] = -act->feet_width; + temp_mins[2] = act->mins[2]; + + temp_maxs[0] = act->feet_width; + temp_maxs[1] = act->feet_width; + temp_maxs[2] = act->maxs[2]; + + auto trace = G_Trace(currentLoc, temp_mins, temp_maxs, bottom, act, mask, false, "Actor::CanWalkTo2"); + + auto saved_endpos = endPos; + saved_endpos.copyTo(trace.endpos); + + return trace; } @@ -1212,16 +1145,16 @@ trace_t MovementSubsystem::_feetWidthTrace( const Vector ¤tLoc, const Vect // float MovementSubsystem::_getTraceStep() const { - // Find the step amount - float trace_step = act->maxs[0] * 2.0f; //was 2.0 - - // Make sure trace_step is divisible by 8 - trace_step = ( (int)(trace_step / 8.0f ) ) * 8.0f; - - if ( trace_step < 8.0f ) - trace_step = 8.0f; - - return trace_step; + // Find the step amount + auto trace_step = act->maxs[0] * 2.0f; //was 2.0 + + // Make sure trace_step is divisible by 8 + trace_step = int(trace_step / 8.0f) * 8.0f; + + if (trace_step < 8.0f) + trace_step = 8.0f; + + return trace_step; } @@ -1239,80 +1172,83 @@ float MovementSubsystem::_getTraceStep() const // // Returns: True or False // -qboolean MovementSubsystem::_checkHaveGroundEachStep( const Vector &start, const Vector &end, const Vector &test_mins, const Vector &test_maxs, const int mask ) const +qboolean MovementSubsystem::_checkHaveGroundEachStep(const Vector &start, const Vector &end, const Vector &test_mins, const Vector &test_maxs, const int mask) const { - int clipMask = act->edict->clipmask; - if ( mask >= 0 ) - { - clipMask = mask; - } - - // Find the vector to walk - Vector dir = end - start; - float length = dir.length(); - dir.normalize(); - - // Get Trace Steps; - float trace_step = _getTraceStep(); - float small_trace_step = 8; - - // Test each step to see if the ground is not too far below - float last_height = end[2]; - - Vector last_loc = Vector::Identity(); - // Vector last_loc = start; - for( float i = 0 ; i < length ; i += trace_step ) - { - Vector current_loc = start + ( dir * i ); - current_loc[2] = last_height + STEPSIZE; - - Vector bottom = current_loc; - - if ( !act->GetActorFlag( ACTOR_FLAG_ALLOW_FALL ) ) - bottom[2] = last_height - STEPSIZE; - else - bottom[2] = last_height - 1000.0f; - - trace_t trace = G_Trace( current_loc, test_mins, test_maxs, bottom, act, clipMask, false, "Actor::CanWalkTo1" ); - - if ( !( ( trace.fraction == 1.0f ) || trace.startsolid || trace.allsolid ) && act->feet_width ) - trace = _feetWidthTrace( current_loc , bottom , trace.endpos, clipMask ); - - if ( ( trace.fraction == 1.0f ) || trace.startsolid || trace.allsolid ) - { - // The wide one failed, do the small traces for this segment - if ( ( i == 0 ) || ( trace_step == small_trace_step ) ) - return false; - - for( float j = small_trace_step ; j <= trace_step ; j += small_trace_step ) - { - current_loc = last_loc + ( dir * j ); - current_loc[2] = last_height + STEPSIZE; - - bottom = current_loc; - bottom[2] = last_height - STEPSIZE; - - trace = G_Trace( current_loc, test_mins, test_maxs, bottom, act, clipMask, false, "Actor::CanWalkTo3" ); - - if ( ( trace.fraction == 1.0f ) || trace.startsolid || trace.allsolid || - ( trace.ent && trace.ent->entity->isSubclassOf( Sentient ) && !act->GetActorFlag( ACTOR_FLAG_CAN_WALK_ON_OTHERS ) ) ) - return false; - - if ( act->feet_width ) - trace = _feetWidthTrace( current_loc , bottom , trace.endpos, clipMask ); - - last_height = trace.endpos[2]; - } - } - - last_height = trace.endpos[2]; - last_loc = current_loc; - } - - if ( ( last_height > ( end.z + ( STEPSIZE * 2.0f ) ) ) || ( last_height < ( end.z - ( STEPSIZE * 2.0f ) ) ) ) - return false; - - return true; + auto clipMask = act->edict->clipmask; + if (mask >= 0) + { + clipMask = mask; + } + + // Find the vector to walk + auto dir = end - start; + auto length = dir.length(); + dir.normalize(); + + // Get Trace Steps; + auto trace_step = _getTraceStep(); + auto small_trace_step = 8.0f; + + // Test each step to see if the ground is not too far below + auto last_height = end[2]; + + auto last_loc = Vector::Identity(); + // Vector last_loc = start + Vector current_loc; + Vector bottom; + trace_t trace; + for (auto i = 0.0f; i < length; i += trace_step) + { + current_loc = start + dir * i; + current_loc[2] = last_height + STEPSIZE; + + bottom = current_loc; + + if (!act->GetActorFlag(ACTOR_FLAG_ALLOW_FALL)) + bottom[2] = last_height - STEPSIZE; + else + bottom[2] = last_height - 1000.0f; + + trace = G_Trace(current_loc, test_mins, test_maxs, bottom, act, clipMask, false, "Actor::CanWalkTo1"); + + if (!(trace.fraction == 1.0f || trace.startsolid || trace.allsolid) && act->feet_width) + trace = _feetWidthTrace(current_loc, bottom, trace.endpos, clipMask); + + if (trace.fraction == 1.0f || trace.startsolid || trace.allsolid) + { + // The wide one failed, do the small traces for this segment + if (i == 0 || trace_step == small_trace_step) + return false; + + for (auto j = small_trace_step; j <= trace_step; j += small_trace_step) + { + current_loc = last_loc + dir * j; + current_loc[2] = last_height + STEPSIZE; + + bottom = current_loc; + bottom[2] = last_height - STEPSIZE; + + trace = G_Trace(current_loc, test_mins, test_maxs, bottom, act, clipMask, false, "Actor::CanWalkTo3"); + + if (trace.fraction == 1.0f || trace.startsolid || trace.allsolid || + trace.ent && trace.ent->entity->isSubclassOf(Sentient) && !act->GetActorFlag(ACTOR_FLAG_CAN_WALK_ON_OTHERS)) + return false; + + if (act->feet_width) + trace = _feetWidthTrace(current_loc, bottom, trace.endpos, clipMask); + + last_height = trace.endpos[2]; + } + } + + last_height = trace.endpos[2]; + last_loc = current_loc; + } + + if (last_height > end.z + STEPSIZE * 2.0f || last_height < end.z - STEPSIZE * 2.0f) + return false; + + return true; } @@ -1326,23 +1262,23 @@ qboolean MovementSubsystem::_checkHaveGroundEachStep( const Vector &start, const // // Returns: True or False // -qboolean MovementSubsystem::_isBlockedByDoor( trace_t &trace ) const +qboolean MovementSubsystem::_isBlockedByDoor(trace_t &trace) const { - Door *door; - - if ( !act->deadflag && trace.ent ) - { - // Check if we hit a door - - if ( trace.ent->entity->isSubclassOf( Door ) ) - { - door = ( Door * )trace.ent->entity; - if ( !door->locked && !door->isOpen() ) - return true; - } - } - - return false; + Door *door; + + if (!act->deadflag && trace.ent) + { + // Check if we hit a door + + if (trace.ent->entity->isSubclassOf(Door)) + { + door = dynamic_cast(trace.ent->entity); + if (!door->locked && !door->isOpen()) + return true; + } + } + + return false; } @@ -1357,21 +1293,21 @@ qboolean MovementSubsystem::_isBlockedByDoor( trace_t &trace ) const // // Returns: stepmoveresult_t // -stepmoveresult_t MovementSubsystem::_noGravityTryMove( const Vector &oldorg, trace_t &verticalTrace ) const +stepmoveresult_t MovementSubsystem::_noGravityTryMove(const Vector &oldorg, trace_t &verticalTrace) const { - Vector neworg = oldorg - _step; - //trace_t newTrace; - - // try stepping down - verticalTrace = G_Trace( oldorg, act->mins, act->maxs, neworg, act, act->edict->clipmask, false, "Actor::TryMove 2" ); - - if ( verticalTrace.startsolid ) - return STEPMOVE_STUCK; - - - //act->setOrigin( verticalTrace.endpos ); - - return STEPMOVE_OK; + auto neworg = oldorg - _step; + //trace_t newTrace; + + // try stepping down + verticalTrace = G_Trace(oldorg, act->mins, act->maxs, neworg, act, act->edict->clipmask, false, "Actor::TryMove 2"); + + if (verticalTrace.startsolid) + return STEPMOVE_STUCK; + + + //act->setOrigin( verticalTrace.endpos ); + + return STEPMOVE_OK; } @@ -1385,46 +1321,44 @@ stepmoveresult_t MovementSubsystem::_noGravityTryMove( const Vector &oldorg, tra // // Returns: True or False // -qboolean MovementSubsystem::_isBlockedByFall( trace_t &trace ) const +qboolean MovementSubsystem::_isBlockedByFall(trace_t &trace) const { - // Determine if we should allow the actor to fall - qboolean allow_fall = _allowFall(); - - // We never want to step on a flying creature, even if we are allowed to - // step on sentients in general. This is because, if we were to step on a flying - // creature, and the flying creature moved, then we might fall, where had we not - // stepped on the flying creature we would still be safe and sound - if ( trace.ent && ( trace.ent->entity->flags & FlagFly ) && !allow_fall ) - return true; - - // Don't voluntarilty step on sentients - if ( trace.ent && trace.ent->entity->isSubclassOf( Sentient ) && - !allow_fall && !act->GetActorFlag( ACTOR_FLAG_CAN_WALK_ON_OTHERS ) ) - return true; - - // Check if the move places us on solid ground - if ( trace.fraction == 1.0f ) - { - if ( allow_fall ) - { - // don't let guys get stuck standing on other guys - // if monster had the ground pulled out, go ahead and fall - act->groundentity = NULL; - return false; - } - else - { - // walked off an edge - return true; - } - } - - // Make sure ground is not too slopped or we will just slide off - - if ( ( trace.plane.normal[ 2 ] <= 0.7f ) && !allow_fall ) - return true; - - return false; + // Determine if we should allow the actor to fall + auto allow_fall = _allowFall(); + + // We never want to step on a flying creature, even if we are allowed to + // step on sentients in general. This is because, if we were to step on a flying + // creature, and the flying creature moved, then we might fall, where had we not + // stepped on the flying creature we would still be safe and sound + if (trace.ent && trace.ent->entity->flags & FlagFly && !allow_fall) + return true; + + // Don't voluntarilty step on sentients + if (trace.ent && trace.ent->entity->isSubclassOf(Sentient) && + !allow_fall && !act->GetActorFlag(ACTOR_FLAG_CAN_WALK_ON_OTHERS)) + return true; + + // Check if the move places us on solid ground + if (trace.fraction == 1.0f) + { + if (allow_fall) + { + // don't let guys get stuck standing on other guys + // if monster had the ground pulled out, go ahead and fall + act->groundentity = nullptr; + return false; + } + // walked off an edge + + return true; + } + + // Make sure ground is not too slopped or we will just slide off + + if (trace.plane.normal[2] <= 0.7f && !allow_fall) + return true; + + return false; } @@ -1441,12 +1375,12 @@ qboolean MovementSubsystem::_isBlockedByFall( trace_t &trace ) const // qboolean MovementSubsystem::_allowFall() const { - if ( ( act->flags & FlagPartialground ) || - ( act->groundentity && act->groundentity->entity && ( act->groundentity->entity->isSubclassOf( Sentient ) ) ) || - ( act->GetActorFlag( ACTOR_FLAG_ALLOW_FALL ) ) ) - return true; - - return false; + if (act->flags & FlagPartialground || + act->groundentity && act->groundentity->entity && act->groundentity->entity->isSubclassOf(Sentient) || + act->GetActorFlag(ACTOR_FLAG_ALLOW_FALL)) + return true; + + return false; } @@ -1462,14 +1396,14 @@ qboolean MovementSubsystem::_allowFall() const // qboolean MovementSubsystem::_shouldTryMove() const { - // We have a velocity so movement of the actor is done in physics - if ( ( act->velocity != vec_zero ) && !act->deadflag ) - return false; - - if ( ( _totallen <= 0.01f ) || ( _move == vec_zero ) ) - return false; - - return true; + // We have a velocity so movement of the actor is done in physics + if (act->velocity != vec_zero && !act->deadflag) + return false; + + if (_totallen <= 0.01f || _move == vec_zero) + return false; + + return true; } @@ -1485,11 +1419,11 @@ qboolean MovementSubsystem::_shouldTryMove() const // void MovementSubsystem::_saveGroundInformation(trace_t &trace) { - act->groundentity = trace.ent; - act->groundplane = trace.plane; - act->groundcontents = trace.contents; - act->last_origin = act->origin; - act->SetActorFlag( ACTOR_FLAG_HAVE_MOVED, true ); + act->groundentity = trace.ent; + act->groundplane = trace.plane; + act->groundcontents = trace.contents; + act->last_origin = act->origin; + act->SetActorFlag(ACTOR_FLAG_HAVE_MOVED, true); } @@ -1505,28 +1439,28 @@ void MovementSubsystem::_saveGroundInformation(trace_t &trace) // void MovementSubsystem::_init() { - _lastmove = STEPMOVE_OK; - _path = NULL; - _turnspeed = TURN_SPEED; - _startpos = act->origin; - _forwardspeed = 0; - _divedir = vec_zero; - act->angles.AngleVectors( &_movedir ); - - //Set our internal step var - _step = Vector( 0.0f, 0.0f, STEPSIZE ); - _movespeed = 1.0f; - - _fliplegs = false; - _movingBackwards = false; - _faceEnemy = false; - _adjustAnimDir = true; - _useCodeDrivenSpeed = false; - - _movementType = MOVEMENT_TYPE_NORMAL; - _stickToGround = true; - CheckWater(); - + _lastmove = STEPMOVE_OK; + _path = nullptr; + _turnspeed = TURN_SPEED; + _startpos = act->origin; + _forwardspeed = 0; + _divedir = vec_zero; + act->angles.AngleVectors(&_movedir); + + //Set our internal step var + _step = Vector(0.0f, 0.0f, STEPSIZE); + _movespeed = 1.0f; + + _fliplegs = false; + _movingBackwards = false; + _faceEnemy = false; + _adjustAnimDir = true; + _useCodeDrivenSpeed = false; + + _movementType = MOVEMENT_TYPE_NORMAL; + _stickToGround = true; + CheckWater(); + } @@ -1540,9 +1474,9 @@ void MovementSubsystem::_init() // // Returns: None // -void MovementSubsystem::setMove( const Vector &move ) +void MovementSubsystem::setMove(const Vector &move) { - _move = move; + _move = move; } @@ -1558,7 +1492,7 @@ void MovementSubsystem::setMove( const Vector &move ) // Vector MovementSubsystem::getMove() { - return _move; + return _move; } @@ -1573,9 +1507,9 @@ Vector MovementSubsystem::getMove() // // Returns: None // -void MovementSubsystem::setMoveDir( const Vector &moveDir ) +void MovementSubsystem::setMoveDir(const Vector &moveDir) { - _movedir = moveDir; + _movedir = moveDir; } @@ -1591,7 +1525,7 @@ void MovementSubsystem::setMoveDir( const Vector &moveDir ) // Vector MovementSubsystem::getMoveDir() { - return _movedir; + return _movedir; } @@ -1606,9 +1540,9 @@ Vector MovementSubsystem::getMoveDir() // // Returns: None // -void MovementSubsystem::setMoveVelocity( const Vector &moveVelocity ) +void MovementSubsystem::setMoveVelocity(const Vector &moveVelocity) { - _movevelocity = moveVelocity; + _movevelocity = moveVelocity; } @@ -1624,7 +1558,7 @@ void MovementSubsystem::setMoveVelocity( const Vector &moveVelocity ) // Vector MovementSubsystem::getMoveVelocity() { - return _movevelocity; + return _movevelocity; } @@ -1638,9 +1572,9 @@ Vector MovementSubsystem::getMoveVelocity() // // Returns: None // -void MovementSubsystem::setAnimDir( const Vector &animDir ) +void MovementSubsystem::setAnimDir(const Vector &animDir) { - _animdir = animDir; + _animdir = animDir; } @@ -1656,7 +1590,7 @@ void MovementSubsystem::setAnimDir( const Vector &animDir ) // Vector MovementSubsystem::getAnimDir() { - return _animdir; + return _animdir; } @@ -1670,9 +1604,9 @@ Vector MovementSubsystem::getAnimDir() // // Returns: None // -void MovementSubsystem::setDiveDir( const Vector &diveDir ) +void MovementSubsystem::setDiveDir(const Vector &diveDir) { - _divedir = diveDir; + _divedir = diveDir; } @@ -1688,7 +1622,7 @@ void MovementSubsystem::setDiveDir( const Vector &diveDir ) // Vector MovementSubsystem::getDiveDir() { - return _divedir; + return _divedir; } @@ -1702,9 +1636,9 @@ Vector MovementSubsystem::getDiveDir() // // Returns: None // -void MovementSubsystem::setStartPos( const Vector &startPos ) +void MovementSubsystem::setStartPos(const Vector &startPos) { - _startpos = startPos; + _startpos = startPos; } @@ -1720,7 +1654,7 @@ void MovementSubsystem::setStartPos( const Vector &startPos ) // Vector MovementSubsystem::getStartPos() { - return _startpos; + return _startpos; } @@ -1735,9 +1669,9 @@ Vector MovementSubsystem::getStartPos() // // Returns: None // -void MovementSubsystem::setTotalLen( float totalLen ) +void MovementSubsystem::setTotalLen(float totalLen) { - _totallen = totalLen; + _totallen = totalLen; } @@ -1753,7 +1687,7 @@ void MovementSubsystem::setTotalLen( float totalLen ) // float MovementSubsystem::getTotalLen() { - return _totallen; + return _totallen; } @@ -1767,9 +1701,9 @@ float MovementSubsystem::getTotalLen() // // Returns: None // -void MovementSubsystem::setTurnSpeed( float turnSpeed ) +void MovementSubsystem::setTurnSpeed(float turnSpeed) { - _turnspeed = turnSpeed; + _turnspeed = turnSpeed; } @@ -1785,7 +1719,7 @@ void MovementSubsystem::setTurnSpeed( float turnSpeed ) // float MovementSubsystem::getTurnSpeed() { - return _turnspeed; + return _turnspeed; } @@ -1799,9 +1733,9 @@ float MovementSubsystem::getTurnSpeed() // // Returns: None // -void MovementSubsystem::setForwardSpeed( float forwardSpeed ) +void MovementSubsystem::setForwardSpeed(float forwardSpeed) { - _forwardspeed = forwardSpeed; + _forwardspeed = forwardSpeed; } @@ -1817,7 +1751,7 @@ void MovementSubsystem::setForwardSpeed( float forwardSpeed ) // float MovementSubsystem::getForwardSpeed() { - return _forwardspeed; + return _forwardspeed; } @@ -1832,9 +1766,9 @@ float MovementSubsystem::getForwardSpeed() // // Returns: None // -void MovementSubsystem::setMoveSpeed( float moveSpeed ) +void MovementSubsystem::setMoveSpeed(float moveSpeed) { - _movespeed = moveSpeed; + _movespeed = moveSpeed; } @@ -1850,7 +1784,7 @@ void MovementSubsystem::setMoveSpeed( float moveSpeed ) // float MovementSubsystem::getMoveSpeed() { - return _movespeed; + return _movespeed; } @@ -1864,9 +1798,9 @@ float MovementSubsystem::getMoveSpeed() // // Returns: None // -void MovementSubsystem::setFlipLegs( qboolean flip ) +void MovementSubsystem::setFlipLegs(qboolean flip) { - _fliplegs = flip; + _fliplegs = flip; } @@ -1882,7 +1816,7 @@ void MovementSubsystem::setFlipLegs( qboolean flip ) // qboolean MovementSubsystem::getFlipLegs() { - return _fliplegs; + return _fliplegs; } @@ -1898,29 +1832,29 @@ qboolean MovementSubsystem::getFlipLegs() // void MovementSubsystem::flipLegs() { - Vector Angles; - - _fliplegs = !_fliplegs; - - - if ( _fliplegs ) - _movingBackwards = true; - else - _movingBackwards = false; - - - Angles = _animdir; - Angles = Angles.toAngles(); - - Angles[PITCH] = AngleNormalize180( Angles[PITCH] ); - Angles[ROLL] = AngleNormalize180( Angles[ROLL] ); - - Angles[YAW] = AngleNormalize180( Angles[YAW] + 180.0f ); - - Angles.AngleVectors( &_animdir ); - - //act->setAngles( Angles ); - + Vector Angles; + + _fliplegs = !_fliplegs; + + + if (_fliplegs) + _movingBackwards = true; + else + _movingBackwards = false; + + + Angles = _animdir; + Angles = Angles.toAngles(); + + Angles[PITCH] = AngleNormalize180(Angles[PITCH]); + Angles[ROLL] = AngleNormalize180(Angles[ROLL]); + + Angles[YAW] = AngleNormalize180(Angles[YAW] + 180.0f); + + Angles.AngleVectors(&_animdir); + + //act->setAngles( Angles ); + } @@ -1934,25 +1868,25 @@ void MovementSubsystem::flipLegs() // // Returns: None // -void MovementSubsystem::setMovingBackwards( qboolean backwards ) +void MovementSubsystem::setMovingBackwards(qboolean backwards) { - _movingBackwards = backwards; + _movingBackwards = backwards; } -void MovementSubsystem::setFaceEnemy( bool faceEnemy ) +void MovementSubsystem::setFaceEnemy(bool faceEnemy) { - _faceEnemy = faceEnemy; + _faceEnemy = faceEnemy; } -void MovementSubsystem::setAdjustAnimDir( bool adjustAnimDir ) +void MovementSubsystem::setAdjustAnimDir(bool adjustAnimDir) { - _adjustAnimDir = adjustAnimDir; + _adjustAnimDir = adjustAnimDir; } bool MovementSubsystem::getAdjustAnimDir() { - return _adjustAnimDir; + return _adjustAnimDir; } // @@ -1967,12 +1901,12 @@ bool MovementSubsystem::getAdjustAnimDir() // qboolean MovementSubsystem::getMovingBackwards() { - return _movingBackwards; + return _movingBackwards; } bool MovementSubsystem::getFaceEnemy() { - return _faceEnemy; + return _faceEnemy; } // @@ -1985,12 +1919,12 @@ bool MovementSubsystem::getFaceEnemy() // // Returns: None // -void MovementSubsystem::setPath( Path *path ) +void MovementSubsystem::setPath(Path *path) { - if ( _path && ( _path != path ) ) - delete _path; - - _path = path; + if (_path && _path != path) + delete _path; + + _path = path; } @@ -2006,7 +1940,7 @@ void MovementSubsystem::setPath( Path *path ) // Path* MovementSubsystem::getPath() { - return _path; + return _path; } // @@ -2019,9 +1953,9 @@ Path* MovementSubsystem::getPath() // // Returns: None // -void MovementSubsystem::setStep( const Vector &step ) +void MovementSubsystem::setStep(const Vector &step) { - _step = step; + _step = step; } @@ -2037,7 +1971,7 @@ void MovementSubsystem::setStep( const Vector &step ) // const Vector & MovementSubsystem::getStep() const { - return _step; + return _step; } // @@ -2050,9 +1984,9 @@ const Vector & MovementSubsystem::getStep() const // // Returns: None // -void MovementSubsystem::setLastMove( stepmoveresult_t lastMove ) +void MovementSubsystem::setLastMove(stepmoveresult_t lastMove) { - _lastmove = lastMove; + _lastmove = lastMove; } @@ -2068,7 +2002,7 @@ void MovementSubsystem::setLastMove( stepmoveresult_t lastMove ) // stepmoveresult_t MovementSubsystem::getLastMove() { - return _lastmove; + return _lastmove; } // @@ -2081,9 +2015,9 @@ stepmoveresult_t MovementSubsystem::getLastMove() // // Returns: None // -void MovementSubsystem::setMovementType( MovementType_t mType ) +void MovementSubsystem::setMovementType(MovementType_t mType) { - _movementType = mType; + _movementType = mType; } // @@ -2098,27 +2032,27 @@ void MovementSubsystem::setMovementType( MovementType_t mType ) // MovementType_t MovementSubsystem::getMovementType() { - return _movementType; + return _movementType; } -void MovementSubsystem::SetStickToGround( const bool stick ) +void MovementSubsystem::SetStickToGround(const bool stick) { - _stickToGround = stick; + _stickToGround = stick; } -const bool MovementSubsystem::GetStickToGround( void ) const +bool MovementSubsystem::GetStickToGround(void) const { - return _stickToGround; + return _stickToGround; } Entity* MovementSubsystem::getBlockingEntity() { - return _blockingEntity; + return _blockingEntity; } void MovementSubsystem::clearBlockingEntity() { - _blockingEntity = NULL; + _blockingEntity = nullptr; } // @@ -2132,13 +2066,13 @@ void MovementSubsystem::clearBlockingEntity() // // Returns: None // -void MovementSubsystem::DoArchive( Archiver &arc , Actor *actor ) +void MovementSubsystem::DoArchive(Archiver &arc, Actor *actor) { - Archive( arc ); - if ( actor ) - act = actor; - else - gi.Error( ERR_FATAL, "MovementSubsystem::DoArchive -- actor is NULL" ); + Archive(arc); + if (actor) + act = actor; + else + gi.Error(ERR_FATAL, "MovementSubsystem::DoArchive -- actor is NULL"); } @@ -2152,29 +2086,29 @@ void MovementSubsystem::DoArchive( Archiver &arc , Actor *actor ) // // Returns: None // -void MovementSubsystem::Archive( Archiver &arc ) +void MovementSubsystem::Archive(Archiver &arc) { - // Don't archive - //static Vector _step; + // Don't archive + //static Vector _step; - ArchiveEnum( _lastmove, stepmoveresult_t ); - arc.ArchiveFloat( &_forwardspeed ); - arc.ArchiveSafePointer( &_path ); - arc.ArchiveVector( &_move ); - arc.ArchiveVector( &_movedir ); - arc.ArchiveFloat( &_movespeed ); - arc.ArchiveVector( &_movevelocity ); - arc.ArchiveFloat( &_totallen ); - arc.ArchiveFloat( &_turnspeed ); - arc.ArchiveVector( &_animdir ); - arc.ArchiveVector( &_divedir ); - arc.ArchiveVector( &_startpos ); - arc.ArchiveBoolean( &_fliplegs ); - arc.ArchiveBoolean( &_movingBackwards ); - arc.ArchiveBool ( &_faceEnemy ); - arc.ArchiveBool ( &_adjustAnimDir ); - ArchiveEnum( _movementType, MovementType_t ); - arc.ArchiveBool( &_stickToGround ); - arc.ArchiveBool( &_useCodeDrivenSpeed ); - arc.ArchiveSafePointer( &_blockingEntity ); + ArchiveEnum(_lastmove, stepmoveresult_t); + arc.ArchiveFloat(&_forwardspeed); + arc.ArchiveSafePointer(&_path); + arc.ArchiveVector(&_move); + arc.ArchiveVector(&_movedir); + arc.ArchiveFloat(&_movespeed); + arc.ArchiveVector(&_movevelocity); + arc.ArchiveFloat(&_totallen); + arc.ArchiveFloat(&_turnspeed); + arc.ArchiveVector(&_animdir); + arc.ArchiveVector(&_divedir); + arc.ArchiveVector(&_startpos); + arc.ArchiveBoolean(&_fliplegs); + arc.ArchiveBoolean(&_movingBackwards); + arc.ArchiveBool(&_faceEnemy); + arc.ArchiveBool(&_adjustAnimDir); + ArchiveEnum(_movementType, MovementType_t); + arc.ArchiveBool(&_stickToGround); + arc.ArchiveBool(&_useCodeDrivenSpeed); + arc.ArchiveSafePointer(&_blockingEntity); } diff --git a/dlls/game/actor_locomotion.h b/dlls/game/actor_locomotion.h index c9eac6c..630a552 100644 --- a/dlls/game/actor_locomotion.h +++ b/dlls/game/actor_locomotion.h @@ -22,40 +22,48 @@ class LocomotionController; #ifndef __ACTOR_LOCOMOTION_H__ #define __ACTOR_LOCOMOTION_H__ -#include "actor.h" #include "actorincludes.h" -#include "weapon.h" #include "path.h" -#include "steering.h" class LocomotionController - { - public: - LocomotionController(); - LocomotionController( Actor *actor ); - ~LocomotionController(); +{ +public: + LocomotionController(); - void Begin(); - void Evaluate(); - void End(); - - // Accessors & Mutators - void SetMovementStyle( MovementStyle style ); - MovementStyle GetMovementStyle(); - - // Archiving - virtual void Archive( Archiver &arc ); - void DoArchive( Archiver &arc , Actor *actor ); + explicit LocomotionController(Actor *actor) + { + //Initialize our Actor + if (actor) + act = actor; + else + gi.Error(ERR_DROP, "LocomotionController::LocomotionController -- actor is NULL"); - protected: - void _init(); + _init(); + } - private: - Actor *act; - MovementStyle _movementStyle; - FollowPath _chase; + virtual ~LocomotionController(); - }; + void Begin(); + void Evaluate(); + void End(); + + // Accessors & Mutators + void SetMovementStyle(MovementStyle style); + MovementStyle GetMovementStyle(); + + // Archiving + virtual void Archive(Archiver &arc); + void DoArchive(Archiver &arc, Actor *actor); + +protected: + void _init(); + +private: + Actor *act; + MovementStyle _movementStyle; + FollowPath _chase; + +}; //============================ // Class MovementSubsystem @@ -63,155 +71,155 @@ class LocomotionController // // Encapsulates movement related data and functionality for the actor // -class MovementSubsystem - { - public: - MovementSubsystem(); - MovementSubsystem( Actor *actor ); - ~MovementSubsystem(); - - qboolean CanMoveTo( const Vector &pos ); - bool CanWalkTowardsPoint( const Vector &goalPoint, const int mask = -1); - qboolean CanWalkTo( const Vector &pos, float bounding_box_extra = 0, int entnum = ENTITYNUM_NONE, const int mask = -1 ); - qboolean CanWalkToFrom( const Vector &origin, const Vector &pos, float bounding_box_extra = 0, int entnum = ENTITYNUM_NONE, const int mask = -1 ); - void Accelerate( const Vector &steering ); - void CalcMove( void ); - stepmoveresult_t WaterMove( void ); - stepmoveresult_t AirMove( void ); - stepmoveresult_t IsMoveValid( trace_t &horizontalTrace, trace_t &verticalTrace, const Vector &moveBegin, const Vector &moveEnd ); - stepmoveresult_t TryMove( void ); - stepmoveresult_t SimpleMove( const bool stickToGround ); - - qboolean Push( const Vector &dir ); - void CheckWater( void ); - float JumpTo( PathNode * goal, const Angle angle = 45.0f ); - float JumpTo( Entity * goal, const Angle angle = 45.0f ); - float JumpTo( const Vector &targ, const Angle angle = 45.0f ); - const Vector SteerTowardsPoint(const Vector &targetPosition, const Vector &targetVelocity, const Vector &moveDirection, const float maxSpeed=1.0f, const bool adjustSpeed = false); - - - // Archiving - virtual void Archive( Archiver &arc ); - void DoArchive( Archiver &arc , Actor *actor ); - - // Accessors and Mutators - void setStep( const Vector &step ); - const Vector & getStep() const; - - void setLastMove( stepmoveresult_t lastMove ); - stepmoveresult_t getLastMove(); - - void setMove( const Vector &move ); - Vector getMove(); - - void setMoveDir( const Vector &moveDir ); - Vector getMoveDir(); - - void setMoveVelocity( const Vector &moveVelocity ); - Vector getMoveVelocity(); - - void setAnimDir( const Vector &animDir ); - Vector getAnimDir(); - - void setDiveDir( const Vector &diveDir ); - Vector getDiveDir(); - - void setStartPos( const Vector &startPos ); - Vector getStartPos(); - - void setTotalLen( float totalLen ); - float getTotalLen(); - - void setTurnSpeed( float turnSpeed ); - float getTurnSpeed(); - - void setForwardSpeed( float forwardSpeed ); - float getForwardSpeed(); - - void setMoveSpeed( float moveSpeed ); - float getMoveSpeed(); - - void setPath( Path* path ); - Path* getPath(); - - void setFlipLegs( qboolean flip ); - qboolean getFlipLegs(); - void flipLegs(); - - void setMovingBackwards( qboolean backwards ); - qboolean getMovingBackwards(); - - void setFaceEnemy ( bool faceEnemy ); - bool getFaceEnemy (); - - void setAdjustAnimDir( bool adjustAnimDir ); - bool getAdjustAnimDir(); - - - void setMovementType( MovementType_t mType ); - MovementType_t getMovementType(); - - void SetStickToGround( const bool stick ); - const bool GetStickToGround( void ) const; - - void setUseCodeDrivenSpeed( bool useCode ); - bool getUseCodeDrivenSpeed(); - - Entity* getBlockingEntity(); - void clearBlockingEntity(); - - - protected: // Functions - - Vector _getRealDestinationPosition( const Vector &pos ) const; - stepmoveresult_t _noGravityTryMove( const Vector &oldorg, trace_t &verticalTrace ) const; - trace_t _feetWidthTrace( const Vector ¤tLoc , const Vector &bottom , const Vector &endPos, const int mask ) const; - float _getTraceStep() const; - void _saveGroundInformation(trace_t &trace); - qboolean _isBlockedByDoor(trace_t &trace ) const; - qboolean _canMoveSimplePath(const Vector &mins, const Vector &maxs, const Vector &pos ) const; - qboolean _isBlockedByFall(trace_t &trace ) const; - qboolean _allowFall() const; - qboolean _shouldTryMove() const; - qboolean _checkHaveGroundEachStep( const Vector &start, const Vector &end, const Vector &test_mins , const Vector &test_maxs, const int mask = -1 ) const; - void _init(); - - private: // Member Variables - static Vector _step; - - stepmoveresult_t _lastmove; - float _forwardspeed; - PathPtr _path; - Vector _move; - Vector _movedir; - float _movespeed; - Vector _movevelocity; - float _totallen; - float _turnspeed; - Vector _animdir; - Vector _divedir; - Vector _startpos; - qboolean _fliplegs; - qboolean _movingBackwards; - bool _faceEnemy; - bool _adjustAnimDir; - MovementType_t _movementType; - bool _stickToGround; - bool _useCodeDrivenSpeed; - - Actor *act; - EntityPtr _blockingEntity; - - }; - -inline void MovementSubsystem::setUseCodeDrivenSpeed( bool useCode ) +class MovementSubsystem { - _useCodeDrivenSpeed = useCode; +public: + MovementSubsystem(); + explicit MovementSubsystem(Actor *actor); + virtual ~MovementSubsystem(); + + qboolean CanMoveTo(const Vector &pos); + bool CanWalkTowardsPoint(const Vector &goalPoint, const int mask = -1); + qboolean CanWalkTo(const Vector &pos, float bounding_box_extra = 0, int entnum = ENTITYNUM_NONE, const int mask = -1); + qboolean CanWalkToFrom(const Vector &origin, const Vector &pos, float bounding_box_extra = 0, int entnum = ENTITYNUM_NONE, const int mask = -1); + void Accelerate(const Vector &steering); + void CalcMove(void); + stepmoveresult_t WaterMove(void); + stepmoveresult_t AirMove(void); + stepmoveresult_t IsMoveValid(trace_t &horizontalTrace, trace_t &verticalTrace, const Vector &moveBegin, const Vector &moveEnd); + stepmoveresult_t TryMove(void); + stepmoveresult_t SimpleMove(const bool stickToGround); + + qboolean Push(const Vector &dir); + void CheckWater(void); + float JumpTo(PathNode * goal, const Angle angle = 45.0f); + float JumpTo(Entity * goal, const Angle angle = 45.0f); + float JumpTo(const Vector &targ, const Angle angle = 45.0f); + Vector SteerTowardsPoint(const Vector &targetPosition, const Vector &targetVelocity, const Vector &moveDirection, const float maxSpeed = 1.0f, const bool adjustSpeed = false); + + + // Archiving + virtual void Archive(Archiver &arc); + void DoArchive(Archiver &arc, Actor *actor); + + // Accessors and Mutators + void setStep(const Vector &step); + const Vector & getStep() const; + + void setLastMove(stepmoveresult_t lastMove); + stepmoveresult_t getLastMove(); + + void setMove(const Vector &move); + Vector getMove(); + + void setMoveDir(const Vector &moveDir); + Vector getMoveDir(); + + void setMoveVelocity(const Vector &moveVelocity); + Vector getMoveVelocity(); + + void setAnimDir(const Vector &animDir); + Vector getAnimDir(); + + void setDiveDir(const Vector &diveDir); + Vector getDiveDir(); + + void setStartPos(const Vector &startPos); + Vector getStartPos(); + + void setTotalLen(float totalLen); + float getTotalLen(); + + void setTurnSpeed(float turnSpeed); + float getTurnSpeed(); + + void setForwardSpeed(float forwardSpeed); + float getForwardSpeed(); + + void setMoveSpeed(float moveSpeed); + float getMoveSpeed(); + + void setPath(Path* path); + Path* getPath(); + + void setFlipLegs(qboolean flip); + qboolean getFlipLegs(); + void flipLegs(); + + void setMovingBackwards(qboolean backwards); + qboolean getMovingBackwards(); + + void setFaceEnemy(bool faceEnemy); + bool getFaceEnemy(); + + void setAdjustAnimDir(bool adjustAnimDir); + bool getAdjustAnimDir(); + + + void setMovementType(MovementType_t mType); + MovementType_t getMovementType(); + + void SetStickToGround(const bool stick); + bool GetStickToGround(void) const; + + void setUseCodeDrivenSpeed(bool useCode); + bool getUseCodeDrivenSpeed(); + + Entity* getBlockingEntity(); + void clearBlockingEntity(); + + +protected: // Functions + + Vector _getRealDestinationPosition(const Vector &pos) const; + stepmoveresult_t _noGravityTryMove(const Vector &oldorg, trace_t &verticalTrace) const; + trace_t _feetWidthTrace(const Vector ¤tLoc, const Vector &bottom, const Vector &endPos, const int mask) const; + float _getTraceStep() const; + void _saveGroundInformation(trace_t &trace); + qboolean _isBlockedByDoor(trace_t &trace) const; + qboolean _canMoveSimplePath(const Vector &mins, const Vector &maxs, const Vector &pos) const; + qboolean _isBlockedByFall(trace_t &trace) const; + qboolean _allowFall() const; + qboolean _shouldTryMove() const; + qboolean _checkHaveGroundEachStep(const Vector &start, const Vector &end, const Vector &test_mins, const Vector &test_maxs, const int mask = -1) const; + void _init(); + +private: // Member Variables + static Vector _step; + + stepmoveresult_t _lastmove; + float _forwardspeed; + PathPtr _path; + Vector _move; + Vector _movedir; + float _movespeed; + Vector _movevelocity; + float _totallen; + float _turnspeed; + Vector _animdir; + Vector _divedir; + Vector _startpos; + qboolean _fliplegs; + qboolean _movingBackwards; + bool _faceEnemy; + bool _adjustAnimDir; + MovementType_t _movementType; + bool _stickToGround; + bool _useCodeDrivenSpeed; + + Actor *act; + EntityPtr _blockingEntity; + +}; + +inline void MovementSubsystem::setUseCodeDrivenSpeed(bool useCode) +{ + _useCodeDrivenSpeed = useCode; } inline bool MovementSubsystem::getUseCodeDrivenSpeed() { - return _useCodeDrivenSpeed; + return _useCodeDrivenSpeed; } #endif /* __ACTOR_LOCOMOTION_H__ */ diff --git a/dlls/game/actor_posturecontroller.cpp b/dlls/game/actor_posturecontroller.cpp index 724cea9..09f4aa9 100644 --- a/dlls/game/actor_posturecontroller.cpp +++ b/dlls/game/actor_posturecontroller.cpp @@ -14,7 +14,6 @@ //----------------------------------------------------------------------------- #include "_pch_cpp.h" -#include "actor_posturecontroller.hpp" extern Event EV_Actor_SetPostureStateMap; @@ -138,16 +137,16 @@ void PostureController::Archive( Archiver &arc ) //-------------------------------------------------------------- void PostureController::init() { - _postureStateMap = NULL; + _postureStateMap = nullptr; _postureStateMap_Name = ""; - _currentPostureState = NULL; + _currentPostureState = nullptr; _currentPostureState_Name = ""; - _requestedPostureState = NULL; + _requestedPostureState = nullptr; _requestedPostureState_Name = ""; - _requestor = NULL; + _requestor = nullptr; } @@ -163,12 +162,11 @@ void PostureController::init() //-------------------------------------------------------------- void PostureController::evaluate() { - int count; - State *laststate = NULL; + int32_t count; + State *laststate; str currentanim; - str stateLegAnim; - stateLegAnim = act->animname; + auto stateLegAnim = act->animname; count = 0; if ( !_postureStateMap ) @@ -218,7 +216,7 @@ void PostureController::evaluate() // Change the animation if it has changed currentanim = _currentPostureState->getLegAnim( *act, &_postureConditionals ); - if ( currentanim.length() && ( stricmp( stateLegAnim , currentanim.c_str() ) != 0 ) ) + if ( currentanim.length() && stricmp( stateLegAnim , currentanim.c_str() ) != 0 ) { act->SetAnim( currentanim, EV_Posture_Anim_Done, legs ); stateLegAnim = currentanim; @@ -263,14 +261,12 @@ bool PostureController::requestPosture( const str &postureState , Listener *requ void PostureController::setPostureStateMap( const str &stateMap , bool loading ) { - str animName; - // Load the new state map _postureStateMap_Name = stateMap; //_postureConditionals.FreeObjectList(); act->freeConditionals( _postureConditionals ); - _postureStateMap = GetStatemap( _postureStateMap_Name, ( Condition * )act->Conditions, &_postureConditionals, false ); + _postureStateMap = GetStatemap( _postureStateMap_Name, reinterpret_cast * >(act->Conditions), &_postureConditionals, false ); // Set the first state _currentPostureState_Name = "START"; diff --git a/dlls/game/actor_posturecontroller.hpp b/dlls/game/actor_posturecontroller.hpp index 48d4d11..d04fb94 100644 --- a/dlls/game/actor_posturecontroller.hpp +++ b/dlls/game/actor_posturecontroller.hpp @@ -18,9 +18,6 @@ class PostureController; #ifndef __ACTOR_POSTURECONTROLLER_HPP__ #define __ACTOR_POSTURECONTROLLER_HPP__ -#include "actor.h" -#include "actorincludes.h" - extern Event EV_Posture_Anim_Done; extern Event EV_PostureChanged_Completed; @@ -39,54 +36,54 @@ extern Event EV_PostureChanged_Completed; //-------------------------------------------------------------- class PostureController { - public: - PostureController(); - PostureController( Actor *actor ); - ~PostureController(); +public: + PostureController(); + explicit PostureController(Actor *actor); + virtual ~PostureController(); - virtual void Archive( Archiver &arc ); - void DoArchive( Archiver &arc , Actor *actor ); - - void evaluate(); + virtual void Archive(Archiver &arc); + void DoArchive(Archiver &arc, Actor *actor); - bool requestPosture( const str &postureState , Listener *requestor ); - - const str& getRequestedPostureName(); - const str& getCurrentPostureName(); + void evaluate(); - void setPostureStateMap( const str &stateMap , bool loading ); - void setPostureState( const str &postureState ); - void setPostureState( const str &postureState , const str &requestedState ); + bool requestPosture(const str &postureState, Listener *requestor); - protected: - void init(); + const str& getRequestedPostureName(); + const str& getCurrentPostureName(); - private: - StateMap *_postureStateMap; - str _postureStateMap_Name; + void setPostureStateMap(const str &stateMap, bool loading); + void setPostureState(const str &postureState); + void setPostureState(const str &postureState, const str &requestedState); - State *_currentPostureState; - str _currentPostureState_Name; +protected: + void init(); - State *_requestedPostureState; - str _requestedPostureState_Name; +private: + StateMap *_postureStateMap; + str _postureStateMap_Name; - SafePtr _requestor; - Container _postureConditionals; + State *_currentPostureState; + str _currentPostureState_Name; + + State *_requestedPostureState; + str _requestedPostureState_Name; + + SafePtr _requestor; + Container _postureConditionals; - - Actor *act; + + Actor *act; }; inline const str& PostureController::getRequestedPostureName() { - return _requestedPostureState_Name; + return _requestedPostureState_Name; } inline const str& PostureController::getCurrentPostureName() { - return _currentPostureState_Name; + return _currentPostureState_Name; } #endif /* __ACTOR_POSTURECONTROLLER_HPP__ */ diff --git a/dlls/game/actor_sensoryperception.cpp b/dlls/game/actor_sensoryperception.cpp index afb1f8a..7367960 100644 --- a/dlls/game/actor_sensoryperception.cpp +++ b/dlls/game/actor_sensoryperception.cpp @@ -14,9 +14,6 @@ // #include "_pch_cpp.h" -#include "actor_sensoryperception.h" -#include "player.h" -#include "object.h" //====================================== // SensoryPerception Implementation @@ -62,16 +59,10 @@ SensoryPerception::~SensoryPerception() qboolean SensoryPerception::isInLineOfSight( const Vector &position , const int entNum ) { - trace_t trace; - Vector startPos; - Vector endPos; - Entity *traceEnt; - - - startPos = act->origin; + auto startPos = act->origin; startPos.z += 15; - endPos = position; + auto endPos = position; endPos.z += 15; Vector modMins; @@ -83,7 +74,7 @@ qboolean SensoryPerception::isInLineOfSight( const Vector &position , const int modMaxs = act->maxs; modMaxs *= 1.5; - trace = G_Trace( startPos, modMins, modMaxs, endPos, act, act->edict->clipmask, false, "isInLineOfSight" ); + auto trace = G_Trace( startPos, modMins, modMaxs, endPos, act, act->edict->clipmask, false, "isInLineOfSight" ); //G_DebugLine( startPos , trace.endpos, 1.0f, 0.0f, 1.0f, 1.0f ); _lineOfSight.entNum = entNum; @@ -95,13 +86,13 @@ qboolean SensoryPerception::isInLineOfSight( const Vector &position , const int } else { - traceEnt = G_GetEntity( trace.entityNum ); + auto traceEnt = G_GetEntity( trace.entityNum ); _lineOfSight.inLineOfSight = false; if ( traceEnt && traceEnt->isSubclassOf( Actor) ) { Actor *traceActor; - traceActor = (Actor*)traceEnt; + traceActor = dynamic_cast(traceEnt); _lineOfSight.inLineOfSight = traceActor->sensoryPerception->checkInLineOfSight( position , entNum ); } @@ -117,24 +108,23 @@ qboolean SensoryPerception::checkInLineOfSight( const Vector &position , const i timeDelta = level.time - _lineOfSight.time; if ( timeDelta > .5 || entNum != _lineOfSight.entNum ) - return isInLineOfSight( position , entNum ); - else - return _lineOfSight.inLineOfSight; - + return isInLineOfSight( position , entNum ); + + return _lineOfSight.inLineOfSight; } void SensoryPerception::_init() { // Set up Stimuli - _stimuli = STIMULI_ALL; - _permanent_stimuli = STIMULI_ALL; + _stimuli = StimuliAll; + _permanent_stimuli = StimuliAll; //Member Vars _noise_position = vec_zero; _noise_time = 0; _fov = DEFAULT_FOV; - _fovdot = (float)cos( (double)_fov * 0.5 * M_PI / 180.0 ); + _fovdot = float(cos( double(_fov) * 0.5 * M_PI / 180.0 )); _vision_distance = DEFAULT_VISION_DISTANCE; _last_soundType = SOUNDTYPE_NONE; _nextSenseTime = 0.0f; @@ -151,9 +141,7 @@ void SensoryPerception::_init() // needs to wake up // void SensoryPerception::SenseEnemies() -{ - int i; - +{ if ( _nextSenseTime > level.time ) return; @@ -161,13 +149,13 @@ void SensoryPerception::SenseEnemies() //_nextSenseTime = 0; //Well, who your enemies are depends on what side your on - if ( ( act->actortype == IS_ENEMY ) || ( act->actortype == IS_MONSTER ) ) + if ( act->actortype == IS_ENEMY || act->actortype == IS_MONSTER ) { // //If we an ENEMY or a MONSTER than teammates are our enemies // Sentient *teammate; - for ( i = 1 ; i <= TeamMateList.NumObjects() ; i++ ) + for ( auto i = 1 ; i <= TeamMateList.NumObjects() ; i++ ) { teammate = TeamMateList.ObjectAt( i ); @@ -179,14 +167,11 @@ void SensoryPerception::SenseEnemies() else { // - //If we an CIVILIAN, FRIEND, or TEAMMATE our potiential enemies are active monsters + //If we an CIVILIAN, FRIEND, or TEAMMATE our potential enemies are active monsters // - Entity *ent; - - for ( i = 1 ; i <= ActiveList.NumObjects() ; i++ ) + for (auto i = 1 ; i <= ActiveList.NumObjects() ; i++ ) { - ent = ActiveList.ObjectAt( i ); - _SenseEntity(ent); + _SenseEntity(ActiveList.ObjectAt(i)); } //In case we didn't find an enemy, but if the players nearby, we want to wake up anyway @@ -197,7 +182,7 @@ void SensoryPerception::SenseEnemies() qboolean SensoryPerception::_SenseEntity( Entity *ent ) { - // Dont want to target the enemy if he's not a valid target + // Don't want to target the enemy if he's not a valid target if (!ent) return false; @@ -205,7 +190,7 @@ qboolean SensoryPerception::_SenseEntity( Entity *ent ) if ( !EntityIsValidTarget(ent) ) return false; - // Dont wake ourselves up + // Don't wake ourselves up if ( ent->entnum == act->entnum ) return false; @@ -215,49 +200,19 @@ qboolean SensoryPerception::_SenseEntity( Entity *ent ) return false; } - /* - // Check if we're in the PVS - if ( gi.inPVS( ent->centroid, act->centroid ) ) - { - // Check if we can see the enemy - if ( CanSeeEntity ( act , ent , true , true ) ) - Stimuli( STIMULI_SIGHT , ent ); - else - { - // Lets not idle for teammates, just players - if ( ent->isSubclassOf( Player ) ) - { - // We couldn't see the enemy, but we're in the PVS, so we need to wake up and idle a bit. - if ( ( world->farplane_distance == 0 ) || ( Distance( ent->centroid, act->centroid ) < world->farplane_distance ) ) - { - act->Wakeup(); - //act->ActivateAI(); - } - - - } - else - return false; - } - - return true; - } - */ if ( gi.inPVS( ent->centroid, act->centroid ) ) { - Vector enemyToSelf; - enemyToSelf = act->origin - ent->origin; - - float visionDistance = GetVisionDistance(); + auto enemyToSelf = act->origin - ent->origin; + auto visionDistance = GetVisionDistance(); + if ( enemyToSelf.length() < visionDistance ) { if ( CanSeeEntity( act, ent, true, true ) ) - Stimuli( STIMULI_SIGHT , ent ); + Stimuli( StimuliSight , ent ); } } - return false; } @@ -363,17 +318,17 @@ void SensoryPerception::Stimuli( int new_stimuli, const Vector &pos, int sound_T void SensoryPerception::RespondTo(const str &stimuli_name , qboolean respond ) { if ( !Q_stricmp( stimuli_name.c_str() , "sight" ) ) - RespondTo(STIMULI_SIGHT , respond ); + RespondTo(StimuliSight , respond ); else if ( !Q_stricmp( stimuli_name.c_str() , "sound" ) ) - RespondTo(STIMULI_SOUND , respond ); + RespondTo(StimuliSound , respond ); else if ( !Q_stricmp( stimuli_name.c_str() , "pain" ) ) - RespondTo(STIMULI_PAIN , respond ); + RespondTo(StimuliPain , respond ); else if ( !Q_stricmp( stimuli_name.c_str() , "script" ) ) - RespondTo(STIMULI_SCRIPT , respond ); + RespondTo(StimuliScript , respond ); else if ( !Q_stricmp( stimuli_name.c_str() , "all" ) ) - RespondTo(STIMULI_ALL , respond ); + RespondTo(StimuliAll , respond ); else if ( !Q_stricmp( stimuli_name.c_str() , "none" ) ) - RespondTo(STIMULI_NONE , respond ); + RespondTo(StimuliNone , respond ); } // @@ -384,23 +339,15 @@ void SensoryPerception::RespondTo(const str &stimuli_name , qboolean respond ) // void SensoryPerception::RespondTo( int stimuli , qboolean respond ) { - if ( stimuli == STIMULI_ALL ) + if ( stimuli == StimuliAll ) { - if ( respond ) - _stimuli = STIMULI_ALL; - else - _stimuli = STIMULI_NONE; - + _stimuli = respond ? StimuliAll : StimuliNone; return; } - if ( stimuli == STIMULI_NONE ) + if ( stimuli == StimuliNone ) { - if ( respond ) - _stimuli = STIMULI_NONE; - else - _stimuli = STIMULI_ALL; - + _stimuli = respond ? StimuliNone : StimuliAll; return; } @@ -422,47 +369,47 @@ void SensoryPerception::PermanentlyRespondTo(const str &stimuli_name , qboolean if ( !Q_stricmp( stimuli_name.c_str() , "sight" ) ) { if ( respond ) - _permanent_stimuli |= STIMULI_SIGHT; + _permanent_stimuli |= StimuliSight; else - _permanent_stimuli &= ~STIMULI_SIGHT; + _permanent_stimuli &= ~StimuliSight; } else if ( !Q_stricmp( stimuli_name.c_str() , "sound" ) ) { if ( respond ) - _permanent_stimuli |= STIMULI_SOUND; + _permanent_stimuli |= StimuliSound; else - _permanent_stimuli &= ~STIMULI_SOUND; + _permanent_stimuli &= ~StimuliSound; } else if ( !Q_stricmp( stimuli_name.c_str() , "pain" ) ) { if ( respond ) - _permanent_stimuli |= STIMULI_PAIN; + _permanent_stimuli |= StimuliPain; else - _permanent_stimuli &= ~STIMULI_PAIN; + _permanent_stimuli &= ~StimuliPain; } else if ( !Q_stricmp( stimuli_name.c_str() , "script" ) ) { if ( respond ) - _permanent_stimuli |= STIMULI_SCRIPT; + _permanent_stimuli |= StimuliScript; else - _permanent_stimuli &= ~STIMULI_SCRIPT; + _permanent_stimuli &= ~StimuliScript; } else if ( !Q_stricmp( stimuli_name.c_str() , "all" ) ) { if ( respond ) - _permanent_stimuli = STIMULI_ALL; + _permanent_stimuli = StimuliAll; else - _permanent_stimuli = STIMULI_NONE; + _permanent_stimuli = StimuliNone; } else if ( !Q_stricmp( stimuli_name.c_str() , "none" ) ) { if ( respond ) - _permanent_stimuli = STIMULI_NONE; + _permanent_stimuli = StimuliNone; else - _permanent_stimuli = STIMULI_ALL; + _permanent_stimuli = StimuliAll; } } @@ -473,47 +420,47 @@ void SensoryPerception::PermanentlyRespondTo(const str &stimuli_name , qboolean // qboolean SensoryPerception::ShouldRespondToStimuli( int new_stimuli ) { - if( ( act->targetType == ATTACK_SCRIPTED_ONLY ) && ( new_stimuli != STIMULI_SCRIPT ) ) return false; + if( act->targetType == ATTACK_SCRIPTED_ONLY && new_stimuli != StimuliScript ) return false; - if ( _stimuli == STIMULI_ALL ) + if ( _stimuli == StimuliAll ) return true; - if ( _stimuli == STIMULI_NONE ) + if ( _stimuli == StimuliNone ) return false; - return ( (( new_stimuli & _stimuli ) && ( new_stimuli & _permanent_stimuli )) || ( new_stimuli == STIMULI_SCRIPT ) ); + return new_stimuli & _stimuli && new_stimuli & _permanent_stimuli || new_stimuli == StimuliScript; } // // Name: ShowInfo() // Parameters: None -// Description: Prints sensoryinformation to the console +// Description: Prints sensory information to the console // void SensoryPerception::ShowInfo() { - if ( ShouldRespondToStimuli( STIMULI_ALL ) ) + if ( ShouldRespondToStimuli( StimuliAll ) ) { gi.Printf( "Actor is Responding To: ALL" ); return; } - if ( ShouldRespondToStimuli( STIMULI_NONE ) ) + if ( ShouldRespondToStimuli( StimuliNone ) ) { gi.Printf( "Actor is Responding To: NONE" ); return; } - if ( ShouldRespondToStimuli( STIMULI_SIGHT ) ) + if ( ShouldRespondToStimuli( StimuliSight ) ) gi.Printf( "Actor is Responding To: SIGHT" ); - if ( ShouldRespondToStimuli( STIMULI_SOUND ) ) + if ( ShouldRespondToStimuli( StimuliSound ) ) gi.Printf( "Actor is Responding To: SOUND" ); - if ( ShouldRespondToStimuli( STIMULI_PAIN ) ) + if ( ShouldRespondToStimuli( StimuliPain ) ) gi.Printf( "Actor is Responding To: PAIN" ); - if ( ShouldRespondToStimuli( STIMULI_SCRIPT ) ) + if ( ShouldRespondToStimuli( StimuliScript ) ) gi.Printf( "Actor is Responding To: SCRIPT" ); } @@ -537,8 +484,8 @@ qboolean SensoryPerception::WithinVisionDistance( const Entity *ent ) gi.Error( ERR_DROP, "SensoryPerception::WithinVisionDistance -- actor is NULL" ); - // Use whichever is less : the actor's vision distance or the distance of the farplane (fog) - if ( ( world->farplane_distance != 0.0f ) && ( world->farplane_distance < _vision_distance ) ) + // Use whichever is less : the actor's vision distance or the distance of the far plane (fog) + if ( world->farplane_distance != 0.0f && world->farplane_distance < _vision_distance ) distance = world->farplane_distance; else distance = _vision_distance; @@ -553,8 +500,8 @@ qboolean SensoryPerception::WithinVisionDistance( const Vector &pos ) if ( !act ) gi.Error( ERR_DROP, "SensoryPerception::WithinVisionDistance -- actor is NULL" ); - // Use whichever is less : the actor's vision distance or the distance of the farplane (fog) - if ( ( world->farplane_distance != 0.0f ) && ( world->farplane_distance < _vision_distance ) ) + // Use whichever is less : the actor's vision distance or the distance of the far plane (fog) + if ( world->farplane_distance != 0.0f && world->farplane_distance < _vision_distance ) distance = world->farplane_distance; else distance = _vision_distance; @@ -571,19 +518,13 @@ qboolean SensoryPerception::WithinVisionDistance( const Vector &pos ) // qboolean SensoryPerception::InFOV( const Vector &pos, float check_fov, float check_fovdot ) { - Vector delta; - float dot; - Vector temp; - int tagNum; - - if ( !act ) gi.Error( ERR_DROP, "SensoryPerception::InFOV -- actor is NULL" ); if ( check_fov == 360.0f ) return true; - temp = act->EyePosition(); - delta = pos - act->EyePosition(); + + auto delta = pos - act->EyePosition(); if ( !delta.x && !delta.y ) { @@ -596,8 +537,9 @@ qboolean SensoryPerception::InFOV( const Vector &pos, float check_fov, float che delta.normalize(); - tagNum = gi.Tag_NumForName( act->edict->s.modelindex, "tag_eyes" ); + auto tagNum = gi.Tag_NumForName( act->edict->s.modelindex, "tag_eyes" ); + float dot; if ( tagNum >= 0 ) { Vector tag_pos; @@ -611,7 +553,7 @@ qboolean SensoryPerception::InFOV( const Vector &pos, float check_fov, float che dot = DotProduct( act->orientation[ 0 ], delta ); } - return ( dot > check_fovdot ); + return dot > check_fovdot; } @@ -653,7 +595,7 @@ qboolean SensoryPerception::CanSeeEntity( Entity *start, const Entity *target, q return false; // Check if This Actor can even see at all - if ( !ShouldRespondToStimuli( STIMULI_SIGHT ) ) + if ( !ShouldRespondToStimuli( StimuliSight ) ) return false; // Check for FOV @@ -671,18 +613,14 @@ qboolean SensoryPerception::CanSeeEntity( Entity *start, const Entity *target, q } // Do Trace - trace_t trace; - Vector p; - Vector eyePos; - - p = target->centroid; - eyePos = vec_zero; + auto p = target->centroid; + auto eyePos = vec_zero; // If the start entity is an actor, then we want to add in the eyeposition if ( start->isSubclassOf ( Actor ) ) { Actor *a; - a = (Actor*)start; + a = dynamic_cast(start); if ( !a ) return false; @@ -692,15 +630,9 @@ qboolean SensoryPerception::CanSeeEntity( Entity *start, const Entity *target, q } // Check if he's visible - trace = G_Trace( eyePos, vec_zero, vec_zero, p, target, MASK_OPAQUE, false, "SensoryPerception::CanSeeEntity" ); - - //if ( act->actortype == IS_TEAMMATE ) - // { - // G_DebugLine( eyePos , target->centroid, 0.0f, 0.0f, 1.0f, 1.0f ); - // G_DebugLine( eyePos , trace.endpos , 1.0f, 0.0f, 1.0f, 1.0f ); - // } + auto trace = G_Trace( eyePos, vec_zero, vec_zero, p, target, MASK_OPAQUE, false, "SensoryPerception::CanSeeEntity" ); - if ( ( trace.fraction == 1.0f ) || ( trace.ent == target->edict ) ) + if ( trace.fraction == 1.0f || trace.ent == target->edict ) return true; // Check if his head is visible @@ -724,14 +656,12 @@ qboolean SensoryPerception::CanSeeEntity( Entity *start, const Entity *target, q // qboolean SensoryPerception::CanSeeEntity( const Vector &start , const Entity *target, qboolean useFOV , qboolean useVisionDistance ) { - Vector realStart; - // Check for NULL if ( !target ) return false; // Check if This Actor can even see at all - if ( !ShouldRespondToStimuli( STIMULI_SIGHT ) ) + if ( !ShouldRespondToStimuli( StimuliSight ) ) return false; @@ -750,21 +680,16 @@ qboolean SensoryPerception::CanSeeEntity( const Vector &start , const Entity *ta } // Do Trace - trace_t trace; - Vector p; - Vector eyePos; - - realStart = start; - - p = target->centroid; + auto realStart = start; + auto p = target->centroid; // Add in the eye offset - eyePos = act->EyePosition() - act->origin; + auto eyePos = act->EyePosition() - act->origin; realStart += eyePos; // Check if he's visible - trace = G_Trace( realStart, vec_zero, vec_zero, p, act, MASK_OPAQUE, false, "SensoryPerception::CanSeeEntity" ); + auto trace = G_Trace( realStart, vec_zero, vec_zero, p, act, MASK_OPAQUE, false, "SensoryPerception::CanSeeEntity" ); if ( trace.fraction == 1.0f || trace.ent == target->edict ) return true; @@ -795,7 +720,7 @@ qboolean SensoryPerception::CanSeeEntityComplex(Entity *start, Entity *target, q return false; // Check if This Actor can even see at all - if ( !ShouldRespondToStimuli( STIMULI_SIGHT ) ) + if ( !ShouldRespondToStimuli( StimuliSight ) ) return false; if ( !act ) @@ -826,7 +751,7 @@ qboolean SensoryPerception::CanSeeEntityComplex( Vector &start, Entity *target, return false; // Check if This Actor can even see at all - if ( !ShouldRespondToStimuli( STIMULI_SIGHT ) ) + if ( !ShouldRespondToStimuli( StimuliSight ) ) return false; if ( !act ) @@ -845,7 +770,7 @@ qboolean SensoryPerception::CanSeePosition( const Vector &start, const Vector &p { // Check if This Actor can even see at all - if ( !ShouldRespondToStimuli( STIMULI_SIGHT ) ) + if ( !ShouldRespondToStimuli( StimuliSight ) ) return false; // Check for FOV @@ -863,13 +788,8 @@ qboolean SensoryPerception::CanSeePosition( const Vector &start, const Vector &p } // Do Trace - trace_t trace; - Vector eyePos; - - eyePos = vec_zero; - // Check if he's visible - trace = G_Trace( start, vec_zero, vec_zero, position, act, MASK_OPAQUE, false, "SensoryPerception::CanSeeEntity" ); + auto trace = G_Trace( start, vec_zero, vec_zero, position, act, MASK_OPAQUE, false, "SensoryPerception::CanSeeEntity" ); if ( trace.fraction == 1.0f ) return true; @@ -886,17 +806,15 @@ qboolean SensoryPerception::CanSeePosition( const Vector &start, const Vector &p // qboolean SensoryPerception::_CanSeeComplex( Vector &start, Entity *target , qboolean useFOV, qboolean useVisionDistance ) { - Vector d; - Vector p1; - Vector p2; - if ( !target ) return false; - d = target->centroid - start; + auto d = target->centroid - start; d.z = 0; d.normalize(); + Vector p1; + Vector p2; p1.x = -d.y; p1.y = d.x; p1 *= max( act->size.x, act->size.y ) * 1.44f * 0.5f; diff --git a/dlls/game/actor_sensoryperception.h b/dlls/game/actor_sensoryperception.h index 7818aca..0079f5d 100644 --- a/dlls/game/actor_sensoryperception.h +++ b/dlls/game/actor_sensoryperception.h @@ -20,9 +20,7 @@ class SensoryPerception; #ifndef __ACTOR_SENSORYPERCEPTION_H__ #define __ACTOR_SENSORYPERCEPTION_H__ -#include "actor.h" #include "actorincludes.h" -#include "weapon.h" //============================ // Class SensoryPerception @@ -30,102 +28,101 @@ class SensoryPerception; // // Class used to handle all sensory perception by actors. // -class SensoryPerception - { - public: - SensoryPerception(); - SensoryPerception(Actor *actor ); - ~SensoryPerception(); - - // Sense functions - void SenseEnemies(); - void SearchForEnemies(); +class SensoryPerception +{ +public: + SensoryPerception(); + explicit SensoryPerception(Actor *actor); + virtual ~SensoryPerception(); + + // Sense functions + void SenseEnemies(); - // Stimuli functions - void Stimuli( int stimuli ); - void Stimuli( int stimuli, Entity *ent ); - void Stimuli( int stimuli, const Vector &pos ); - void Stimuli( int stimuli, const Vector &pos, int sound_Type ); - void RespondTo( const str &stimuli_name , qboolean respond ); - void RespondTo( int stimuli, qboolean respond ); - void PermanentlyRespondTo( const str &stimuli_name , qboolean respond ); - qboolean ShouldRespondToStimuli( int new_stimuli ); - + // Stimuli functions + void Stimuli(int stimuli); + void Stimuli(int stimuli, Entity *ent); + void Stimuli(int stimuli, const Vector &pos); + void Stimuli(int stimuli, const Vector &pos, int sound_Type); + void RespondTo(const str &stimuli_name, qboolean respond); + void RespondTo(int stimuli, qboolean respond); + void PermanentlyRespondTo(const str &stimuli_name, qboolean respond); + qboolean ShouldRespondToStimuli(int new_stimuli); - // Vision functions - qboolean WithinVisionDistance( const Entity *ent ); - qboolean WithinVisionDistance( const Vector &pos ); - qboolean InFOV( const Vector &pos, float check_fov, float check_fovdot ); - qboolean InFOV( const Vector &pos ); - qboolean InFOV( const Entity *ent ); - - // New Vision Functions -- Simplified Vision - qboolean CanSeeEntity( Entity *start , const Entity *target, qboolean useFOV, qboolean useVisionDistance ); - qboolean CanSeeEntity( const Vector &start , const Entity *target, qboolean useFOV, qboolean useVisionDistance ); - - // New Vision Functions -- More Sophisticated Vision - qboolean CanSeeEntityComplex( Entity *start , Entity *target, qboolean useFOV, qboolean useVisionDistance ); - qboolean CanSeeEntityComplex( Vector &start , Entity *target, qboolean useFOV, qboolean useVisionDistance ); - qboolean CanSeePosition( const Vector &start, const Vector &position, qboolean useFOV, qboolean useVisionDistance ); + // Vision functions + qboolean WithinVisionDistance(const Entity *ent); + qboolean WithinVisionDistance(const Vector &pos); + qboolean InFOV(const Vector &pos, float check_fov, float check_fovdot); + qboolean InFOV(const Vector &pos); + qboolean InFOV(const Entity *ent); - qboolean isInLineOfSight( const Vector &position , const int entNum ); - qboolean checkInLineOfSight( const Vector &position , const int entNum ); + // New Vision Functions -- Simplified Vision + qboolean CanSeeEntity(Entity *start, const Entity *target, qboolean useFOV, qboolean useVisionDistance); + qboolean CanSeeEntity(const Vector &start, const Entity *target, qboolean useFOV, qboolean useVisionDistance); - // Debugging Functions - void ShowInfo(); + // New Vision Functions -- More Sophisticated Vision + qboolean CanSeeEntityComplex(Entity *start, Entity *target, qboolean useFOV, qboolean useVisionDistance); + qboolean CanSeeEntityComplex(Vector &start, Entity *target, qboolean useFOV, qboolean useVisionDistance); - // Accessors and Mutators - void SetNoisePosition( const Vector &pos ); - Vector GetNoisePosition(); + qboolean CanSeePosition(const Vector &start, const Vector &position, qboolean useFOV, qboolean useVisionDistance); - void SetLastSoundType( int soundtype ); - int GetLastSoundType(); + qboolean isInLineOfSight(const Vector &position, const int entNum); + qboolean checkInLineOfSight(const Vector &position, const int entNum); - void SetNoiseTime( float noisetime ); - float GetNoiseTime(); + // Debugging Functions + void ShowInfo(); - void SetFOV( float fov ); - float GetFOV(); + // Accessors and Mutators + void SetNoisePosition(const Vector &pos); + Vector GetNoisePosition(); - void SetFOVdot( float fov_dot ); - float GetFOVdot(); + void SetLastSoundType(int soundtype); + int GetLastSoundType(); - void SetVisionDistance( float vision_distance ); - float GetVisionDistance(); - - // Archiving - virtual void Archive( Archiver &arc ); - void DoArchive( Archiver &arc , Actor *actor ); - - private: //Functions - qboolean _CanSeeComplex( Vector &start , Entity *target , qboolean useFOV , qboolean useVisionDistance ); - qboolean _SenseEntity( Entity *ent ); - void _init(); + void SetNoiseTime(float noisetime); + float GetNoiseTime(); - private: //Member Variables - - // Stimuli Variables - int _stimuli; - int _permanent_stimuli; + void SetFOV(float fov); + float GetFOV(); - // Hearing Variables - Vector _noise_position; - int _last_soundType; - float _noise_time; - - // Vision Stuff for "seeing" - float _fov; - float _fovdot; - float _vision_distance; + void SetFOVdot(float fov_dot); + float GetFOVdot(); - float _nextSenseTime; + void SetVisionDistance(float vision_distance); + float GetVisionDistance(); - LineOfSight_t _lineOfSight; + // Archiving + virtual void Archive(Archiver &arc); + void DoArchive(Archiver &arc, Actor *actor); - Actor *act; - - }; +private: //Functions + qboolean _CanSeeComplex(Vector &start, Entity *target, qboolean useFOV, qboolean useVisionDistance); + qboolean _SenseEntity(Entity *ent); + void _init(); + + //Member Variables + + // Stimuli Variables + int _stimuli; + int _permanent_stimuli; + + // Hearing Variables + Vector _noise_position; + int _last_soundType; + float _noise_time; + + // Vision Stuff for "seeing" + float _fov; + float _fovdot; + float _vision_distance; + + float _nextSenseTime; + + LineOfSight_t _lineOfSight; + + Actor *act; + +}; #endif /* __ACTOR_SENSORYPERCEPTION_H__ */ diff --git a/dlls/game/actorgamecomponents.cpp b/dlls/game/actorgamecomponents.cpp index fcd31cf..dd197ad 100644 --- a/dlls/game/actorgamecomponents.cpp +++ b/dlls/game/actorgamecomponents.cpp @@ -20,8 +20,6 @@ // #include "_pch_cpp.h" -#include "actorgamecomponents.h" -#include "player.h" // @@ -74,7 +72,7 @@ EFGameComponent::EFGameComponent() EFGameComponent::EFGameComponent( const Actor *actor ) { if ( actor ) - act = (Actor *)actor; + act = const_cast(actor); } void EFGameComponent::DoArchive( Archiver &arc , const Actor *actor ) @@ -82,7 +80,7 @@ void EFGameComponent::DoArchive( Archiver &arc , const Actor *actor ) Q_UNUSED(arc); if ( actor ) - act = (Actor *)actor; + act = const_cast(actor); else gi.Error( ERR_FATAL, "EFGameComponnet::DoArchive -- actor is NULL" ); diff --git a/dlls/game/actorgamecomponents.h b/dlls/game/actorgamecomponents.h index 447f09d..01c6abf 100644 --- a/dlls/game/actorgamecomponents.h +++ b/dlls/game/actorgamecomponents.h @@ -26,8 +26,6 @@ class RedemptionGameComponent; #ifndef __ACTORGAMECOMPONENTS_H__ #define __ACTORGAMECOMPONENTS_H__ -#include "actor.h" - //============================ // Class ActorGameComponent //============================ @@ -35,20 +33,20 @@ class RedemptionGameComponent; // Base class from which all Actor Game Components are derived. // class ActorGameComponent : public Listener - { - public: - CLASS_PROTOTYPE( ActorGameComponent ); +{ +public: + CLASS_PROTOTYPE(ActorGameComponent); - ActorGameComponent() {} - virtual void HandleEvent( Event * ) {} - virtual void HandleArmorDamage( Event * ) {} - virtual void HandleDeath( const Entity * ) {} - virtual void HandleThink() {} - - virtual qboolean DoCheck( const Conditional & ) { return false; } - virtual void DoArchive( Archiver &, const Actor * ) {} + ActorGameComponent() { } + virtual void HandleEvent(Event *) { } + virtual void HandleArmorDamage(Event *) { } + virtual void HandleDeath(const Entity *) { } + virtual void HandleThink() { } - }; + virtual qboolean DoCheck(const Conditional &) { return false; } + virtual void DoArchive(Archiver &, const Actor *) { } + +}; /* EF Specific Stuff @@ -57,23 +55,23 @@ EF Specific Stuff // Class EFGameComponent //============================ class EFGameComponent : public ActorGameComponent - { - public: - CLASS_PROTOTYPE( EFGameComponent ); +{ +public: + CLASS_PROTOTYPE(EFGameComponent); - EFGameComponent(); - EFGameComponent( const Actor *actor ); + EFGameComponent(); + EFGameComponent(const Actor *actor); - void HandleEvent( Event *ev ); - void HandleArmorDamage( Event *ev ); - void HandleDeath( const Entity *ent); - void HandleThink(); + void HandleEvent(Event *ev); + void HandleArmorDamage(Event *ev); + void HandleDeath(const Entity *ent); + void HandleThink(); - qboolean DoCheck( const Conditional &condition ); - void DoArchive( Archiver &arc , const Actor *act ); + qboolean DoCheck(const Conditional &condition); + void DoArchive(Archiver &arc, const Actor *act); - private: - Actor *act; - }; +private: + Actor *act; +}; #endif /*__ACTORGAMECOMPONENTS_H__*/ diff --git a/dlls/game/actorincludes.h b/dlls/game/actorincludes.h index 925cf50..fa1a9a1 100644 --- a/dlls/game/actorincludes.h +++ b/dlls/game/actorincludes.h @@ -28,8 +28,8 @@ extern Event EV_Actor_Start; extern Event EV_Actor_Dead; extern Event EV_Actor_LookAt; extern Event EV_Actor_TurnTo; -extern Event EV_Actor_BehaviorFinished ; -extern Event EV_Actor_ControlLost ; +extern Event EV_Actor_BehaviorFinished; +extern Event EV_Actor_ControlLost; extern Event EV_Actor_EndBehavior; extern Event EV_Actor_EndHeadBehavior; extern Event EV_Actor_EndEyeBehavior; @@ -61,112 +61,126 @@ extern Event EV_Actor_Statemap; extern Event EV_Actor_SetTargetable; extern Event EV_Sentient_StopFire; extern Event EV_Sentient_Attack; -extern Event EV_Actor_SetUseGravity ; -extern Event EV_Actor_SetSimplifiedThink ; -extern Event EV_Actor_SetStickToGround ; -extern Event EV_Actor_SetMovementMode ; +extern Event EV_Actor_SetUseGravity; +extern Event EV_Actor_SetSimplifiedThink; +extern Event EV_Actor_SetStickToGround; +extern Event EV_Actor_SetMovementMode; //======================================== // General Defines //======================================== -#define MAX_ALIAS_NAME_LENGTH 32 -#define MAX_INACTIVE_TIME 30.0 -#define DEFAULT_FOV 150 -#define DEFAULT_VISION_DISTANCE 1536 -#define MIN_SIGHT_DELAY 2 -#define RANDOM_SIGHT_DELAY 1.5 -#define DEFAULT_INITIAL_HATE 100 -#define TURN_SPEED 60 //Used to be 25 -#define HELPER_NODE_MAX_DISTANCE 96.0 -#define HELPER_NODE_ARRIVAL_DISTANCE 24.0 +static const uint8_t MAX_ALIAS_NAME_LENGTH = 32; +static const float MAX_INACTIVE_TIME = 30.0f; +static const uint8_t DEFAULT_FOV = 150; +static const uint16_t DEFAULT_VISION_DISTANCE = 1536; +static const uint8_t MIN_SIGHT_DELAY = 2; +static const float RANDOM_SIGHT_DELAY = 1.5f; +static const uint8_t DEFAULT_INITIAL_HATE = 100; +static const float TURN_SPEED = 60.0f; //Used to be 25 +static const float HELPER_NODE_MAX_DISTANCE = 96.0f; +static const float HELPER_NODE_ARRIVAL_DISTANCE = 24.0f; -#define HACK_PATH_CHECK 1.0 +static const float HACK_PATH_CHECK = 1.0f; //======================================== // Stimuli types //======================================== -#define STIMULI_ALL -1 -#define STIMULI_NONE 0 -#define STIMULI_SIGHT (1<<0) -#define STIMULI_SOUND (1<<1) -#define STIMULI_PAIN (1<<2) -#define STIMULI_SCRIPT (1<<3) +enum EStimuli +{ + StimuliAll = -1, + StimuliNone, + StimuliSight = 1 << 0, + StimuliSound = 1 << 1, + StimuliPain = 1 << 2, + StimuliScript = 1 << 3 +}; //======================================== // Bones used by actor //======================================== -#define ACTOR_MOUTH_TAG 0 -#define ACTOR_HEAD_TAG 1 -#define ACTOR_TORSO_TAG 2 -#define ACTOR_LEYE_TAG 3 -#define ACTOR_REYE_TAG 4 +enum EActorBoneTag +{ + ActorMouthTag = 0, + ActorHeadTag = 1, + ActorTorsoTag = 2, + ActorLeyeTag = 3, + ActorReyeTag = 4 +}; //======================================== // Dialog stuff //======================================== -#define MAX_DIALOG_PARAMETERS_LENGTH 100 -#define MAX_DIALOG_PARM_LENGTH 64 -#define MAX_DIALOG_PARMS 10 -#define DIALOG_PARM_TYPE_NONE 0 -#define DIALOG_PARM_TYPE_PLAYERHAS 1 -#define DIALOG_PARM_TYPE_PLAYERHASNOT 2 -#define DIALOG_PARM_TYPE_HAS 3 -#define DIALOG_PARM_TYPE_HASNOT 4 -#define DIALOG_PARM_TYPE_DEPENDS 5 -#define DIALOG_PARM_TYPE_DEPENDSNOT 6 -#define DIALOG_PARM_TYPE_DEPENDSINT 7 -#define DIALOG_PARM_TYPE_CONTEXT_INITIATOR 8 -#define DIALOG_PARM_TYPE_CONTEXT_RESPONSE 9 +static const uint8_t MAX_DIALOG_PARAMETERS_LENGTH = 100; +static const uint8_t MAX_DIALOG_PARM_LENGTH = 64; +static const uint8_t MAX_DIALOG_PARMS = 10; +static const uint8_t DIALOG_PARM_TYPE_NONE = 0; +static const uint8_t DIALOG_PARM_TYPE_PLAYERHAS = 1; +static const uint8_t DIALOG_PARM_TYPE_PLAYERHASNOT = 2; +static const uint8_t DIALOG_PARM_TYPE_HAS = 3; +static const uint8_t DIALOG_PARM_TYPE_HASNOT = 4; +static const uint8_t DIALOG_PARM_TYPE_DEPENDS = 5; +static const uint8_t DIALOG_PARM_TYPE_DEPENDSNOT = 6; +static const uint8_t DIALOG_PARM_TYPE_DEPENDSINT = 7; +static const uint8_t DIALOG_PARM_TYPE_CONTEXT_INITIATOR = 8; +static const uint8_t DIALOG_PARM_TYPE_CONTEXT_RESPONSE = 9; //======================================== // State flags //======================================== -#define STATE_FLAG_IN_PAIN ( 1<<0 ) -#define STATE_FLAG_MELEE_HIT ( 1<<1 ) -#define STATE_FLAG_TOUCHED ( 1<<2 ) -#define STATE_FLAG_ACTIVATED ( 1<<3 ) -#define STATE_FLAG_USED ( 1<<4 ) -#define STATE_FLAG_TWITCH ( 1<<5 ) -#define STATE_FLAG_BLOCKED_HIT ( 1<<6 ) -#define STATE_FLAG_SMALL_PAIN ( 1<<7 ) -#define STATE_FLAG_OTHER_DIED ( 1<<8 ) -#define STATE_FLAG_STUCK ( 1<<9 ) -#define STATE_FLAG_NO_PATH ( 1<<10 ) -#define STATE_FLAG_TOUCHED_BY_PLAYER ( 1<<11 ) -#define STATE_FLAG_CHANGED_WEAPON ( 1<<12 ) -#define STATE_FLAG_DAMAGE_THRESHOLD_EXCEEDED ( 1<<13 ) -#define STATE_FLAG_ATTACKED ( 1<<14 ) -#define STATE_FLAG_ATTACKED_BY_PLAYER ( 1<<15 ) -#define STATE_FLAG_SHOW_PAIN ( 1<<16 ) -#define STATE_FLAG_IN_THE_WAY ( 1<<17 ) -#define STATE_FLAG_STEERING_FAILED ( 1<<18 ) -#define STATE_FLAG_BLOCKED_BY_ENTITY ( 1<<19 ) -#define STATE_FLAG_ENEMY_PROJECTILE_CLOSE ( 1<<20 ) +enum EStateFlag +{ + StateFlagInPain = 1 << 0, + StateFlagMeleeHit = 1 << 1, + StateFlagTouched = 1 << 2, + StateFlagActivated = 1 << 3, + StateFlagUsed = 1 << 4, + StateFlagTwitch = 1 << 5, + StateFlagBlockedHit = 1 << 6, + StateFlagSmallPain = 1 << 7, + StateFlagOtherDied = 1 << 8, + StateFlagStuck = 1 << 9, + StateFlagNoPath = 1 << 10, + StateFlagTouchedByPlayer = 1 << 11, + StateFlagChangedWeapon = 1 << 12, + StateFlagDamageThresholdExceeded = 1 << 13, + StateFlagAttacked = 1 << 14, + StateFlagAttackedByPlayer = 1 << 15, + StateFlagShowPain = 1 << 16, + StateFlagInTheWay = 1 << 17, + StateFlagSteeringFailed = 1 << 18, + StateFlagBlockedByEntity = 1 << 19, + StateFlagEnemyProjectileClose = 1 << 20 +}; //======================================== // Combat Subsystem Defines //======================================== -#define DEFAULT_TRACE_INTERVAL .05f - -#define DEFAULT_PATH_TO_ENEMY_INTERVAL .05f +static const float DEFAULT_TRACE_INTERVAL = .05f; +static const float DEFAULT_PATH_TO_ENEMY_INTERVAL = .05f; //======================================== // Actor modes //======================================== -#define ACTOR_MODE_NONE 0 -#define ACTOR_MODE_IDLE 1 -#define ACTOR_MODE_AI 2 -#define ACTOR_MODE_SCRIPT 3 -#define ACTOR_MODE_TALK 4 +enum EActorMode +{ + ActorModeNone, + ActorModeIdle, + ActorModeAi, + ActorModeScript, + ActorModeTalk +}; //======================================= // Pain types //======================================= -#define PAIN_SMALL 0 -#define PAIN_BIG 1 +enum EPainType +{ + PainSmall, + PainBig +}; //======================================== // Save Flags @@ -208,39 +222,39 @@ extern Event EV_Actor_SetMovementMode ; //DialogParm_t -- Structure for Dialog Parameters typedef struct { - byte type; - char parm[ MAX_DIALOG_PARM_LENGTH ]; - char parm2[ MAX_DIALOG_PARM_LENGTH ]; + byte type; + char parm[MAX_DIALOG_PARM_LENGTH]; + char parm2[MAX_DIALOG_PARM_LENGTH]; } DialogParm_t; typedef enum { - DIALOG_TYPE_NORMAL, - DIALOG_TYPE_RADIUS, - DIALOG_TYPE_GREETING, - DIALOG_TYPE_COMBAT, - DIALOG_TYPE_CONTEXT_INITIATOR, - DIALOG_TYPE_CONTEXT_RESPONSE + DIALOG_TYPE_NORMAL, + DIALOG_TYPE_RADIUS, + DIALOG_TYPE_GREETING, + DIALOG_TYPE_COMBAT, + DIALOG_TYPE_CONTEXT_INITIATOR, + DIALOG_TYPE_CONTEXT_RESPONSE } DialogType_t; //DialogNode_t -- Structure for Dialog Nodes typedef struct DialogNode_s - { - char alias_name[ MAX_ALIAS_NAME_LENGTH ]; - int random_flag; - int number_of_parms; - float random_percent; - DialogType_t dType; - DialogParm_t parms[ MAX_DIALOG_PARMS ]; - struct DialogNode_s *next; - } DialogNode_t; +{ + char alias_name[MAX_ALIAS_NAME_LENGTH]; + int random_flag; + int number_of_parms; + float random_percent; + DialogType_t dType; + DialogParm_t parms[MAX_DIALOG_PARMS]; + struct DialogNode_s *next; +} DialogNode_t; typedef struct - { - int entNum; - float time; - qboolean inLineOfSight; - } LineOfSight_t; +{ + int entNum; + float time; + qboolean inLineOfSight; +} LineOfSight_t; //HateListEntry_t -- Structure for the hate list typedef struct @@ -268,34 +282,34 @@ typedef struct // Helper Node Data typedef struct { - HelperNodePtr node; - int mask; - int nodeID; + HelperNodePtr node; + int mask; + int nodeID; } CurrentHelperNodeData_t; typedef struct { - HelperNodePtr node; - int mask; - int nodeID; + HelperNodePtr node; + int mask; + int nodeID; } IgnoreHelperNodeData_t; // Follow Target Data typedef struct { - EntityPtr currentFollowTarget; - EntityPtr specifiedFollowTarget; - float maxRangeIdle; - float minRangeIdle; - float maxRangeCombat; - float minRangeCombat; + EntityPtr currentFollowTarget; + EntityPtr specifiedFollowTarget; + float maxRangeIdle; + float minRangeIdle; + float maxRangeCombat; + float minRangeCombat; } FollowTargetData_t; typedef struct { int packageIndex; float currentScore; - float lastScore; + float lastScore; float lastTimeExecuted; float priority; @@ -320,210 +334,215 @@ typedef struct // StateVar -- Structure for holding StateVars typedef struct { - str varName; - str varValue; - float varTime; + str varName; + str varValue; + float varTime; } StateVar; // part_t -- Part stuff typedef struct { - EntityPtr ent; - unsigned int state_flags; + EntityPtr ent; + unsigned int state_flags; } part_t; // threadlist_t -- A Key/Value pair for all the custom threading stuff we're doing // we will eventually need to convert all those errant actor threads into this. typedef struct { - str threadType; - str threadName; + str threadType; + str threadName; } threadlist_t; //=========================================== // Enumerations //=========================================== -typedef enum{ - MOVEMENT_TYPE_NORMAL, +typedef enum +{ + MOVEMENT_TYPE_NORMAL, MOVEMENT_TYPE_ANIM } MovementType_t; //DialogMode_t -- Enumeration of Dialog Modes -typedef enum{ - DIALOG_MODE_ANXIOUS, - DIALOG_MODE_NORMAL, - DIALOG_MODE_IGNORE - } DialogMode_t; +typedef enum +{ + DIALOG_MODE_ANXIOUS, + DIALOG_MODE_NORMAL, + DIALOG_MODE_IGNORE +} DialogMode_t; // actortype_t -- Enumeration of possible actor types typedef enum - { - IS_INANIMATE, - IS_MONSTER, - IS_ENEMY, - IS_CIVILIAN, - IS_FRIEND, - IS_ANIMAL, - IS_TEAMMATE, - NUM_ACTORTYPES - } actortype_t; +{ + IS_INANIMATE, + IS_MONSTER, + IS_ENEMY, + IS_CIVILIAN, + IS_FRIEND, + IS_ANIMAL, + IS_TEAMMATE, + NUM_ACTORTYPES +} actortype_t; // targetType_t -- Enumeration of possible target types typedef enum - { - ATTACK_ANY, - ATTACK_PLAYER_ONLY, - ATTACK_ACTORS_ONLY, - ATTACK_SCRIPTED_ONLY, - ATTACK_LEVEL_INTERACTION - } targetType_t; +{ + ATTACK_ANY, + ATTACK_PLAYER_ONLY, + ATTACK_ACTORS_ONLY, + ATTACK_SCRIPTED_ONLY, + ATTACK_LEVEL_INTERACTION +} targetType_t; typedef enum - { - DEBUG_NONE, - DEBUG_STATES_ONLY, - DEBUG_STATES_BEHAVIORS, - DEBUG_ALL, - MAX_DEBUG_TYPES - } stateDebugType_t; +{ + DEBUG_NONE, + DEBUG_STATES_ONLY, + DEBUG_STATES_BEHAVIORS, + DEBUG_ALL, + MAX_DEBUG_TYPES +} stateDebugType_t; typedef enum - { - TALK_TURNTO, - TALK_HEADWATCH, - TALK_IGNORE - } talkModeStates_t; +{ + TALK_TURNTO, + TALK_HEADWATCH, + TALK_IGNORE +} talkModeStates_t; // actorflags -- Enumeration of Actor flags -typedef enum{ - ACTOR_FLAG_NOISE_HEARD, - ACTOR_FLAG_INVESTIGATING, - ACTOR_FLAG_DEATHGIB, - ACTOR_FLAG_DEATHFADE, - ACTOR_FLAG_NOCHATTER, - ACTOR_FLAG_INACTIVE, - ACTOR_FLAG_ANIM_DONE, - ACTOR_FLAG_STATE_DONE_TIME_VALID, - ACTOR_FLAG_MASTER_STATE_DONE_TIME_VALID, - ACTOR_FLAG_AI_ON, - ACTOR_FLAG_LAST_CANSEEENEMY, - ACTOR_FLAG_LAST_CANSEEENEMY_NOFOV, - ACTOR_FLAG_DIALOG_PLAYING, - ACTOR_FLAG_RADIUS_DIALOG_PLAYING, - ACTOR_FLAG_ALLOW_TALK, - ACTOR_FLAG_DAMAGE_ONCE_ON, - ACTOR_FLAG_DAMAGE_ONCE_DAMAGED, - ACTOR_FLAG_BOUNCE_OFF, - ACTOR_FLAG_NOTIFY_OTHERS_AT_DEATH, - ACTOR_FLAG_HAS_THING1, - ACTOR_FLAG_HAS_THING2, - ACTOR_FLAG_HAS_THING3, - ACTOR_FLAG_HAS_THING4, - ACTOR_FLAG_LAST_ATTACK_HIT, - ACTOR_FLAG_STARTED, - ACTOR_FLAG_ALLOW_HANGBACK, - ACTOR_FLAG_USE_GRAVITY, - ACTOR_FLAG_SPAWN_FAILED, - ACTOR_FLAG_FADING_OUT, - ACTOR_FLAG_DEATHSHRINK, - ACTOR_FLAG_DEATHSINK, - ACTOR_FLAG_STAYSOLID, - ACTOR_FLAG_STUNNED, - ACTOR_FLAG_ALLOW_FALL, - ACTOR_FLAG_FINISHED, - ACTOR_FLAG_IN_LIMBO, - ACTOR_FLAG_CAN_WALK_ON_OTHERS, - ACTOR_FLAG_PUSHABLE, - ACTOR_FLAG_LAST_TRY_TALK, - ACTOR_FLAG_TARGETABLE, - ACTOR_FLAG_IMMORTAL, - ACTOR_FLAG_TURNING_HEAD, - ACTOR_FLAG_MOVING_EYES, - ACTOR_FLAG_DIE_COMPLETELY, - ACTOR_FLAG_BLEED_AFTER_DEATH, - ACTOR_FLAG_IGNORE_STUCK_WARNING, - ACTOR_FLAG_IGNORE_OFF_GROUND_WARNING, - ACTOR_FLAG_ALLOWED_TO_KILL, - ACTOR_FLAG_TOUCH_TRIGGERS, - ACTOR_FLAG_IGNORE_WATER, - ACTOR_FLAG_NEVER_IGNORE_SOUNDS, - ACTOR_FLAG_SIMPLE_PATHFINDING, - ACTOR_FLAG_HAVE_MOVED, - ACTOR_FLAG_NO_PAIN_SOUNDS, - ACTOR_FLAG_UPDATE_BOSS_HEALTH, - ACTOR_FLAG_IGNORE_PAIN_FROM_ACTORS, - ACTOR_FLAG_DAMAGE_ALLOWED, - ACTOR_FLAG_AT_COVER_NODE, - ACTOR_FLAG_WAIT_FOR_NEW_ENEMY, - ACTOR_FLAG_TAKE_DAMAGE, - ACTOR_FLAG_USE_DAMAGESKINS, - ACTOR_FLAG_CAPTURED, - ACTOR_FLAG_TURRET_MODE, - ACTOR_FLAG_INCOMING_HITSCAN, - ACTOR_FLAG_RESPONDING_TO_HITSCAN, - ACTOR_FLAG_MELEE_HIT_WORLD, - ACTOR_FLAG_TORSO_ANIM_DONE, - ACTOR_FLAG_WEAPON_READY, - ACTOR_FLAG_DISABLED, - ACTOR_FLAG_IN_ALCOVE, - ACTOR_FLAG_IN_CONE_OF_FIRE, - ACTOR_FLAG_IN_PLAYER_CONE_OF_FIRE, - ACTOR_FLAG_PLAYER_IN_CALL_VOLUME, - ACTOR_FLAG_IN_CALL_VOLUME, - ACTOR_FLAG_OUT_OF_TORSO_RANGE, - ACTOR_FLAG_DUCKED, - ACTOR_FLAG_PRONE, - ACTOR_FLAG_SHOULD_BLINK, - ACTOR_FLAG_CRIPPLED, - ACTOR_FLAG_RETREATING, - ACTOR_FLAG_HIDDEN, - ACTOR_FLAG_FOLLOWING_IN_FORMATION, - ACTOR_FLAG_DISPLAYING_FAILURE_FX, - ACTOR_FLAG_GROUPMEMBER_INJURED, - ACTOR_FLAG_CAN_HEAL_OTHER, - ACTOR_FLAG_STRICTLY_FOLLOW_PATHS, - ACTOR_FLAG_POSTURE_ANIM_DONE, - ACTOR_FLAG_ATTACKING_ENEMY, - ACTOR_FLAG_UPDATE_HATE_WITH_ATTACKERS, - ACTOR_FLAG_LAST_CANSEEPLAYER, - ACTOR_FLAG_LAST_CANSEEPLAYER_NOFOV, - ACTOR_FLAG_MELEE_ALLOWED, - ACTOR_FLAG_PLAYING_DIALOG_ANIM, - ACTOR_FLAG_USING_HUD, - ACTOR_FLAG_FORCE_LIFEBAR, - ACTOR_FLAG_UPDATE_ACTION_LEVEL, - ACTOR_FLAG_CAN_CHANGE_ANIM, - ACTOR_FLAG_USE_FOLLOWRANGE_FOR_NODES, - ACTOR_FLAG_IMMEDIATE_ACTIVATE, - ACTOR_FLAG_CANNOT_DISINTEGRATE, - ACTOR_FLAG_CANNOT_USE, - ACTOR_FLAG_CANNOT_FREEZE, +typedef enum +{ + ACTOR_FLAG_NOISE_HEARD, + ACTOR_FLAG_INVESTIGATING, + ACTOR_FLAG_DEATHGIB, + ACTOR_FLAG_DEATHFADE, + ACTOR_FLAG_NOCHATTER, + ACTOR_FLAG_INACTIVE, + ACTOR_FLAG_ANIM_DONE, + ACTOR_FLAG_STATE_DONE_TIME_VALID, + ACTOR_FLAG_MASTER_STATE_DONE_TIME_VALID, + ACTOR_FLAG_AI_ON, + ACTOR_FLAG_LAST_CANSEEENEMY, + ACTOR_FLAG_LAST_CANSEEENEMY_NOFOV, + ACTOR_FLAG_DIALOG_PLAYING, + ACTOR_FLAG_RADIUS_DIALOG_PLAYING, + ACTOR_FLAG_ALLOW_TALK, + ACTOR_FLAG_DAMAGE_ONCE_ON, + ACTOR_FLAG_DAMAGE_ONCE_DAMAGED, + ACTOR_FLAG_BOUNCE_OFF, + ACTOR_FLAG_NOTIFY_OTHERS_AT_DEATH, + ACTOR_FLAG_HAS_THING1, + ACTOR_FLAG_HAS_THING2, + ACTOR_FLAG_HAS_THING3, + ACTOR_FLAG_HAS_THING4, + ACTOR_FLAG_LAST_ATTACK_HIT, + ACTOR_FLAG_STARTED, + ACTOR_FLAG_ALLOW_HANGBACK, + ACTOR_FLAG_USE_GRAVITY, + ACTOR_FLAG_SPAWN_FAILED, + ACTOR_FLAG_FADING_OUT, + ACTOR_FLAG_DEATHSHRINK, + ACTOR_FLAG_DEATHSINK, + ACTOR_FLAG_STAYSOLID, + ACTOR_FLAG_STUNNED, + ACTOR_FLAG_ALLOW_FALL, + ACTOR_FLAG_FINISHED, + ACTOR_FLAG_IN_LIMBO, + ACTOR_FLAG_CAN_WALK_ON_OTHERS, + ACTOR_FLAG_PUSHABLE, + ACTOR_FLAG_LAST_TRY_TALK, + ACTOR_FLAG_TARGETABLE, + ACTOR_FLAG_IMMORTAL, + ACTOR_FLAG_TURNING_HEAD, + ACTOR_FLAG_MOVING_EYES, + ACTOR_FLAG_DIE_COMPLETELY, + ACTOR_FLAG_BLEED_AFTER_DEATH, + ACTOR_FLAG_IGNORE_STUCK_WARNING, + ACTOR_FLAG_IGNORE_OFF_GROUND_WARNING, + ACTOR_FLAG_ALLOWED_TO_KILL, + ACTOR_FLAG_TOUCH_TRIGGERS, + ACTOR_FLAG_IGNORE_WATER, + ACTOR_FLAG_NEVER_IGNORE_SOUNDS, + ACTOR_FLAG_SIMPLE_PATHFINDING, + ACTOR_FLAG_HAVE_MOVED, + ACTOR_FLAG_NO_PAIN_SOUNDS, + ACTOR_FLAG_UPDATE_BOSS_HEALTH, + ACTOR_FLAG_IGNORE_PAIN_FROM_ACTORS, + ACTOR_FLAG_DAMAGE_ALLOWED, + ACTOR_FLAG_AT_COVER_NODE, + ACTOR_FLAG_WAIT_FOR_NEW_ENEMY, + ACTOR_FLAG_TAKE_DAMAGE, + ACTOR_FLAG_USE_DAMAGESKINS, + ACTOR_FLAG_CAPTURED, + ACTOR_FLAG_TURRET_MODE, + ACTOR_FLAG_INCOMING_HITSCAN, + ACTOR_FLAG_RESPONDING_TO_HITSCAN, + ACTOR_FLAG_MELEE_HIT_WORLD, + ACTOR_FLAG_TORSO_ANIM_DONE, + ACTOR_FLAG_WEAPON_READY, + ACTOR_FLAG_DISABLED, + ACTOR_FLAG_IN_ALCOVE, + ACTOR_FLAG_IN_CONE_OF_FIRE, + ACTOR_FLAG_IN_PLAYER_CONE_OF_FIRE, + ACTOR_FLAG_PLAYER_IN_CALL_VOLUME, + ACTOR_FLAG_IN_CALL_VOLUME, + ACTOR_FLAG_OUT_OF_TORSO_RANGE, + ACTOR_FLAG_DUCKED, + ACTOR_FLAG_PRONE, + ACTOR_FLAG_SHOULD_BLINK, + ACTOR_FLAG_CRIPPLED, + ACTOR_FLAG_RETREATING, + ACTOR_FLAG_HIDDEN, + ACTOR_FLAG_FOLLOWING_IN_FORMATION, + ACTOR_FLAG_DISPLAYING_FAILURE_FX, + ACTOR_FLAG_GROUPMEMBER_INJURED, + ACTOR_FLAG_CAN_HEAL_OTHER, + ACTOR_FLAG_STRICTLY_FOLLOW_PATHS, + ACTOR_FLAG_POSTURE_ANIM_DONE, + ACTOR_FLAG_ATTACKING_ENEMY, + ACTOR_FLAG_UPDATE_HATE_WITH_ATTACKERS, + ACTOR_FLAG_LAST_CANSEEPLAYER, + ACTOR_FLAG_LAST_CANSEEPLAYER_NOFOV, + ACTOR_FLAG_MELEE_ALLOWED, + ACTOR_FLAG_PLAYING_DIALOG_ANIM, + ACTOR_FLAG_USING_HUD, + ACTOR_FLAG_FORCE_LIFEBAR, + ACTOR_FLAG_UPDATE_ACTION_LEVEL, + ACTOR_FLAG_CAN_CHANGE_ANIM, + ACTOR_FLAG_USE_FOLLOWRANGE_FOR_NODES, + ACTOR_FLAG_IMMEDIATE_ACTIVATE, + ACTOR_FLAG_CANNOT_DISINTEGRATE, + ACTOR_FLAG_CANNOT_USE, + ACTOR_FLAG_CANNOT_FREEZE, - ACTOR_FLAG_MAX - - } ActorFlags; + ACTOR_FLAG_MAX + +} ActorFlags; -typedef enum { - NOTIFY_FLAG_DAMAGED, - NOTIFY_FLAG_KILLED, - NOTIFY_FLAG_SPOTTED_ENEMY, +typedef enum +{ + NOTIFY_FLAG_DAMAGED, + NOTIFY_FLAG_KILLED, + NOTIFY_FLAG_SPOTTED_ENEMY, - NOTIFY_FLAG_MAX - } NotifyFlags; + NOTIFY_FLAG_MAX +} NotifyFlags; -typedef enum { - MOVEMENT_STYLE_NONE, - MOVEMENT_STYLE_WALK, - MOVEMENT_STYLE_RUN, +typedef enum +{ + MOVEMENT_STYLE_NONE, + MOVEMENT_STYLE_WALK, + MOVEMENT_STYLE_RUN, - MOVEMENT_STYLE_MAX - } MovementStyle; + MOVEMENT_STYLE_MAX +} MovementStyle; //======================================== diff --git a/dlls/game/actorstrategies.cpp b/dlls/game/actorstrategies.cpp index b1a2598..33fc249 100644 --- a/dlls/game/actorstrategies.cpp +++ b/dlls/game/actorstrategies.cpp @@ -460,7 +460,7 @@ void DefaultThink::Think( Actor &actor ) if ( actor.flags & FlagImmobile ) { // Update boss health if necessary - if ( (actor.GetActorFlag( ACTOR_FLAG_UPDATE_BOSS_HEALTH ) && actor.max_boss_health && ( actor.mode == ACTOR_MODE_AI )) || actor.GetActorFlag(ACTOR_FLAG_FORCE_LIFEBAR) ) + if ( (actor.GetActorFlag( ACTOR_FLAG_UPDATE_BOSS_HEALTH ) && actor.max_boss_health && ( actor.mode == ActorModeAi )) || actor.GetActorFlag(ACTOR_FLAG_FORCE_LIFEBAR) ) UpdateBossHealth( actor ); if ( actor.statemap ) @@ -471,7 +471,7 @@ void DefaultThink::Think( Actor &actor ) } // Update boss health if necessary - if ( (actor.GetActorFlag( ACTOR_FLAG_UPDATE_BOSS_HEALTH ) && actor.max_boss_health && ( actor.mode == ACTOR_MODE_AI )) || actor.GetActorFlag(ACTOR_FLAG_FORCE_LIFEBAR) ) + if ( (actor.GetActorFlag( ACTOR_FLAG_UPDATE_BOSS_HEALTH ) && actor.max_boss_health && ( actor.mode == ActorModeAi )) || actor.GetActorFlag(ACTOR_FLAG_FORCE_LIFEBAR) ) UpdateBossHealth( actor ); if ( actor.postureController ) diff --git a/dlls/game/behavior.cpp b/dlls/game/behavior.cpp index 6ff2832..7aa1534 100644 --- a/dlls/game/behavior.cpp +++ b/dlls/game/behavior.cpp @@ -170,7 +170,7 @@ BehaviorReturnCode_t Idle::Evaluate if ( nexttwitch < level.time ) { self.chattime += 10.0f; - self.AddStateFlag( STATE_FLAG_TWITCH ); + self.AddStateFlag( StateFlagTwitch ); return BEHAVIOR_EVALUATING; } else @@ -214,7 +214,7 @@ void Pain::SetPainAnim // Determine which pain type to play - if ( new_pain_type == PAIN_SMALL ) + if ( new_pain_type == PainSmall ) anim_name = "pain_small"; else anim_name = "pain"; @@ -225,7 +225,7 @@ void Pain::SetPainAnim if ( !self.animate->HasAnim( anim_name.c_str() ) ) { - if ( new_pain_type == PAIN_SMALL ) + if ( new_pain_type == PainSmall ) anim_name = "pain_small1"; else anim_name = "pain1"; @@ -257,7 +257,7 @@ int Pain::GetNumberOfPainAnims // Determine base animation name - if ( new_pain_type == PAIN_SMALL ) + if ( new_pain_type == PainSmall ) anim_name = "pain_small"; else anim_name = "pain"; @@ -290,18 +290,18 @@ void Pain::Begin // Figure out which type of pain to do - if ( self.pain_type == PAIN_SMALL ) - SetPainAnim( self, PAIN_SMALL, pain_anim_number ); + if ( self.pain_type == PainSmall ) + SetPainAnim( self, PainSmall, pain_anim_number ); else - SetPainAnim( self, PAIN_BIG, pain_anim_number ); + SetPainAnim( self, PainBig, pain_anim_number ); current_pain_type = self.pain_type; number_of_pains = 1; // Make sure we don't have pain any more - self.state_flags &= ~STATE_FLAG_SMALL_PAIN; - self.state_flags &= ~STATE_FLAG_IN_PAIN; + self.state_flags &= ~StateFlagSmallPain; + self.state_flags &= ~StateFlagInPain; max_pains = (int)G_Random( 4 ) + 4; } @@ -322,34 +322,34 @@ BehaviorReturnCode_t Pain::Evaluate { str anim_name; - if ( self.state_flags & STATE_FLAG_SMALL_PAIN ) + if ( self.state_flags & StateFlagSmallPain ) { // See if we should play another pain animation if ( ( self.means_of_death != MOD_FIRE ) && ( self.means_of_death != MOD_ON_FIRE ) && ( self.means_of_death != MOD_FIRE_BLOCKABLE ) ) { - if ( ( self.pain_type == PAIN_SMALL ) && ( current_pain_type == PAIN_SMALL ) && ( number_of_pains < max_pains ) ) + if ( ( self.pain_type == PainSmall ) && ( current_pain_type == PainSmall ) && ( number_of_pains < max_pains ) ) { pain_anim_number++; number_of_pains++; - SetPainAnim( self, PAIN_SMALL, pain_anim_number ); + SetPainAnim( self, PainSmall, pain_anim_number ); } - else if ( self.pain_type == PAIN_BIG ) + else if ( self.pain_type == PainBig ) { pain_anim_number++; - current_pain_type = PAIN_BIG; + current_pain_type = PainBig; - SetPainAnim( self, PAIN_BIG, pain_anim_number ); + SetPainAnim( self, PainBig, pain_anim_number ); } } // Reset pain stuff - self.state_flags &= ~STATE_FLAG_SMALL_PAIN; - self.state_flags &= ~STATE_FLAG_IN_PAIN; + self.state_flags &= ~StateFlagSmallPain; + self.state_flags &= ~StateFlagInPain; } // If the pain animation has finished, then we are done @@ -949,9 +949,9 @@ void HeadWatch::Begin ) { - self.SetControllerTag( ACTOR_HEAD_TAG, gi.Tag_NumForName( self.edict->s.modelindex, "Bip01 Head" ) ); + self.SetControllerTag( ActorHeadTag, gi.Tag_NumForName( self.edict->s.modelindex, "Bip01 Head" ) ); - current_head_angles = self.GetControllerAngles( ACTOR_HEAD_TAG ); + current_head_angles = self.GetControllerAngles( ActorHeadTag ); self.SetActorFlag( ACTOR_FLAG_TURNING_HEAD, true ); } @@ -1048,7 +1048,7 @@ BehaviorReturnCode_t HeadWatch::Evaluate { if( forever ) { - self.SetControllerAngles( ACTOR_HEAD_TAG, current_head_angles ); + self.SetControllerAngles( ActorHeadTag, current_head_angles ); return BEHAVIOR_EVALUATING; } else @@ -1105,7 +1105,7 @@ BehaviorReturnCode_t HeadWatch::Evaluate else if ( change[PITCH] < -max_speed ) angles_diff[PITCH] = current_head_angles[PITCH] - max_speed; */ - self.SetControllerAngles( ACTOR_HEAD_TAG, angles_diff ); + self.SetControllerAngles( ActorHeadTag, angles_diff ); self.real_head_pitch = angles_diff[PITCH]; current_head_angles = angles_diff; @@ -1137,7 +1137,7 @@ void HeadWatch::End { // Snap head back into position if we have lost our target or we are doing a resethead - self.SetControllerAngles( ACTOR_HEAD_TAG, vec_zero ); + self.SetControllerAngles( ActorHeadTag, vec_zero ); self.real_head_pitch = 0; self.SetActorFlag( ACTOR_FLAG_TURNING_HEAD, false ); @@ -1196,9 +1196,9 @@ void HeadWatchEnemy::Begin ) { - self.SetControllerTag( ACTOR_HEAD_TAG, gi.Tag_NumForName( self.edict->s.modelindex, "Bip01 Head" ) ); + self.SetControllerTag( ActorHeadTag, gi.Tag_NumForName( self.edict->s.modelindex, "Bip01 Head" ) ); - current_head_angles = self.GetControllerAngles( ACTOR_HEAD_TAG ); + current_head_angles = self.GetControllerAngles( ActorHeadTag ); self.SetActorFlag( ACTOR_FLAG_TURNING_HEAD, true ); @@ -1223,11 +1223,11 @@ BehaviorReturnCode_t HeadWatchEnemy::Evaluate // Get our Torso Angles - self.SetControllerTag( ACTOR_TORSO_TAG , gi.Tag_NumForName( self.edict->s.modelindex, "Bip01 Spine1" ) ); - current_torso_angles = self.GetControllerAngles( ACTOR_TORSO_TAG ); + self.SetControllerTag( ActorTorsoTag , gi.Tag_NumForName( self.edict->s.modelindex, "Bip01 Spine1" ) ); + current_torso_angles = self.GetControllerAngles( ActorTorsoTag ); //Reset our Controller Tag - self.SetControllerTag( ACTOR_HEAD_TAG, gi.Tag_NumForName( self.edict->s.modelindex, "Bip01 Head" ) ); + self.SetControllerTag( ActorHeadTag, gi.Tag_NumForName( self.edict->s.modelindex, "Bip01 Head" ) ); if ( !ent_to_watch ) @@ -1330,8 +1330,8 @@ BehaviorReturnCode_t HeadWatchEnemy::Evaluate FinalAngles = angles_diff; FinalAngles[YAW] = angles_diff[YAW] - current_torso_angles[YAW]; - //self.SetControllerAngles( ACTOR_HEAD_TAG, angles_diff ); - self.SetControllerAngles( ACTOR_HEAD_TAG, FinalAngles ); + //self.SetControllerAngles( ActorHeadTag, angles_diff ); + self.SetControllerAngles( ActorHeadTag, FinalAngles ); self.real_head_pitch = angles_diff[PITCH]; current_head_angles = angles_diff; @@ -1367,7 +1367,7 @@ void HeadWatchEnemy::End { // Snap head back into position if we have lost our target or we are doing a resethead - self.SetControllerAngles( ACTOR_HEAD_TAG, vec_zero ); + self.SetControllerAngles( ActorHeadTag, vec_zero ); self.real_head_pitch = 0; self.SetActorFlag( ACTOR_FLAG_TURNING_HEAD, false ); @@ -1429,12 +1429,12 @@ void EyeWatch::Begin ) { - self.SetControllerTag( ACTOR_LEYE_TAG, gi.Tag_NumForName( self.edict->s.modelindex, "Face eyeballL" ) ); - self.SetControllerTag( ACTOR_REYE_TAG, gi.Tag_NumForName( self.edict->s.modelindex, "Face eyeballR" ) ); + self.SetControllerTag( ActorLeyeTag, gi.Tag_NumForName( self.edict->s.modelindex, "Face eyeballL" ) ); + self.SetControllerTag( ActorReyeTag, gi.Tag_NumForName( self.edict->s.modelindex, "Face eyeballR" ) ); - current_left_eye_angles = self.GetControllerAngles( ACTOR_LEYE_TAG ); - current_right_eye_angles = self.GetControllerAngles( ACTOR_REYE_TAG ); + current_left_eye_angles = self.GetControllerAngles( ActorLeyeTag ); + current_right_eye_angles = self.GetControllerAngles( ActorReyeTag ); self.SetActorFlag( ACTOR_FLAG_MOVING_EYES, true ); } @@ -1535,8 +1535,8 @@ BehaviorReturnCode_t EyeWatch::Evaluate else if ( change[PITCH] < -max_speed ) angles_diff[PITCH] = current_left_eye_angles[PITCH] - max_speed; - self.SetControllerAngles( ACTOR_LEYE_TAG, angles_diff ); - self.SetControllerAngles( ACTOR_REYE_TAG, angles_diff ); + self.SetControllerAngles( ActorLeyeTag, angles_diff ); + self.SetControllerAngles( ActorReyeTag, angles_diff ); current_left_eye_angles = angles_diff; current_right_eye_angles = angles_diff; @@ -1561,8 +1561,8 @@ void EyeWatch::End { // Snap head back into position if we have lost our target or we are doing a resethead - self.SetControllerAngles( ACTOR_LEYE_TAG, vec_zero ); - self.SetControllerAngles( ACTOR_REYE_TAG, vec_zero ); + self.SetControllerAngles( ActorLeyeTag, vec_zero ); + self.SetControllerAngles( ActorReyeTag, vec_zero ); self.SetActorFlag( ACTOR_FLAG_MOVING_EYES, false ); } @@ -1622,12 +1622,12 @@ void EyeWatchEnemy::Begin ) { - self.SetControllerTag( ACTOR_LEYE_TAG, gi.Tag_NumForName( self.edict->s.modelindex, "Face eyeballL" ) ); - self.SetControllerTag( ACTOR_REYE_TAG, gi.Tag_NumForName( self.edict->s.modelindex, "Face eyeballR" ) ); + self.SetControllerTag( ActorLeyeTag, gi.Tag_NumForName( self.edict->s.modelindex, "Face eyeballL" ) ); + self.SetControllerTag( ActorReyeTag, gi.Tag_NumForName( self.edict->s.modelindex, "Face eyeballR" ) ); - current_left_eye_angles = self.GetControllerAngles( ACTOR_LEYE_TAG ); - current_right_eye_angles = self.GetControllerAngles( ACTOR_REYE_TAG ); + current_left_eye_angles = self.GetControllerAngles( ActorLeyeTag ); + current_right_eye_angles = self.GetControllerAngles( ActorReyeTag ); self.SetActorFlag( ACTOR_FLAG_MOVING_EYES, true ); } @@ -1735,8 +1735,8 @@ BehaviorReturnCode_t EyeWatchEnemy::Evaluate else if ( change[PITCH] < -max_speed ) angles_diff[PITCH] = current_left_eye_angles[PITCH] - max_speed; - self.SetControllerAngles( ACTOR_LEYE_TAG, angles_diff ); - self.SetControllerAngles( ACTOR_REYE_TAG, angles_diff ); + self.SetControllerAngles( ActorLeyeTag, angles_diff ); + self.SetControllerAngles( ActorReyeTag, angles_diff ); //self.real_head_pitch = angles_diff[PITCH]; current_left_eye_angles = angles_diff; @@ -1763,8 +1763,8 @@ void EyeWatchEnemy::End //if ( !ent_to_watch ) // { - self.SetControllerAngles( ACTOR_LEYE_TAG, vec_zero ); - self.SetControllerAngles( ACTOR_REYE_TAG, vec_zero ); + self.SetControllerAngles( ActorLeyeTag, vec_zero ); + self.SetControllerAngles( ActorReyeTag, vec_zero ); //self.real_head_pitch = 0; // } @@ -1911,9 +1911,9 @@ void TorsoTurn::Begin { Vector controller_angles; - self.SetControllerTag( ACTOR_TORSO_TAG, gi.Tag_NumForName( self.edict->s.modelindex, "Bip01 Spine1" ) ); + self.SetControllerTag( ActorTorsoTag, gi.Tag_NumForName( self.edict->s.modelindex, "Bip01 Spine1" ) ); - controller_angles = self.GetControllerAngles( ACTOR_TORSO_TAG ); + controller_angles = self.GetControllerAngles( ActorTorsoTag ); current_yaw = controller_angles[YAW]; current_pitch = controller_angles[PITCH]; @@ -2048,7 +2048,7 @@ BehaviorReturnCode_t TorsoTurn::Evaluate // Set our new angles - self.SetControllerAngles( ACTOR_TORSO_TAG, new_angles ); + self.SetControllerAngles( ActorTorsoTag, new_angles ); current_yaw = yaw_diff; current_pitch = pitch_diff; @@ -2067,7 +2067,7 @@ void TorsoTurn::End ) { - self.SetControllerAngles( ACTOR_TORSO_TAG, vec_zero ); + self.SetControllerAngles( ActorTorsoTag, vec_zero ); } @@ -2141,9 +2141,9 @@ void TorsoWatchEnemy::Begin { Vector controller_angles; - self.SetControllerTag( ACTOR_TORSO_TAG, gi.Tag_NumForName( self.edict->s.modelindex, "Bip01 Spine1" ) ); + self.SetControllerTag( ActorTorsoTag, gi.Tag_NumForName( self.edict->s.modelindex, "Bip01 Spine1" ) ); - controller_angles = self.GetControllerAngles( ACTOR_TORSO_TAG ); + controller_angles = self.GetControllerAngles( ActorTorsoTag ); current_yaw = controller_angles[YAW]; current_pitch = controller_angles[PITCH]; @@ -2205,7 +2205,7 @@ BehaviorReturnCode_t TorsoWatchEnemy::Evaluate /* Vector controller_angles; - controller_angles = self.GetControllerAngles( ACTOR_TORSO_TAG ); + controller_angles = self.GetControllerAngles( ActorTorsoTag ); current_yaw = controller_angles[YAW]; current_pitch = controller_angles[PITCH]; @@ -2292,7 +2292,7 @@ BehaviorReturnCode_t TorsoWatchEnemy::Evaluate // Set our new angles - self.SetControllerAngles( ACTOR_TORSO_TAG, new_angles ); + self.SetControllerAngles( ActorTorsoTag, new_angles ); current_yaw = yaw_diff; current_pitch = pitch_diff; @@ -2318,7 +2318,7 @@ void TorsoWatchEnemy::End self.movementSubsystem->setMovingBackwards( false ); if ( reset ) - self.SetControllerAngles( ACTOR_TORSO_TAG, vec_zero ); + self.SetControllerAngles( ActorTorsoTag, vec_zero ); } /**************************************************************************** @@ -6165,7 +6165,7 @@ BehaviorReturnCode_t FlyDive::Evaluate //hit_entity->Damage( &self, &self, damage, Vector (0, 0, 0), Vector (0, 0, 0), Vector (0, 0, 0), 0, 0, MOD_CRUSH ); dir.normalize(); hit_entity->Damage( &self, &self, damage, self.centroid, dir, vec_zero, 0, 0, MOD_CRUSH ); - self.AddStateFlag( STATE_FLAG_MELEE_HIT ); + self.AddStateFlag( StateFlagMeleeHit ); stuck = false; } } @@ -6179,7 +6179,7 @@ BehaviorReturnCode_t FlyDive::Evaluate self.setAngles( self.angles ); if ( stuck ) - self.AddStateFlag( STATE_FLAG_STUCK ); + self.AddStateFlag( StateFlagStuck ); return BEHAVIOR_SUCCESS; } @@ -6322,7 +6322,7 @@ BehaviorReturnCode_t FlyCharge::Evaluate //hit_entity->Damage( &self, &self, damage, Vector (0, 0, 0), Vector (0, 0, 0), Vector (0, 0, 0), 0, 0, MOD_CRUSH ); dir.normalize(); hit_entity->Damage( &self, &self, damage, self.centroid, dir, vec_zero, 0, 0, MOD_CRUSH ); - self.AddStateFlag( STATE_FLAG_MELEE_HIT ); + self.AddStateFlag( StateFlagMeleeHit ); stuck = false; } } @@ -6336,7 +6336,7 @@ BehaviorReturnCode_t FlyCharge::Evaluate self.setAngles( self.angles ); if ( stuck ) - self.AddStateFlag( STATE_FLAG_STUCK ); + self.AddStateFlag( StateFlagStuck ); return BEHAVIOR_SUCCESS; } @@ -9033,7 +9033,7 @@ BehaviorReturnCode_t ShockWater::Evaluate else { // Shock head - center_actor->AddStateFlag( STATE_FLAG_IN_PAIN ); + center_actor->AddStateFlag( StateFlagInPain ); center_actor->SpawnEffect( "fx_elecstrike.tik", center_actor->origin, vec_zero, 2.0f ); center_actor->Sound( "sound/weapons/sword/electric/hitmix2.wav", 0, 1.0f, 500.0f ); @@ -10897,7 +10897,7 @@ BehaviorReturnCode_t GhostAttack::Evaluate if ( real_attack ) { success = MeleeAttack( start, end, 7.5f, &self, MOD_LIFEDRAIN, 32.0f, 0.0f, 64.0f, 0.0f ); - self.AddStateFlag( STATE_FLAG_MELEE_HIT ); + self.AddStateFlag( StateFlagMeleeHit ); } else success = false; diff --git a/dlls/game/behaviors_general.cpp b/dlls/game/behaviors_general.cpp index 4c92325..7a94e5c 100644 --- a/dlls/game/behaviors_general.cpp +++ b/dlls/game/behaviors_general.cpp @@ -574,62 +574,62 @@ BehaviorReturnCode_t GotoEntity::Evaluate( Actor &self ) case Steering::FAILED: self.SetAnim( "idle" ); SetFailureReason( "Steering returned FAILED" ); - self.AddStateFlag( STATE_FLAG_STEERING_FAILED ); + self.AddStateFlag( StateFlagSteeringFailed ); return BEHAVIOR_FAILED; break; case Steering::FAILED_BLOCKED_BY_ENEMY: self.SetAnim( "idle" ); SetFailureReason( "Steering returned BLOCKED_BY_ENEMY" ); - self.AddStateFlag( STATE_FLAG_STEERING_FAILED ); + self.AddStateFlag( StateFlagSteeringFailed ); return BEHAVIOR_FAILED_STEERING_BLOCKED_BY_ENEMY; break; case Steering::FAILED_BLOCKED_BY_CIVILIAN: self.SetAnim( "idle" ); SetFailureReason( "Steering returned BLOCKED_BY_CIVILIAN" ); - self.AddStateFlag( STATE_FLAG_STEERING_FAILED ); + self.AddStateFlag( StateFlagSteeringFailed ); return BEHAVIOR_FAILED_STEERING_BLOCKED_BY_CIVILIAN; break; case Steering::FAILED_BLOCKED_BY_FRIEND: self.SetAnim( "idle" ); SetFailureReason( "Steering returned BLOCKED_BY_FRIEND" ); - self.AddStateFlag( STATE_FLAG_STEERING_FAILED ); + self.AddStateFlag( StateFlagSteeringFailed ); return BEHAVIOR_FAILED_STEERING_BLOCKED_BY_FRIEND; break; case Steering::FAILED_BLOCKED_BY_TEAMMATE: self.SetAnim( "idle" ); SetFailureReason( "Steering returned BLOCKED_BY_TEAMMATE" ); - self.AddStateFlag( STATE_FLAG_STEERING_FAILED ); + self.AddStateFlag( StateFlagSteeringFailed ); return BEHAVIOR_FAILED_STEERING_BLOCKED_BY_TEAMMATE; break; case Steering::FAILED_BLOCKED_BY_WORLD: self.SetAnim( "idle" ); SetFailureReason( "Steering returned BLOCKED_BY_WORLD" ); - self.AddStateFlag( STATE_FLAG_STEERING_FAILED ); + self.AddStateFlag( StateFlagSteeringFailed ); return BEHAVIOR_FAILED_STEERING_BLOCKED_BY_WORLD; break; case Steering::FAILED_BLOCKED_BY_DOOR: self.SetAnim( "idle" ); SetFailureReason( "Steering returned BLOCKED_BY_DOOR" ); - self.AddStateFlag( STATE_FLAG_STEERING_FAILED ); + self.AddStateFlag( StateFlagSteeringFailed ); return BEHAVIOR_FAILED_STEERING_BLOCKED_BY_DOOR; break; case Steering::FAILED_CANNOT_GET_TO_PATH: - self.AddStateFlag( STATE_FLAG_NO_PATH ); + self.AddStateFlag( StateFlagNoPath ); self.SetAnim( "idle" ); SetFailureReason( "Steering returned CANNOT_GET_TO_PATH" ); - self.AddStateFlag( STATE_FLAG_STEERING_FAILED ); + self.AddStateFlag( StateFlagSteeringFailed ); return BEHAVIOR_FAILED_STEERING_CANNOT_GET_TO_PATH; break; case Steering::FAILED_NO_PATH: - self.AddStateFlag( STATE_FLAG_NO_PATH ); + self.AddStateFlag( StateFlagNoPath ); /* if ( !self.GetActorFlag(ACTOR_FLAG_DISPLAYING_FAILURE_FX) ) { @@ -643,7 +643,7 @@ BehaviorReturnCode_t GotoEntity::Evaluate( Actor &self ) self.SetAnim( "idle" ); SetFailureReason( "Steering returned NO_PATH" ); - self.AddStateFlag( STATE_FLAG_STEERING_FAILED ); + self.AddStateFlag( StateFlagSteeringFailed ); return BEHAVIOR_FAILED_STEERING_NO_PATH; break; @@ -777,7 +777,7 @@ BehaviorReturnCode_t GotoPoint::Evaluate( Actor &self ) unsigned int chaseResult; //E3 2002 HACK LOVIN' - if ( self.state_flags & STATE_FLAG_STUCK ) + if ( self.state_flags & StateFlagStuck ) { self.SetAnim( "idle" ); SetFailureReason( "I'm stuck!!!!!!" ); @@ -840,13 +840,13 @@ BehaviorReturnCode_t GotoPoint::Evaluate( Actor &self ) break; case Steering::FAILED_CANNOT_GET_TO_PATH: - self.AddStateFlag( STATE_FLAG_NO_PATH ); + self.AddStateFlag( StateFlagNoPath ); self.SetAnim( "idle" ); return BEHAVIOR_FAILED_STEERING_CANNOT_GET_TO_PATH; break; case Steering::FAILED_NO_PATH: - self.AddStateFlag( STATE_FLAG_NO_PATH ); + self.AddStateFlag( StateFlagNoPath ); self.SetAnim( "idle" ); return BEHAVIOR_FAILED_STEERING_NO_PATH; break; diff --git a/dlls/game/player.cpp b/dlls/game/player.cpp index 58ebb97..d13470c 100644 --- a/dlls/game/player.cpp +++ b/dlls/game/player.cpp @@ -4570,13 +4570,13 @@ void Player::showObjectInfo() sprintf(addstr, "Think is OFF\n" ); desc += addstr; - if ( act->mode == ACTOR_MODE_IDLE ) + if ( act->mode == ActorModeIdle ) sprintf(addstr, "Mode: IDLE\n" ); - else if ( act->mode == ACTOR_MODE_AI ) + else if ( act->mode == ActorModeAi ) sprintf(addstr, "Mode: AI\n" ); - else if ( act->mode == ACTOR_MODE_SCRIPT ) + else if ( act->mode == ActorModeScript ) sprintf(addstr, "Mode: SCRIPT\n" ); - else if ( act->mode == ACTOR_MODE_TALK ) + else if ( act->mode == ActorModeTalk ) sprintf(addstr, "Mode: TALK\n" ); desc += addstr; diff --git a/dlls/game/sentient.cpp b/dlls/game/sentient.cpp index 1769c6d..b42fa0f 100644 --- a/dlls/game/sentient.cpp +++ b/dlls/game/sentient.cpp @@ -2164,7 +2164,7 @@ void Sentient::ArmorDamage( float damage, Entity *inflictor, Entity *attacker, c { Actor *act = (Actor *)this; - if ( ( act->state_flags & STATE_FLAG_SMALL_PAIN ) && ( meansofdeath == MOD_ON_FIRE || Immune( meansofdeath ) ) ) + if ( ( act->state_flags & StateFlagSmallPain ) && ( meansofdeath == MOD_ON_FIRE || Immune( meansofdeath ) ) ) set_means_of_death = false; } @@ -2423,7 +2423,7 @@ void Sentient::ArmorDamage( float damage, Entity *inflictor, Entity *attacker, c if ( this->isSubclassOf( Actor ) ) { Actor *act = ( Actor * )this; - act->AddStateFlag( STATE_FLAG_BLOCKED_HIT ); + act->AddStateFlag( StateFlagBlockedHit ); } WeaponEffectsAndSound( weapon, "Blocked", position ); @@ -4798,7 +4798,7 @@ void Sentient::CheckDamageThreshold( float damageValue ) { Actor *actor; actor = (Actor*)this; - actor->AddStateFlag(STATE_FLAG_DAMAGE_THRESHOLD_EXCEEDED); + actor->AddStateFlag(StateFlagDamageThresholdExceeded); } //Clear out our structure diff --git a/dlls/game/snipeEnemy.cpp b/dlls/game/snipeEnemy.cpp index d9a846e..8b73ad2 100644 --- a/dlls/game/snipeEnemy.cpp +++ b/dlls/game/snipeEnemy.cpp @@ -226,7 +226,7 @@ BehaviorReturnCode_t SnipeEnemy::Evaluate( Actor & ) //--------------------------------------------------------------------- case SNIPE_AIM_AND_FIRE_SUCCESS: //--------------------------------------------------------------------- - _self->SetControllerAngles( ACTOR_TORSO_TAG, vec_zero ); + _self->SetControllerAngles( ActorTorsoTag, vec_zero ); return BEHAVIOR_SUCCESS; break; @@ -267,7 +267,7 @@ void SnipeEnemy::End(Actor &) _fireWeapon.End(*_self); //gi.Printf( "TorsoAimAndFireWeapon::End()\n"); - _self->SetControllerAngles( ACTOR_TORSO_TAG, vec_zero ); + _self->SetControllerAngles( ActorTorsoTag, vec_zero ); _self->ClearTorsoAnim(); _self->SetEnemyTargeted( false ); //_self->SetAnim( _aimAnim , NULL , torso ); @@ -353,8 +353,8 @@ void SnipeEnemy::init( Actor &self ) _self = &self; //Set Our Controller Tag and set up our angles - self.SetControllerTag( ACTOR_TORSO_TAG, gi.Tag_NumForName( self.edict->s.modelindex, "Bip01 Spine1" ) ); - _currentTorsoAngles = self.GetControllerAngles( ACTOR_TORSO_TAG ); + self.SetControllerTag( ActorTorsoTag, gi.Tag_NumForName( self.edict->s.modelindex, "Bip01 Spine1" ) ); + _currentTorsoAngles = self.GetControllerAngles( ActorTorsoTag ); _animDone = false; _canAttack = true; @@ -522,7 +522,7 @@ void SnipeEnemy::LerpTorsoBySpeed( const Vector &angleDelta ) anglesDiff = angleDelta; //Reset our Controller Tag - _self->SetControllerTag( ACTOR_TORSO_TAG, gi.Tag_NumForName( _self->edict->s.modelindex, "Bip01 Spine1" ) ); + _self->SetControllerTag( ActorTorsoTag, gi.Tag_NumForName( _self->edict->s.modelindex, "Bip01 Spine1" ) ); // Make sure we don't change our head angles too much at once @@ -541,7 +541,7 @@ void SnipeEnemy::LerpTorsoBySpeed( const Vector &angleDelta ) finalAngles = anglesDiff; - _self->SetControllerAngles( ACTOR_TORSO_TAG, finalAngles ); + _self->SetControllerAngles( ActorTorsoTag, finalAngles ); _currentTorsoAngles = anglesDiff; diff --git a/dlls/game/talk.cpp b/dlls/game/talk.cpp index cf4884f..07532a9 100644 --- a/dlls/game/talk.cpp +++ b/dlls/game/talk.cpp @@ -319,7 +319,7 @@ BehaviorReturnCode_t Talk::Evaluate if ( !self.GetActorFlag( ACTOR_FLAG_DIALOG_PLAYING ) ) { mode = TALK_MODE_WAIT; - self.state_flags &= ~STATE_FLAG_USED; + self.state_flags &= ~StateFlagUsed; // Tell player to stop watching us @@ -372,7 +372,7 @@ BehaviorReturnCode_t Talk::Evaluate if ( !self.WithinDistance( ent_listening, 100.0f ) ) mode = TALK_MODE_TURN_BACK; - if ( self.state_flags & STATE_FLAG_USED ) + if ( self.state_flags & StateFlagUsed ) { mode = TALK_MODE_TURN_TO; self.SetActorFlag(ACTOR_FLAG_PLAYING_DIALOG_ANIM, false ); @@ -381,7 +381,7 @@ BehaviorReturnCode_t Talk::Evaluate angles = dir.toAngles(); yaw = angles[YAW]; - self.state_flags &= ~STATE_FLAG_USED; + self.state_flags &= ~StateFlagUsed; /* event = new Event( EV_Player_WatchActor ); event->AddEntity( &self ); diff --git a/dlls/game/torsoAimAndFireWeapon.cpp b/dlls/game/torsoAimAndFireWeapon.cpp index a617c1f..b783097 100644 --- a/dlls/game/torsoAimAndFireWeapon.cpp +++ b/dlls/game/torsoAimAndFireWeapon.cpp @@ -239,7 +239,7 @@ BehaviorReturnCode_t TorsoAimAndFireWeapon::Evaluate( Actor &self ) //--------------------------------------------------------------------- case TORSO_AIM_AND_FIRE_SUCCESS: //--------------------------------------------------------------------- - _self->SetControllerAngles( ACTOR_TORSO_TAG, vec_zero ); + _self->SetControllerAngles( ActorTorsoTag, vec_zero ); if ( _repeat ) { @@ -292,7 +292,7 @@ void TorsoAimAndFireWeapon::End(Actor &) _fireWeapon.End(*_self); //gi.Printf( "TorsoAimAndFireWeapon::End()\n"); - _self->SetControllerAngles( ACTOR_TORSO_TAG, vec_zero ); + _self->SetControllerAngles( ActorTorsoTag, vec_zero ); _self->ClearTorsoAnim(); //_self->SetAnim( _aimAnim , NULL , torso ); } @@ -377,8 +377,8 @@ void TorsoAimAndFireWeapon::init( Actor &self ) _self = &self; //Set Our Controller Tag and set up our angles - self.SetControllerTag( ACTOR_TORSO_TAG, gi.Tag_NumForName( self.edict->s.modelindex, "Bip01 Spine1" ) ); - _currentTorsoAngles = self.GetControllerAngles( ACTOR_TORSO_TAG ); + self.SetControllerTag( ActorTorsoTag, gi.Tag_NumForName( self.edict->s.modelindex, "Bip01 Spine1" ) ); + _currentTorsoAngles = self.GetControllerAngles( ActorTorsoTag ); _animDone = false; _canAttack = true; @@ -570,7 +570,7 @@ void TorsoAimAndFireWeapon::updateEnemy() } _currentEnemy = currentEnemy; - //_self->SetControllerAngles( ACTOR_TORSO_TAG, vec_zero ); + //_self->SetControllerAngles( ActorTorsoTag, vec_zero ); //gi.Printf( "TorsoAimAndFireWeapon::_turnTowardsEntity()\n"); //_self->turnTowardsEntity( _currentEnemy, 0.0f ); @@ -596,7 +596,7 @@ void TorsoAimAndFireWeapon::LerpTorsoBySpeed( const Vector &angleDelta ) anglesDiff = angleDelta; //Reset our Controller Tag - _self->SetControllerTag( ACTOR_TORSO_TAG, gi.Tag_NumForName( _self->edict->s.modelindex, "Bip01 Spine1" ) ); + _self->SetControllerTag( ActorTorsoTag, gi.Tag_NumForName( _self->edict->s.modelindex, "Bip01 Spine1" ) ); // Make sure we don't change our head angles too much at once @@ -615,7 +615,7 @@ void TorsoAimAndFireWeapon::LerpTorsoBySpeed( const Vector &angleDelta ) finalAngles = anglesDiff; - _self->SetControllerAngles( ACTOR_TORSO_TAG, finalAngles ); + _self->SetControllerAngles( ActorTorsoTag, finalAngles ); _currentTorsoAngles = anglesDiff;