qboolean Item::Drop( void ) { if ( !owner ) { return false; } setOrigin( owner->origin + Vector( "0 0 40" ) ); // drop the item PlaceItem(); velocity = owner->velocity * 0.5f + Vector( G_CRandom( 50.0f ), G_CRandom( 50.0f ), 100.0f ); setAngles( owner->angles ); avelocity = Vector( 0.0f, G_CRandom( 360.0f ), 0.0f ); trigger_time = level.time + 1.0f; if ( owner->isClient() ) { spawnflags |= DROPPED_PLAYER_ITEM; } else { spawnflags |= DROPPED_ITEM; } // Remove this from the owner's item list owner->RemoveItem( this ); owner = NULL; return true; }
void CombatSubsystem::AimWeaponTag(const Vector& targetPos) { Vector aimAngles; Vector gunPos, gunForward, gunRight, gunUp; //currentEnemy = act->enemyManager->GetCurrentEnemy(); if (!_activeWeapon.weapon) return; _activeWeapon.weapon->setOrigin(); _activeWeapon.weapon->setAngles(); _activeWeapon.weapon->SetControllerAngles(WEAPONBONE_BARREL_TAG, vec_zero); GetGunPositionData(&gunPos, &gunForward, &gunRight, &gunUp); Vector mypos, myforward, myleft, myup; _activeWeapon.weapon->GetTag(WEAPONBONE_BARREL_TAG, &mypos, &myforward, &myleft, &myup); float gfToWorld[ 3 ][ 3 ]; float worldToGf[ 3 ][ 3 ]; gunForward.copyTo(gfToWorld[0]); gunRight.copyTo(gfToWorld[1]); gunUp.copyTo(gfToWorld[2]); TransposeMatrix(gfToWorld, worldToGf); auto barrelToEnemyVector = targetPos - gunPos; vec3_t barrelToEnemyVec3_t; barrelToEnemyVector.copyTo(barrelToEnemyVec3_t); vec3_t barrelToEnemyTransformedVec3_t; MatrixTransformVector(barrelToEnemyVec3_t, worldToGf, barrelToEnemyTransformedVec3_t); Vector barrelToEnemyTransformed(barrelToEnemyTransformedVec3_t); barrelToEnemyTransformed.normalize(); barrelToEnemyTransformed = barrelToEnemyTransformed.toAngles(); barrelToEnemyTransformed.EulerNormalize(); aimAngles = -barrelToEnemyTransformed; Vector aimUp, aimLeft, aimForward; float spreadX, spreadY; aimAngles.AngleVectors(&aimForward, &aimLeft, &aimUp); spreadX = GetDataForMyWeapon("spreadx"); spreadY = GetDataForMyWeapon("spready"); // figure the new projected impact point based upon computed spread if (_activeWeapon.weapon->GetFireType(FIRE_MODE1) == FT_PROJECTILE) { // Apply Spread aimForward = aimForward * _activeWeapon.weapon->GetRange(FIRE_MODE1) + aimLeft * G_CRandom(spreadX) + aimUp * G_CRandom(spreadY); } // after figuring spread location, re-normalize vectors aimForward.normalize(); aimAngles = aimForward.toAngles(); _activeWeapon.weapon->SetControllerTag(WEAPONBONE_BARREL_TAG, gi.Tag_NumForName(_activeWeapon.weapon->edict->s.modelindex, "tag_barrel")); _activeWeapon.weapon->SetControllerAngles(WEAPONBONE_BARREL_TAG, aimAngles); //Draw Trace if (g_showbullettrace->integer) { Vector test; GetGunPositionData(&gunPos, &gunForward); test = gunForward * 1000 + gunPos; G_DebugLine(gunPos, test, 1.0f, 0.0f, 0.0f, 1.0f); Vector barrelForward; aimAngles.AngleVectors(&barrelForward); } }
bool HoldableItemSpawnPowerup::use( void ) { SpawnArgs args; Entity *ent; Item *item; if ( _powerupToSpawn.length() == 0 ) return true; if ( _owner ) { args.setArg( "model", _powerupToSpawn ); ent = args.Spawn(); if ( !ent || !ent->isSubclassOf( Item ) ) return true; item = (Item *)ent; item->setOrigin( _owner->centroid ); item->ProcessPendingEvents(); item->PlaceItem(); item->setOrigin( _owner->centroid ); if ( _owner->isSubclassOf( Player ) ) { Vector viewAngles; Vector viewDir; Player *player = (Player *)_owner; Vector pos; player->GetPlayerView( &pos, &viewAngles ); //viewAngles = player->GetVAngles(); viewAngles.AngleVectors( &viewDir ); viewDir.normalize(); viewDir *= 500.0f; item->velocity = viewDir; item->setOrigin( pos ); } else { item->velocity = Vector( G_CRandom( 100.0f ), G_CRandom( 100.0f ), 200.0f + G_Random( 200.0f ) ); } item->edict->clipmask = CONTENTS_SOLID | CONTENTS_PLAYERCLIP; item->_nextPickupTime = level.time + 1.0f; item->setRespawn( false ); // Powerup is only gets half time item->setAmount( item->getAmount() / 2.0f ); // Get rid of the spawned powerup in 10 seconds item->PostEvent( EV_Remove, 10.0f ); return true; } return false; }
void World::Think( void ) { int i; DynamicLightInfo *dlight; // Do dynamic light stuff for ( i = 0 ; i < MAX_LIGHTING_GROUPS ; i++ ) { dlight = &dynamic_lights[ i ]; if ( dlight->fade_time ) { if ( level.time > ( dlight->start_fade_time + dlight->fade_time ) ) { dlight->intensity = dlight->end_intensity; dlight->fade_time = 0; } else { dlight->intensity = dlight->start_intensity + ( ( dlight->end_intensity - dlight->start_intensity ) * ( ( level.time - dlight->start_fade_time ) / dlight->fade_time ) ); } } else if ( dlight->lightstyle.length() ) { dlight->current_lightstyle_position++; if ( dlight->current_lightstyle_position >= dlight->lightstyle.length() ) { if ( dlight->stop_at_end ) { dlight->lightstyle = ""; dlight->current_lightstyle_position = -1; } else { dlight->current_lightstyle_position = 0; } } if ( dlight->current_lightstyle_position >= 0 ) dlight->intensity = ( dlight->lightstyle[ dlight->current_lightstyle_position ] - 'a' ) / 25.0f; } } UpdateDynamicLights(); // Do wind stuff if ( wind.gust_time ) { if ( level.time < ( wind.start_fade_time + wind.fade_time ) ) { wind.intensity = wind.start_intensity + ( ( wind.end_intensity - wind.start_intensity ) * ( ( level.time - wind.start_fade_time ) / wind.fade_time ) ); } else if ( level.time < ( wind.start_fade_time + wind.fade_time + wind.gust_time ) ) { wind.intensity = wind.end_intensity; } else { wind.intensity = wind.end_intensity + ( ( wind.start_intensity - wind.end_intensity ) * ( ( level.time - wind.start_fade_time - wind.fade_time - wind.gust_time ) / wind.fade_time ) ); if ( level.time > ( wind.start_fade_time + wind.fade_time + wind.gust_time + wind.fade_time ) ) { wind.intensity = wind.start_intensity; wind.fade_time = 0; wind.gust_time = 0; } } } else if ( wind.fade_time ) { if ( level.time > ( wind.start_fade_time + wind.fade_time ) ) { wind.intensity = wind.end_intensity; wind.fade_time = 0; } else { wind.intensity = wind.start_intensity + ( ( wind.end_intensity - wind.start_intensity ) * ( ( level.time - wind.start_fade_time ) / wind.fade_time ) ); } } else if ( ( wind.min_intensity > 0.0f ) && ( wind.max_intensity > 0.0f ) ) { wind.intensity += G_CRandom( wind.max_change ); if ( wind.intensity > wind.max_intensity ) wind.intensity = wind.max_intensity; if ( wind.intensity < wind.min_intensity ) wind.intensity = wind.min_intensity; } UpdateWindDirection(); UpdateWindIntensity(); UpdateTimeScale(); // Do gravity stuff float gravity; // Try to use the world's specified gravity gravity = getPhysicsVar( WORLD_PHYSICS_GRAVITY ); // If not set, use the normal cvar for the gravity if ( gravity == -1 ) { gravity = sv_gravity->value; } // If gravity has changed change the cvar if ( sv_currentGravity->value != gravity ) { gi.cvar_set( "sv_currentGravity", va( "%f", gravity ) ); } }
void GooProjectile::Explode( Event *ev ) { int i; Entity *owner; Entity *ignoreEnt=NULL; if ( ev->NumArgs() == 1 ) ignoreEnt = ev->GetEntity( 1 ); // Get the owner of this projectile owner = G_GetEntity( this->owner ); // If the owner's not here, make the world the owner if ( !owner ) owner = world; takedamage = DamageNo; // Spawn an explosion model if ( explosionmodel.length() ) { // Move the projectile back off the surface a bit so we can see // explosion effects. Vector dir, v; v = velocity; v.normalize(); dir = v; v = origin - v * 36.0f; setOrigin( v ); ExplosionAttack( v, owner, explosionmodel, dir, ignoreEnt ); } CancelEventsOfType( EV_Projectile_UpdateBeam ); // Kill the beam if ( m_beam ) { m_beam->ProcessEvent( EV_Remove ); m_beam = NULL; } // When the goo hits something, spawn debris for ( i=0; i<m_debriscount; i++ ) { GooDebris *proj; Vector dir; dir = Vector( level.impact_trace.plane.normal ); dir += Vector( crandom() * 0.5, crandom() * 0.5f, 0.0f ); proj = ( GooDebris * )ProjectileAttack( this->origin, dir, this, m_debrismodel, 1.0f ); if ( !proj ) { warning( "GooProjectile::Explode", "Could not create debris projectile" ); return; } proj->owner = ENTITYNUM_WORLD; proj->setSolidType( SOLID_TRIGGER ); proj->avelocity = Vector( G_CRandom( 360.0f ), G_CRandom( 360.0f ), G_CRandom( 360.0f ) ); proj->setSize( Vector( -16.0f, -16.0f, 0.0f ) * proj->edict->s.scale, Vector( 16.0f ,16.0f ,32.0f ) * proj->edict->s.scale ); proj->setMoveType( MOVETYPE_TOSS ); proj->PostEvent( EV_GooDebris_Prethink, level.frametime ); } // Change to the splat if ( level.impact_trace.ent && ( level.impact_trace.ent->solid == SOLID_BSP ) ) { GooDebris *p; Vector ang; p = new GooDebris; vectoangles( level.impact_trace.plane.normal, ang ); p->setAngles( ang ); p->setModel( this->model ); p->ProcessInitCommands( p->edict->s.modelindex ); p->setSize( Vector( -16.0f, -16.0f, 0.0f ) * p->edict->s.scale, Vector( 16.0f, 16.0f, 32.0f ) * p->edict->s.scale ); p->setOrigin( this->origin ); p->velocity = Vector( 0.0f, 0.0f, 0.0f ); p->setMoveType( MOVETYPE_FLY ); p->setSolidType( SOLID_TRIGGER ); p->animate->RandomAnimate( "splat" ); p->owner = this->owner; p->PostEvent( EV_GooDebris_Prethink, level.frametime ); // shrink out } }