From 0c118de14d8871ffee8cddf5b99d15b00042ecfc Mon Sep 17 00:00:00 2001 From: puzl Date: Sat, 29 Apr 2006 15:00:23 +0000 Subject: [PATCH] o Fixed hive +use o Redemption prioritises hives under attack last. git-svn-id: https://unknownworlds.svn.cloudforge.com/ns1@436 67975925-1194-0748-b3d5-c16f83f1a3a1 --- releases/3.2.0/source/dlls/player.cpp | 77 +++++++++++++++------ releases/3.2.0/source/mod/AvHPlayer.cpp | 92 +++++++++++++++++-------- 2 files changed, 122 insertions(+), 47 deletions(-) diff --git a/releases/3.2.0/source/dlls/player.cpp b/releases/3.2.0/source/dlls/player.cpp index f3878a00..3a49c983 100644 --- a/releases/3.2.0/source/dlls/player.cpp +++ b/releases/3.2.0/source/dlls/player.cpp @@ -92,6 +92,7 @@ #include "game.h" #include "common/hltv.h" #include "mod/AvHNetworkMessages.h" +#include "util/MathUtil.h" // #define DUCKFIX @@ -1778,30 +1779,66 @@ void CBasePlayer::PlayerUse ( void ) UTIL_MakeVectors ( pev->v_angle );// so we know which way we are facing - while ((pObject = UTIL_FindEntityInSphere( pObject, pev->origin, PLAYER_SEARCH_RADIUS )) != NULL) - { - - if (pObject->ObjectCaps() & (FCAP_IMPULSE_USE | FCAP_CONTINUOUS_USE | FCAP_ONOFF_USE)) + if ( AvHGetIsAlien(this->pev->iuser3) ) { + while ((pObject = UTIL_FindEntityInSphere( pObject, pev->origin, PLAYER_SEARCH_RADIUS*3)) != NULL) { - // !!!PERFORMANCE- should this check be done on a per case basis AFTER we've determined that - // this object is actually usable? This dot is being done for every object within PLAYER_SEARCH_RADIUS - // when player hits the use key. How many objects can be in that area, anyway? (sjb) - vecLOS = (VecBModelOrigin( pObject->pev ) - (pev->origin + pev->view_ofs)); - - // This essentially moves the origin of the target to the corner nearest the player to test to see - // if it's "hull" is in the view cone - vecLOS = UTIL_ClampVectorToBox( vecLOS, pObject->pev->size * 0.5 ); - - flDot = DotProduct (vecLOS , gpGlobals->v_forward); - if (flDot > flMaxDot ) - {// only if the item is in front of the user - pClosest = pObject; - flMaxDot = flDot; -// ALERT( at_console, "%s : %f\n", STRING( pObject->pev->classname ), flDot ); + if ( pObject->pev->iuser3 != AVH_USER3_HIVE ) { + vec3_t objectLocation; + vec3_t playerLocation; + AvHSHUGetEntityLocation(pObject->entindex(), objectLocation); + AvHSHUGetEntityLocation(this->entindex(), playerLocation); + if ( VectorDistance(objectLocation, playerLocation) > PLAYER_SEARCH_RADIUS ) + continue; + } + if (pObject->ObjectCaps() & (FCAP_IMPULSE_USE | FCAP_CONTINUOUS_USE | FCAP_ONOFF_USE)) + { + // !!!PERFORMANCE- should this check be done on a per case basis AFTER we've determined that + // this object is actually usable? This dot is being done for every object within PLAYER_SEARCH_RADIUS + // when player hits the use key. How many objects can be in that area, anyway? (sjb) + vecLOS = (VecBModelOrigin( pObject->pev ) - (pev->origin + pev->view_ofs)); + + // This essentially moves the origin of the target to the corner nearest the player to test to see + // if it's "hull" is in the view cone + vecLOS = UTIL_ClampVectorToBox( vecLOS, pObject->pev->size * 0.5 ); + + flDot = DotProduct (vecLOS , gpGlobals->v_forward); + if (flDot > flMaxDot ) + {// only if the item is in front of the user + pClosest = pObject; + flMaxDot = flDot; + // ALERT( at_console, "%s : %f\n", STRING( pObject->pev->classname ), flDot ); + } + // ALERT( at_console, "%s : %f\n", STRING( pObject->pev->classname ), flDot ); } -// ALERT( at_console, "%s : %f\n", STRING( pObject->pev->classname ), flDot ); } } + else { + while ((pObject = UTIL_FindEntityInSphere( pObject, pev->origin, PLAYER_SEARCH_RADIUS )) != NULL) + { + + if (pObject->ObjectCaps() & (FCAP_IMPULSE_USE | FCAP_CONTINUOUS_USE | FCAP_ONOFF_USE)) + { + // !!!PERFORMANCE- should this check be done on a per case basis AFTER we've determined that + // this object is actually usable? This dot is being done for every object within PLAYER_SEARCH_RADIUS + // when player hits the use key. How many objects can be in that area, anyway? (sjb) + vecLOS = (VecBModelOrigin( pObject->pev ) - (pev->origin + pev->view_ofs)); + + // This essentially moves the origin of the target to the corner nearest the player to test to see + // if it's "hull" is in the view cone + vecLOS = UTIL_ClampVectorToBox( vecLOS, pObject->pev->size * 0.5 ); + + flDot = DotProduct (vecLOS , gpGlobals->v_forward); + if (flDot > flMaxDot ) + {// only if the item is in front of the user + pClosest = pObject; + flMaxDot = flDot; + // ALERT( at_console, "%s : %f\n", STRING( pObject->pev->classname ), flDot ); + } + // ALERT( at_console, "%s : %f\n", STRING( pObject->pev->classname ), flDot ); + } + } + } + pObject = pClosest; // Found an object diff --git a/releases/3.2.0/source/mod/AvHPlayer.cpp b/releases/3.2.0/source/mod/AvHPlayer.cpp index 972261cb..bb47d47e 100644 --- a/releases/3.2.0/source/mod/AvHPlayer.cpp +++ b/releases/3.2.0/source/mod/AvHPlayer.cpp @@ -5979,42 +5979,80 @@ bool AvHPlayer::Redeem() AvHTeam* theTeam = this->GetTeamPointer(); if(theTeam && (theTeam->GetNumActiveHives() > 0)) { + vector theSafeHives; + vector theAttackedHives; // Bring player back if(this->GetTeamPointer()->GetNumActiveHives() > 0) { + + // Loop through the hives for this team, look for the farthest one (hives under attack take precedence) + FOR_ALL_ENTITIES(kesTeamHive, AvHHive*) + if(theEntity->pev->team == this->pev->team) + { + bool theHiveIsUnderAttack = GetGameRules()->GetIsEntityUnderAttack(theEntity->entindex()); + // allow teleport to any built hive, or unbuilt hives under attack. + if(!theEntity->GetIsSpawning()) + { + if ( theHiveIsUnderAttack ) + theAttackedHives.push_back(theEntity->entindex()); + else + theSafeHives.push_back(theEntity->entindex()); + + } + } + END_FOR_ALL_ENTITIES(kesTeamHive) + + } + vector *tmpPtr=&theSafeHives; + if ( theSafeHives.size() == 0 ) + tmpPtr=&theAttackedHives; + + int teleportHiveIndex=-1; + if ( tmpPtr->size() > 0 ) { + int index=RANDOM_LONG(0, tmpPtr->size()-1); + teleportHiveIndex=(*tmpPtr)[index]; + } + + // If we have a valid hive index, jump the player to it + if(teleportHiveIndex != -1) + { // Play redeem effect where it happened so attackers know it happened PLAYBACK_EVENT_FULL(0, this->edict(), gStartCloakEventID, 0, this->pev->origin, (float *)&g_vecZero, this->GetAlienAdjustedEventVolume(), 0.0, /*theWeaponIndex*/ 0, 0, 0, 0 ); - - edict_t* theNewSpawnPoint = GetGameRules()->SelectSpawnPoint(this); - if(!FNullEnt(theNewSpawnPoint)) - { - //// Create building here to test getting stuck - //const int kOffset = 20; - //Vector theBaseOrigin = theNewSpawnPoint->v.origin; - //Vector theRandomOffset(theBaseOrigin.x + RANDOM_LONG(-kOffset, kOffset), theBaseOrigin.y + RANDOM_LONG(-kOffset, kOffset), theBaseOrigin.z + RANDOM_LONG(-kOffset, kOffset)); - //AvHSUBuildTechForPlayer(ALIEN_BUILD_MOVEMENT_CHAMBER, theRandomOffset, this); + + // Move him to it! + AvHHive* theHive = NULL; + AvHSUGetEntityFromIndex(teleportHiveIndex, theHive); + if(theHive) + { + CBaseEntity* theSpawnEntity = GetGameRules()->GetRandomHiveSpawnPoint(this, theHive->pev->origin, theHive->GetMaxSpawnDistance()); + if(theSpawnEntity) + { + Vector theMinSize; + Vector theMaxSize; + this->GetSize(theMinSize, theMaxSize); - theNewSpawnPoint = GetGameRules()->SelectSpawnPoint(this); - if(!FNullEnt(theNewSpawnPoint)) - { - if(this->GetIsDigesting()) - { - this->StopDigestion(false); - } + int theOffset = AvHMUGetOriginOffsetForUser3(AvHUser3(this->pev->iuser3)); + Vector theOriginToSpawn = theSpawnEntity->pev->origin; + theOriginToSpawn.z += theOffset; - mTimeOfLastRedeem = gpGlobals->time; + if(AvHSUGetIsEnoughRoomForHull(theOriginToSpawn, AvHMUGetHull(false, this->pev->iuser3), this->edict())) + { + this->SetPosition(theOriginToSpawn); + this->pev->velocity = Vector(0, 0, 0); + if(this->GetIsDigesting()) + { + this->StopDigestion(false); + } - // Respawn player normally - this->InitPlayerFromSpawn(theNewSpawnPoint); - - PLAYBACK_EVENT_FULL(0, this->edict(), gStartCloakEventID, 0, this->pev->origin, (float *)&g_vecZero, this->GetAlienAdjustedEventVolume(), 0.0, /*theWeaponIndex*/ 0, 0, 0, 0 ); - } - - theSuccess = true; - } - } - } + mTimeOfLastRedeem = gpGlobals->time; + theSuccess = true; + // Play teleport sound before and after + PLAYBACK_EVENT_FULL(0, this->edict(), gStartCloakEventID, 0, this->pev->origin, (float *)&g_vecZero, this->GetAlienAdjustedEventVolume(), 0.0, /*theWeaponIndex*/ 0, 0, 0, 0 ); } + } + } + } + } return theSuccess; }