From 0622ccc638877473ab610e21bd8033498844845c Mon Sep 17 00:00:00 2001 From: Giegue Date: Sun, 19 Feb 2023 15:57:07 -0300 Subject: [PATCH] Stop allied monsters from attacking the player. Part B of making MonsterMod aware of normal HL entities. --- src/dlls/combat.cpp | 9 +++----- src/dlls/hornet.cpp | 5 ++--- src/dlls/monster_api.cpp | 4 ++-- src/dlls/monster_mm.dsp | 4 ++++ src/dlls/monsters.cpp | 44 ++++++++++++++++++++++++++++------------ src/dlls/util.cpp | 20 ++++++++++++------ src/dlls/weapons.cpp | 2 +- 7 files changed, 57 insertions(+), 31 deletions(-) diff --git a/src/dlls/combat.cpp b/src/dlls/combat.cpp index 8a9bc1f..cec3f03 100644 --- a/src/dlls/combat.cpp +++ b/src/dlls/combat.cpp @@ -1154,11 +1154,8 @@ void RadiusDamage( Vector vecSrc, entvars_t *pevInflictor, entvars_t *pevAttacke } } } - else if (!UTIL_IsPlayer(pEntity)) + else { - // I'm doing really bad copypastes instead of making the code clean! - // Remind me to refactor this, this is not how this is supposed to be written! - // -Giegue edict_t *pMonster = pEntity; if ( iClassIgnore != CLASS_NONE && pMonster->v.iuser4 == iClassIgnore ) @@ -1260,7 +1257,7 @@ edict_t* CMBaseMonster :: CheckTraceHullAttack( float flDist, int iDamage, int i CMBaseMonster *pMonster = GetClassPtr((CMBaseMonster *)VARS(pEntity)); pMonster->TakeDamage( pev, pev, iDamage, iDmgType ); } - else if (!UTIL_IsPlayer(pEntity)) + else UTIL_TakeDamageExternal( pEntity, pev, pev, iDamage, iDmgType ); } @@ -1571,7 +1568,7 @@ void CMBaseEntity::FireBullets(ULONG cShots, Vector vecSrc, Vector vecDirShootin } } } - else if (!UTIL_IsPlayer(tr.pHit)) // normal game monster + else // normal game entity { edict_t *pMonster = tr.pHit; diff --git a/src/dlls/hornet.cpp b/src/dlls/hornet.cpp index db6a52e..b41edc0 100644 --- a/src/dlls/hornet.cpp +++ b/src/dlls/hornet.cpp @@ -326,11 +326,10 @@ void CMHornet :: TrackTouch ( edict_t *pOther ) } // is this NOT a player and IS a monster? - if (!UTIL_IsPlayer(pOther) && (pOther->v.euser4 != NULL)) + if (!UTIL_IsPlayer(pOther) && (pOther->v.flags & FL_MONSTER)) { CMBaseMonster *pMonster = GetClassPtr((CMBaseMonster *)VARS(pOther)); - - if ( IRelationship( pMonster ) <= R_NO ) + if ( pMonster != NULL && IRelationship( pMonster ) <= R_NO || IRelationshipByClass( pOther->v.iuser4 ) <= R_NO ) { // hit something we don't want to hurt, so turn around. diff --git a/src/dlls/monster_api.cpp b/src/dlls/monster_api.cpp index d084ec1..bdd0b25 100644 --- a/src/dlls/monster_api.cpp +++ b/src/dlls/monster_api.cpp @@ -56,8 +56,8 @@ static META_FUNCTIONS gMetaFunctionTable = plugin_info_t Plugin_info = { META_INTERFACE_VERSION, // interface version "MonsterMod", // name - "2.0", // version - "03/06/2020", // date in DD/MM/YYYY format + "3.0-dev", // version + "15/02/2023", // date in DD/MM/YYYY format "botman, Rick90, Giegue", // original authors + recreation by... "https://github.com/JulianR0/monstermod-redo", // url "MONSTER", // logtag diff --git a/src/dlls/monster_mm.dsp b/src/dlls/monster_mm.dsp index 129e886..9c3462e 100644 --- a/src/dlls/monster_mm.dsp +++ b/src/dlls/monster_mm.dsp @@ -274,6 +274,10 @@ SOURCE=.\strooper.cpp # End Source File # Begin Source File +SOURCE=.\stukabat.cpp +# End Source File +# Begin Source File + SOURCE=.\subs.cpp # End Source File # Begin Source File diff --git a/src/dlls/monsters.cpp b/src/dlls/monsters.cpp index 55a55d0..0c2fb66 100644 --- a/src/dlls/monsters.cpp +++ b/src/dlls/monsters.cpp @@ -207,7 +207,7 @@ void CMBaseMonster :: Look ( int iDistance ) } } } - else if (!UTIL_IsPlayer(pSightEnt)) + else { /* MonsterMod monster looking at a NON-MonsterMod monster */ @@ -2081,17 +2081,30 @@ edict_t *CMBaseMonster :: BestVisibleEnemy ( void ) while (edictList_index < m_edictList_count) { pEnt = m_edictList[edictList_index]; - + if ( UTIL_IsPlayer(pEnt) ) { // it's a player... - iDist = ( pEnt->v.origin - pev->origin ).Length(); - - if ( iDist <= iNearest ) + if ( UTIL_IsAlive(pEnt) ) { - iNearest = iDist; - iBestRelationship = R_NM; // player is always nemesis - pReturn = pEnt; + // repeat2 + if ( IRelationshipByClass( CLASS_PLAYER ) > iBestRelationship ) + { + iBestRelationship = IRelationshipByClass( CLASS_PLAYER ); + iNearest = ( pEnt->v.origin - pev->origin ).Length(); + pReturn = pEnt; + } + else if ( IRelationshipByClass( CLASS_PLAYER ) == iBestRelationship ) + { + iDist = ( pEnt->v.origin - pev->origin ).Length(); + + if ( iDist <= iNearest ) + { + iNearest = iDist; + iBestRelationship = IRelationshipByClass( CLASS_PLAYER ); + pReturn = pEnt; + } + } } } else if (pEnt->v.euser4 != NULL) @@ -2125,12 +2138,12 @@ edict_t *CMBaseMonster :: BestVisibleEnemy ( void ) } } } - else if (!UTIL_IsPlayer(pEnt)) + else { - // it's a game default monster... + // it's a normal game entity... if ( UTIL_IsAlive(pEnt) ) { - //repeat2 + //repeat3 if ( IRelationship( pEnt->v.iuser4 ) > iBestRelationship ) { iBestRelationship = IRelationship( pEnt->v.iuser4 ); @@ -2959,8 +2972,13 @@ BOOL CMBaseMonster :: GetEnemy ( void ) if (HasConditions(bits_COND_SEE_CLIENT) && (m_hEnemy == NULL)) { m_hEnemy = BestVisibleEnemy(); - m_hTargetEnt = m_hEnemy; - m_vecEnemyLKP = m_hEnemy->v.origin; + + // the player we've just seen might not always be our enemy + if ( m_hEnemy != NULL ) + { + m_hTargetEnt = m_hEnemy; + m_vecEnemyLKP = m_hEnemy->v.origin; + } } // remember old enemies diff --git a/src/dlls/util.cpp b/src/dlls/util.cpp index d8e9304..bc2d365 100644 --- a/src/dlls/util.cpp +++ b/src/dlls/util.cpp @@ -1540,10 +1540,10 @@ bool UTIL_IsPlayer(edict_t *pEdict) Vector UTIL_BodyTarget(edict_t *pEdict, Vector posSrc) { - if (pEdict->v.flags & FL_CLIENT) - return pEdict->v.origin + (pEdict->v.view_ofs * RANDOM_FLOAT(0.5, 1.1)); - else - return (pEdict->v.origin + ((pEdict->v.mins + pEdict->v.maxs) * 0.5)); + if (pEdict->v.flags & FL_CLIENT) + return pEdict->v.origin + (pEdict->v.view_ofs * RANDOM_FLOAT(0.5, 1.1)); + else + return (pEdict->v.origin + ((pEdict->v.mins + pEdict->v.maxs) * 0.5)); } //========================================================= @@ -1875,7 +1875,11 @@ void UTIL_TraceBleed( edict_t *pEdict, float flDamage, Vector vecDir, TraceResul if ( Bloodtr.flFraction != 1.0 ) { - UTIL_BloodDecalTrace( &Bloodtr, BLOOD_COLOR_RED ); + int bloodColor = pEdict->v.iuser3; + if ( !bloodColor ) + bloodColor = BLOOD_COLOR_RED; + + UTIL_BloodDecalTrace( &Bloodtr, bloodColor ); } } } @@ -1886,9 +1890,13 @@ void UTIL_TraceAttack( edict_t *pEdict, entvars_t *pevAttacker, float flDamage, if ( pEdict->v.takedamage ) { + int bloodColor = pEdict->v.iuser3; + if ( !bloodColor ) + bloodColor = BLOOD_COLOR_RED; + AddMultiDamage( pevAttacker, pEdict, flDamage, bitsDamageType ); - SpawnBlood(ptr->vecEndPos, BLOOD_COLOR_RED, flDamage);// a little surface blood. + SpawnBlood(ptr->vecEndPos, bloodColor, flDamage);// a little surface blood. UTIL_TraceBleed( pEdict, flDamage, vecDir, ptr, bitsDamageType ); } diff --git a/src/dlls/weapons.cpp b/src/dlls/weapons.cpp index 0a36ccb..320bf4a 100644 --- a/src/dlls/weapons.cpp +++ b/src/dlls/weapons.cpp @@ -79,7 +79,7 @@ void ApplyMultiDamage(entvars_t *pevInflictor, entvars_t *pevAttacker ) CMBaseMonster *pMonster = GetClassPtr((CMBaseMonster *)VARS(gMultiDamage.pEntity)); pMonster->TakeDamage(pevInflictor, pevAttacker, gMultiDamage.amount, gMultiDamage.type ); } - else if (!UTIL_IsPlayer(gMultiDamage.pEntity)) + else UTIL_TakeDamageExternal(gMultiDamage.pEntity, pevInflictor, pevAttacker, gMultiDamage.amount, gMultiDamage.type ); }