void AvHMovementChamber::TeleportUse(CBaseEntity* inActivator, CBaseEntity* inCaller, USE_TYPE inUseType, float inValue) { const float kHiveScanInterval = 1.0f; AvHPlayer* thePlayer = dynamic_cast<AvHPlayer*>(inActivator); if(thePlayer && (thePlayer->pev->team == this->pev->team) && (thePlayer->GetUser3() != AVH_USER3_ALIEN_EMBRYO)) { if((this->mLastTimeScannedHives == -1) || (gpGlobals->time > (this->mLastTimeScannedHives + kHiveScanInterval))) { this->mTeleportHiveIndex = -1; float theFarthestDistance = 0.0f; //sqrt((kMaxMapDimension*2)*(kMaxMapDimension*2)); bool theIsDone = false; // 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) && !theIsDone) { bool theHiveIsUnderAttack = GetGameRules()->GetIsEntityUnderAttack(theEntity->entindex()); if(theEntity->GetIsActive() || theHiveIsUnderAttack || theEntity->GetEmergencyUse() ) { float theCurrentDistance = VectorDistance(theEntity->pev->origin, inActivator->pev->origin); bool theHiveIsFarther = (theCurrentDistance > theFarthestDistance); // Undefined which attacked hive is chosen if multiples are under attack if((this->mTeleportHiveIndex == -1) || theHiveIsFarther || theHiveIsUnderAttack) { this->mTeleportHiveIndex = theEntity->entindex(); theFarthestDistance = theCurrentDistance; // If there's a hive under attack, we're done if(theHiveIsUnderAttack) { theIsDone = true; } } } } END_FOR_ALL_ENTITIES(kesTeamHive) this->mLastTimeScannedHives = gpGlobals->time; } // If we have a valid hive index, jump the player to it if(this->mTeleportHiveIndex != -1) { // Play sound at this entity EMIT_SOUND(this->edict(), CHAN_AUTO, kAlienSightOnSound, 1.0f, ATTN_NORM); // Move him to it! AvHHive* theHive = NULL; AvHSUGetEntityFromIndex(this->mTeleportHiveIndex, theHive); if(theHive) { CBaseEntity* theSpawnEntity = GetGameRules()->GetRandomHiveSpawnPoint(thePlayer, theHive->pev->origin, theHive->GetMaxSpawnDistance()); if(theSpawnEntity) { Vector theMinSize; Vector theMaxSize; thePlayer->GetSize(theMinSize, theMaxSize); int theOffset = AvHMUGetOriginOffsetForUser3(AvHUser3(thePlayer->pev->iuser3)); Vector theOriginToSpawn = theSpawnEntity->pev->origin; theOriginToSpawn.z += theOffset; if(AvHSUGetIsEnoughRoomForHull(theOriginToSpawn, AvHMUGetHull(false, thePlayer->pev->iuser3), thePlayer->edict())) { thePlayer->SetPosition(theOriginToSpawn); thePlayer->pev->velocity = Vector(0, 0, 0); thePlayer->TriggerUncloak(); // Play teleport sound before and after EMIT_SOUND(inActivator->edict(), CHAN_AUTO, kAlienSightOffSound, 1.0f, ATTN_NORM); } } } } }