int AvHBasePlayerWeapon::AddToPlayer( CBasePlayer *pPlayer ) { // Can we predict weapon pick-ups? I bet we can. int theAddedToPlayer = 0; #ifdef AVH_SERVER AvHPlayer* inPlayer = dynamic_cast<AvHPlayer*>(pPlayer); ASSERT(inPlayer != NULL); if(this->GetAllowedForUser3(inPlayer->GetUser3())) { // Make sure player doesn't have this weapon already if(!pPlayer->HasItem(this)) { // If weapon was placed by mapper if(this->GetIsPersistent()) { // Create a new weapon and give it to the player pPlayer->GiveNamedItem(STRING(this->pev->classname)); this->DestroyItem(); } else { theAddedToPlayer = CBasePlayerWeapon::AddToPlayer(pPlayer); if(theAddedToPlayer) { // Make sure it's not set for expiration SetThink(NULL); } } } } #endif return theAddedToPlayer; }
void AvHHive::TeleportUse(CBaseEntity* inActivator, CBaseEntity* inCaller, USE_TYPE inUseType, float inValue) { if ( this->GetIsSpawning() ) { this->SetEmergencyUse(); return; } 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) && thePlayer->GetCanUseHive() ) { vector<int> theHives; vector<int> theHivesUnderAttack; if((this->mLastTimeScannedHives == -1) || (gpGlobals->time > (this->mLastTimeScannedHives + kHiveScanInterval))) { this->mTeleportHiveIndex = -1; float theFarthestDistance = 0.0f; //sqrt((kMaxMapDimension*2)*(kMaxMapDimension*2)); // 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) && theEntity != this ) { bool theHiveIsUnderAttack = GetGameRules()->GetIsEntityUnderAttack(theEntity->entindex()); // allow teleport to any built hive, or unbuilt hives under attack. if(!theEntity->GetIsSpawning() || ( theEntity->GetIsSpawning() && ( theHiveIsUnderAttack || theEntity->GetEmergencyUse()) ) ) { theHives.push_back(theEntity->entindex()); if ( theHiveIsUnderAttack ) theHivesUnderAttack.push_back(theEntity->entindex()); } } END_FOR_ALL_ENTITIES(kesTeamHive) this->mLastTimeScannedHives = gpGlobals->time; }
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); } } } } }