/* =========================================================================== IceTech GPL Source Code Copyright (C) 2026 Justin Marshall This file is part of the IceTech GPL Source Code (?IceTech Source Code?). IceTech Source Code is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. IceTech Source Code is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with IceTech Source Code. If not, see . In addition, the IceTech Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the IceTech Source Code. If not, please request a copy in writing from id Software at the address below. If you have questions concerning this license or the applicable additional terms, you may contact in writing Justin Marshall, justinmarshall20@gmail.com =========================================================================== */ /*********************************************************************** game/ai/AI_Vagary.cpp Vagary specific AI code ***********************************************************************/ #include "precompiled.h" #pragma hdrstop #include "../Game_local.h" /* ================ idAI_Vagary::Event_ChooseObjectToThrow ================ */ void idAI_Vagary::Event_ChooseObjectToThrow( const idVec3 &mins, const idVec3 &maxs, float speed, float minDist, float offset ) { idEntity * ent; idEntity * entityList[ MAX_GENTITIES ]; int numListedEntities; int i, index; float dist; idVec3 vel; idVec3 offsetVec( 0, 0, offset ); idEntity *enemyEnt = enemy.GetEntity(); if ( !enemyEnt ) { idThread::ReturnEntity( NULL ); } idVec3 enemyEyePos = lastVisibleEnemyPos + lastVisibleEnemyEyeOffset; const idBounds &myBounds = physicsObj.GetAbsBounds(); idBounds checkBounds( mins, maxs ); checkBounds.TranslateSelf( physicsObj.GetOrigin() ); numListedEntities = gameLocal.clip.EntitiesTouchingBounds( checkBounds, -1, entityList, MAX_GENTITIES ); index = gameLocal.random.RandomInt( numListedEntities ); for ( i = 0; i < numListedEntities; i++, index++ ) { if ( index >= numListedEntities ) { index = 0; } ent = entityList[ index ]; if ( !ent->IsType( idMoveable::Type ) ) { continue; } if ( ent->fl.hidden ) { // don't throw hidden objects continue; } idPhysics *entPhys = ent->GetPhysics(); const idVec3 &entOrg = entPhys->GetOrigin(); dist = ( entOrg - enemyEyePos ).LengthFast(); if ( dist < minDist ) { continue; } idBounds expandedBounds = myBounds.Expand( entPhys->GetBounds().GetRadius() ); if ( expandedBounds.LineIntersection( entOrg, enemyEyePos ) ) { // ignore objects that are behind us continue; } if ( PredictTrajectory( entPhys->GetOrigin() + offsetVec, enemyEyePos, speed, entPhys->GetGravity(), entPhys->GetClipModel(), entPhys->GetClipMask(), MAX_WORLD_SIZE, NULL, enemyEnt, ai_debugTrajectory.GetBool() ? 4000 : 0, vel ) ) { idThread::ReturnEntity( ent ); return; } } idThread::ReturnEntity( NULL ); } /* ================ idAI_Vagary::Event_ThrowObjectAtEnemy ================ */ void idAI_Vagary::Event_ThrowObjectAtEnemy( idEntity *ent, float speed ) { idVec3 vel; idEntity *enemyEnt; idPhysics *entPhys; entPhys = ent->GetPhysics(); enemyEnt = enemy.GetEntity(); if ( !enemyEnt ) { vel = ( viewAxis[ 0 ] * physicsObj.GetGravityAxis() ) * speed; } else { PredictTrajectory( entPhys->GetOrigin(), lastVisibleEnemyPos + lastVisibleEnemyEyeOffset, speed, entPhys->GetGravity(), entPhys->GetClipModel(), entPhys->GetClipMask(), MAX_WORLD_SIZE, NULL, enemyEnt, ai_debugTrajectory.GetBool() ? 4000 : 0, vel ); vel *= speed; } entPhys->SetLinearVelocity( vel ); if ( ent->IsType( idMoveable::Type ) ) { idMoveable *ment = static_cast( ent ); ment->EnableDamage( true, 2.5f ); } }