inline void EsquivoMina(double angulo){ Shoot(0.02*energiadisparo); if (distancia<20 & ((angulo<90) | (angulo>270)) ){ Accelerate(-0.5); }else{ Accelerate(2); } Brake(1); }
//------------------------------------------------------------------------ void CRapid::NetStartFire() { m_netshooting = true; m_pWeapon->EnableUpdate(true, eIUS_FireMode); //SpinUpEffect(true); Accelerate(m_pShared->rapidparams.acceleration); }
void Enemy::Update(Player * player) { if (invulnerable > 0) invulnerable--; playerPos = player->position; Accelerate(xAccel, yAccel); }
inline void EsquivoPared(double distancia){ if (distancia<1){ Accelerate(-0.5); Brake(1); RotateAmount(1,666.0,190.0); } }
//------------------------------------------------------------------------ void CRapid::StopFire() { bool acceleratingOrDecelerating = (m_rapidFlags & (eRapidFlag_accelerating|eRapidFlag_decelerating)) != 0; if (!m_firing && (m_reloading || !acceleratingOrDecelerating)) return; m_firing = false; m_rapidFlags &= ~(eRapidFlag_startedFiring|eRapidFlag_rapidFiring); if(m_acceleration >= 0.0f) { Accelerate(m_fireParams->rapidparams.deceleration); if (m_pWeapon->IsDestroyed()) FinishDeceleration(); } SpinUpEffect(false); SmokeEffect(); const bool shouldTriggerStopFiringAnim = m_fireParams->rapidparams.min_firingTimeToStop==0.0f || ((gEnv->pTimer->GetAsyncTime().GetSeconds() - m_startFiringTime.GetSeconds()) > m_fireParams->rapidparams.min_firingTimeToStop); if (shouldTriggerStopFiringAnim) { m_queueRapidFireAction = true; } m_startFiringTime.SetSeconds(0.0f); m_muzzleEffect.StopFire(this); m_pWeapon->RequestStopFire(); }
// performs simple maneuvers void CBE_Floater::AttackManeuver(CCopyEntity* pCopyEnt, SBE_EnemyExtraData *pExtraData) { float& rfSensoringInterval = pCopyEnt->f1; Vector3& rvDesiredDirection = pCopyEnt->v1; float& rfCurrentManeuverTime = pExtraData->fCurrentManeuverTime; float& rfTotalManeuverTime = pExtraData->fTotalManeuverTime; Vector3& rvManeuverDir = pExtraData->vManeuverDirection; float fSqDistToPlayer = pExtraData->fLastCheckedSqDistToPlayer; ApplyFriction( pCopyEnt, 1.8f ); // evasive maneuver if( 0.20f < rfCurrentManeuverTime - rfTotalManeuverTime || rvManeuverDir == Vector3(0,0,0) ) { rfCurrentManeuverTime = 0; rfTotalManeuverTime = 0.7f + 0.5f * (float)rand() / (float)RAND_MAX; // set up a new direction rvManeuverDir += pCopyEnt->GetRightDirection() * ( 3.0f * (float)rand()/(float)RAND_MAX - 1.5f ) + pCopyEnt->GetUpDirection() * ( 3.0f * (float)rand()/(float)RAND_MAX - 1.5f ) + pCopyEnt->GetDirection() * ( 1.6f * (float)rand()/(float)RAND_MAX - 0.8f ); if( 36.0f < fSqDistToPlayer ) // if over 6m away from player rvManeuverDir += rvDesiredDirection * fSqDistToPlayer / 50.0f; // move toward the player Vec3Normalize( rvManeuverDir, rvManeuverDir ); } else rfCurrentManeuverTime += m_pStage->GetFrameTime(); if( 0.5f < rfTotalManeuverTime - rfCurrentManeuverTime ) { // float fWishSpeed = 12.0f; float fWishSpeed = 10.0f * m_fMobility; Accelerate( pCopyEnt, rvManeuverDir, fWishSpeed, 4.0f ); } if( rfSensoringInterval == 0 ) { // check if there is an obstacle in the direction to which the entity is heading STrace tr; tr.bvType = BVTYPE_AABB; tr.aabb = this->m_aabb; tr.pSourceEntity = pCopyEnt; tr.vStart = pCopyEnt->GetWorldPosition(); tr.vGoal = pCopyEnt->GetWorldPosition() + pCopyEnt->vVelocity * 1.2f; tr.SetAABB(); m_pStage->ClipTrace(tr); // since the entity is heading for some obstacle, correct the velocity to avoid it if( tr.fFraction < 1.0f ) { pCopyEnt->vVelocity += tr.plane.normal * (1.0f - tr.fFraction ) * 3.0f; // m_pStage->GetFrameTime(); } } SlideMove( pCopyEnt ); }
double updatePopulations(int niter) { register int nact; bool_t accel, quiet; double dpops, dpopsmax = 0.0; Atom *atom; Molecule *molecule; /* --- Update active atoms -- -------------- */ for (nact = 0; nact < atmos.Nactiveatom; nact++) { atom = atmos.activeatoms[nact]; statEquil(atom, input.isum); if (mpi.stop) return 1.; /* Get out if there is a singular matrix */ accel = Accelerate(atom->Ng_n, atom->n[0]); if (mpi.stop) return 1.; sprintf(messageStr, " %s,", atom->ID); dpops = MaxChange(atom->Ng_n, messageStr, quiet=FALSE); Error(MESSAGE, NULL, (accel) ? " (accelerated)\n" : "\n"); dpopsmax = MAX(dpops, dpopsmax); } /* --- Update active molecules -- -------------- */ for (nact = 0; nact < atmos.Nactivemol; nact++) { molecule = atmos.activemols[nact]; statEquilMolecule(molecule, 0); if (mpi.stop) return 1.; accel = Accelerate(molecule->Ng_nv, molecule->nv[0]); if (mpi.stop) return 1.; sprintf(messageStr, " %s ,", molecule->ID); dpops = MaxChange(molecule->Ng_nv, messageStr, quiet=FALSE); Error(MESSAGE, NULL, (accel) ? " (accelerated)\n" : "\n"); dpopsmax = MAX(dpops, dpopsmax); } return dpopsmax; }
//------------------------------------------------------------------------ void CRapid::StartReload(int zoomed) { if (IsFiring()) Accelerate(m_pShared->rapidparams.deceleration); Firing(false); CSingle::StartReload(zoomed); }
CSpaceObject::DamageResults CMissile::Damage (CSpaceObject *pCause, const CVector &vHitPos, int iDirection, const DamageDesc &Damage) // Damage // // Object takes damage from the given source { CSpaceObject *pAttacker = pCause->GetDamageCause(); // Compute damage bool bDestroy = false; int iDamage = Damage.RollDamage(); if (iDamage == 0) return damageNoDamage; // If this is a momentum attack then we are pushed int iMomentum; if (iMomentum = Damage.GetMomentumDamage()) { CVector vAccel = PolarToVector(iDirection, -10 * iMomentum * iMomentum); Accelerate(vAccel, g_MomentumConstant); ClipSpeed(GetMaxSpeed()); } // Create a hit effect CEffectCreator *pEffect = g_pUniverse->FindEffectType(g_HitEffectUNID); if (pEffect) pEffect->CreateEffect(GetSystem(), this, vHitPos, GetVel()); // Take damage if (iDamage < m_iHitPoints) { m_iHitPoints -= iDamage; return damageArmorHit; } // We are destroyed m_iHitPoints = 0; if (m_pDesc->m_iVaporTrailLength) { m_fDestroyed = true; m_iLifeLeft = m_pDesc->m_iVaporTrailLength; } else Destroy(killedByDamage, pAttacker); // A missile might be able to pass through after hitting us return damagePassthrough; }
EDamageResults CMissile::OnDamage (SDamageCtx &Ctx) // Damage // // Object takes damage from the given source { Ctx.iSectHit = -1; // Compute damage bool bDestroy = false; Ctx.iDamage = Ctx.Damage.RollDamage(); if (Ctx.iDamage == 0) return damageNoDamage; // If this is a momentum attack then we are pushed int iMomentum; if (iMomentum = Ctx.Damage.GetMomentumDamage()) { CVector vAccel = PolarToVector(Ctx.iDirection, -10 * iMomentum * iMomentum); Accelerate(vAccel, g_MomentumConstant); ClipSpeed(GetMaxSpeed()); } // Create a hit effect Ctx.pDesc->CreateHitEffect(GetSystem(), Ctx); // Check for passthrough. If we pass through then we don't take any damage. if (mathRandom(1, 100) <= m_pDesc->GetPassthrough()) return damageArmorHit; // Take damage if (Ctx.iDamage < m_iHitPoints) { m_iHitPoints -= Ctx.iDamage; return damageArmorHit; } // We are destroyed m_iHitPoints = 0; if (m_pDesc->GetVaporTrailLength()) { m_fDestroyed = true; m_iLifeLeft = m_pDesc->GetVaporTrailLength(); return damagePassthrough; } else { Destroy(killedByDamage, Ctx.Attacker); return damagePassthroughDestroyed; } }
//------------------------------------------------------------------------ void CRapid::NetStartFire() { m_rapidFlags |= eRapidFlag_netShooting; m_pWeapon->EnableUpdate(true, eIUS_FireMode); //SpinUpEffect(true); Accelerate(m_fireParams->rapidparams.acceleration); }
//------------------------------------------------------------------------ void CRapid::StartReload(int zoomed) { if (IsFiring()) Accelerate(m_fireParams->rapidparams.deceleration); Firing(false); PlayStopRapidFireIfNeeded(); BaseClass::StartReload(zoomed); }
inline void APorGalleta(double angulo){ aquemededico=GALLETAS; //RotateTo(7,666,0.0); RotateAmount(1,666,angulo); //while(haciendoalgo){ Accelerate(2.0); Accelerate(2.0); Accelerate(2.0); Accelerate(2.0); Accelerate(2.0); Accelerate(2.0); Accelerate(2.0); Accelerate(2.0); Accelerate(2.0); Accelerate(2.0); tiempogalleta=time(NULL)+3; sleep(1); //} }
///The main function: Ticking. ///Whether this runs before or after the car's ticking shouldn't matter. void AControlActor::RaceTick(float DeltaTime) { if (raceActive || logAIsensors) { timeElapsed += DeltaTime; /// ============ Set Variables such as speed, currCurvature, etc. =========== currTrackPos = GetTrackPos(car->GetActorLocation()); velocity = ReadVelocity(); edgeDist = GetEdgeDist(); currSection = GetSection(0); nextSection = GetSection(1); distToCurrSectionEnd = currSection.length - currTrackPos.distThrough; float r = distToCurrSectionEnd / currSection.length; currCurvature = r*currSection.initCurvature + (1 - r)*currSection.finalCurvature; // currSteeringAngle set each time the user sets it } if (logAIsensors) { /// =============== [Debug] Log all the things ============ UE_LOG(ControlActor, Log, TEXT("")); UE_LOG(ControlActor, Log, TEXT("=============================================")); UE_LOG(ControlActor, Log, TEXT("Time elapsed: %f"), timeElapsed); UE_LOG(ControlActor, Log, TEXT("Current section: %d"), currTrackPos.currSectionI); UE_LOG(ControlActor, Log, TEXT("Distance through section: %f"), currTrackPos.distThrough); UE_LOG(ControlActor, Log, TEXT("Total distancce: %f"), trackSplineDist); UE_LOG(ControlActor, Log, TEXT("")); UE_LOG(ControlActor, Log, TEXT("Velocity forward: %f"), velocity.ahead); UE_LOG(ControlActor, Log, TEXT("Velocity right: %f"), velocity.right); UE_LOG(ControlActor, Log, TEXT("Speed: %f"), velocity.speed); UE_LOG(ControlActor, Log, TEXT("Angle to ahead: %f"), velocity.angleToAhead); UE_LOG(ControlActor, Log, TEXT("")); UE_LOG(ControlActor, Log, TEXT("Left edge dist: %f"), edgeDist.left); UE_LOG(ControlActor, Log, TEXT("Right edge dist: %f"), edgeDist.right); } /// ============ Run the AI! ========== if (raceActive) { ExecuteAIscript(); } else { if (!car->userInControl) { Accelerate(0); SetSteeringAngle(0); } } }
inline void DisparoRobot(double distancia){ int disparosdistancia=0; Shoot(energiadisparo); Shoot(energiadisparo); Shoot(energiadisparo); if (distancia<6){ Accelerate(2); disparosdistancia=5/distancia; while((disparosdistancia--)%10){ Shoot(energiadisparo); } } liberabloqueos(); }
//------------------------------------------------------------------------ void CRapid::NetStopFire() { if(m_acceleration >= 0.0f) { Accelerate(m_pShared->rapidparams.deceleration); if (m_pWeapon->IsDestroyed()) FinishDeceleration(); } SpinUpEffect(false); if(m_firing) SmokeEffect(); }
// Called every frame void ASkateboardPawn::Tick(float DeltaTime) { Super::Tick(DeltaTime); // Brake the skateboard if grounded and player pressed the brake button if (bBraking && bIsGrounded) { float stopValue = (Mesh->GetPhysicsLinearVelocity().X + Mesh->GetPhysicsLinearVelocity().Y)*0.9f; Mesh->SetAllPhysicsLinearVelocity(Mesh->GetForwardVector()*stopValue); } // The roll of the board has to be corrected in any time CorrectRoll(); // If the board is grounded, we need to also correct the gravity and the pitch if (bIsGrounded) { CorrectGravity(); CorrectPitch(); } if (bAccelerating && AccelerationDelayCount < DeltaTime) { AccelerationDelayCount = AccelerationDelay; // Handling acceleration Accelerate(); } else { AccelerationDelayCount -= DeltaTime; } float rotationAngle = DeltaTime * 15.0f; // rotationSpeed = (CurrentVelocity on X/Z-Plane) * steeringFactor float rotationSpeed = (Mesh->GetPhysicsLinearVelocity().X + Mesh->GetPhysicsLinearVelocity().Y) * 20; if (bSteeringLeft && !bSteeringRight) { Steer(FRotator(0, -rotationAngle, 0)); Mesh->AddForce(Mesh->GetRightVector() * -rotationSpeed); } else if (bSteeringRight && !bSteeringLeft) { Steer(FRotator(0, rotationAngle, 0)); Mesh->AddForce(Mesh->GetRightVector() * rotationSpeed); } }
//------------------------------------------------------------------------ void CRapid::StopFire() { m_startedToFire = false; if (m_pWeapon->IsBusy() && !m_pWeapon->IsZoomingInOrOut()) { return; } if (m_zoomtimeout > 0.0f) { CActor *pActor = m_pWeapon->GetOwnerActor(); CScreenEffects *pSE = pActor ? pActor->GetScreenEffects() : NULL; if (pSE) { float speed = 1.0f / .1f; pSE->ResetBlendGroup(CScreenEffects::eSFX_GID_ZoomIn); pSE->ResetBlendGroup(CScreenEffects::eSFX_GID_ZoomOut); IBlendedEffect *fov = CBlendedEffect<CFOVEffect>::Create(CFOVEffect(pActor->GetEntityId(), 1.0f)); IBlendType *blend = CBlendType<CLinearBlend>::Create(CLinearBlend(1.0f)); pSE->StartBlend(fov, blend, speed, CScreenEffects::eSFX_GID_ZoomOut); } m_zoomtimeout = 0.0f; } if(m_acceleration >= 0.0f) { Accelerate(m_pShared->rapidparams.deceleration); if (m_pWeapon->IsDestroyed()) { FinishDeceleration(); } } SpinUpEffect(false); if(m_firing) { SmokeEffect(); } m_pWeapon->RequestStopFire(); }
//------------------------------------------------------------------------ void CRapid::NetStopFire() { if(m_acceleration >= 0.0f) { Accelerate(m_fireParams->rapidparams.deceleration); if (m_pWeapon->IsDestroyed()) FinishDeceleration(); } SpinUpEffect(false); if(m_firing) SmokeEffect(); m_firing = false; m_rapidFlags &= ~(eRapidFlag_startedFiring|eRapidFlag_rapidFiring|eRapidFlag_netShooting); m_queueRapidFireAction = true; m_startFiringTime.SetSeconds(0.0f); }
//------------------------------------------------------------------------ void CRapid::StartFire() { if (m_pWeapon->IsBusy() || !CanFire(true)) { //Clip empty sound if(!CanFire(true) && !m_reloading) { int ammoCount = m_pWeapon->GetAmmoCount(m_fireParams->fireparams.ammo_type_class); if (GetClipSize()==0) ammoCount = m_pWeapon->GetInventoryAmmoCount(m_fireParams->fireparams.ammo_type_class); if(ammoCount<=0) { m_pWeapon->PlayAction(GetFragmentIds().empty_clip); m_pWeapon->OnFireWhenOutOfAmmo(); } } return; } m_rapidFlags &= ~eRapidFlag_netShooting; if ((m_rapidFlags & (eRapidFlag_decelerating | eRapidFlag_accelerating)) == 0) { m_pWeapon->EnableUpdate(true, eIUS_FireMode); } //SpinUpEffect(true); Accelerate(m_fireParams->rapidparams.acceleration); m_rapidFlags |= eRapidFlag_startedFiring; m_firstFire = true; m_startFiringTime = gEnv->pTimer->GetAsyncTime(); m_muzzleEffect.StartFire(this); m_pWeapon->RequestStartFire(); }
static float RankAngle (float a) { vec3_t wishdir; float delta; vec3_t ang1, ang2; vec3_t newvel; wishdir[0] = cos(a / 180 * M_PI); wishdir[1] = sin(a / 180 * M_PI); wishdir[2] = 0; VectorCopy (ra_curvel, newvel); Friction (newvel); Accelerate (wishdir, movevars.maxspeed, newvel); vectoangles (newvel, ang1); vectoangles (ra_intentions, ang2); delta = AngleMod(ang2[YAW] - ang1[YAW]); return -fabs(delta); }
//------------------------------------------------------------------------ void CRapid::StartFire() { if (m_pWeapon->IsBusy() || !CanFire(true)) { //Clip empty sound if(!CanFire(true) && !m_reloading) { int ammoCount = m_pWeapon->GetAmmoCount(m_pShared->fireparams.ammo_type_class); if (m_pShared->fireparams.clip_size==0) ammoCount = m_pWeapon->GetInventoryAmmoCount(m_pShared->fireparams.ammo_type_class); if(ammoCount<=0) { m_pWeapon->PlayAction(m_pShared->actions.empty_clip); //Auto reload m_pWeapon->Reload(); } } return; } else if(m_pWeapon->IsWeaponLowered()) { m_pWeapon->PlayAction(m_pShared->actions.null_fire); return; } m_netshooting = false; m_pWeapon->EnableUpdate(true, eIUS_FireMode); //SpinUpEffect(true); Accelerate(m_pShared->rapidparams.acceleration); m_startedToFire = true; m_pWeapon->RequestStartFire(); }
// movement code is a copy of CGameMovement::FullNoClipMove() void C_HLTVCamera::CalcRoamingView(Vector& eyeOrigin, QAngle& eyeAngles, float& fov) { // only if PVS isn't locked by auto-director if ( !IsPVSLocked() ) { Vector wishvel; Vector forward, right, up; Vector wishdir; float wishspeed; float factor = sv_specspeed.GetFloat(); float maxspeed = sv_maxspeed.GetFloat() * factor; AngleVectors ( m_LastCmd.viewangles, &forward, &right, &up); // Determine movement angles if ( m_LastCmd.buttons & IN_SPEED ) { factor /= 2.0f; } // Copy movement amounts float fmove = m_LastCmd.forwardmove * factor; float smove = m_LastCmd.sidemove * factor; VectorNormalize (forward); // Normalize remainder of vectors VectorNormalize (right); // for (int i=0 ; i<3 ; i++) // Determine x and y parts of velocity wishvel[i] = forward[i]*fmove + right[i]*smove; wishvel[2] += m_LastCmd.upmove * factor; VectorCopy (wishvel, wishdir); // Determine magnitude of speed of move wishspeed = VectorNormalize(wishdir); // // Clamp to server defined MAX speed // if (wishspeed > maxspeed ) { VectorScale (wishvel, maxspeed/wishspeed, wishvel); wishspeed = maxspeed; } if ( sv_specaccelerate.GetFloat() > 0.0 ) { // Set move velocity Accelerate ( wishdir, wishspeed, sv_specaccelerate.GetFloat() ); float spd = VectorLength( m_vecVelocity ); if (spd < 1.0f) { m_vecVelocity.Init(); } else { // Bleed off some speed, but if we have less than the bleed // threshold, bleed the threshold amount. float control = (spd < maxspeed/4.0) ? maxspeed/4.0 : spd; float friction = sv_friction.GetFloat(); // Add the amount to the drop amount. float drop = control * friction * gpGlobals->frametime; // scale the velocity float newspeed = spd - drop; if (newspeed < 0) newspeed = 0; // Determine proportion of old speed we are using. newspeed /= spd; VectorScale( m_vecVelocity, newspeed, m_vecVelocity ); } } else { VectorCopy( wishvel, m_vecVelocity ); } // Just move ( don't clip or anything ) VectorMA( m_vCamOrigin, gpGlobals->frametime, m_vecVelocity, m_vCamOrigin ); // get camera angle directly from engine engine->GetViewAngles( m_aCamAngle ); // Zero out velocity if in noaccel mode if ( sv_specaccelerate.GetFloat() < 0.0f ) { m_vecVelocity.Init(); } } eyeOrigin = m_vCamOrigin; eyeAngles = m_aCamAngle; fov = m_flFOV; }
/* This task makes the robot follow the line, turn around corners, handle crossings and detect an obstacle. */ task Follow(){ int i = 0; startTask(Sound); while (true){ status = "active"; /* Objects are detected below here. When an object is detected the user can either choose to avoid it or charge. */ if(SonarSensor()){ while(speed > 0){ speed = Brake(i,speed); i--; Straight(speed); } status = "engage"; StopSound(); s = ""; while((s != "FIRE")&&(s != "B")){ } if (s == "FIRE"){ startTask(Sound); startTask(AvoidObject); } } else if(speed < max_Speed){ speed = Accelerate(i,speed); i++; } Straight(speed); /* Crossings are handled below here. Once both lightsensors detect the line at the same time the robot will brake unless it was told to go straight. It will then drive backward to find the line again after which it will continue untill it has crossed it. The robot will then look at the last given command to determine which way it will go. */ if((Convert(SensorValue[S3],minlight,maxlight) < 70) && (Convert(SensorValue[S4],mincolor,maxcolor) < 70)){ if (command != "straight"){ speed = EmergencyBrake(speed); wait1Msec(1000); while(Convert(SensorValue[S3],minlight,maxlight) > 30 || Convert(SensorValue[S4],mincolor,maxcolor) > 30){ Straight((-10)); } if (Convert(SensorValue[S3],minlight,maxlight) < 70 || Convert(SensorValue[S4],mincolor,maxcolor) < 70){ nMotorEncoderTarget[motorB]=(nMotorEncoderTarget[motorC]=105); motor[motorB]=(motor[motorC]=-10); while((nMotorRunState[motorB] != runStateIdle) && (nMotorRunState[motorC] != runStateIdle)) wait1Msec(1); } if ((s == "FIRE")||(s == "")){ StopSound(); while ((s == "FIRE")||(s == "")){ Straight(0); } startTask(Sound); } if (command == "left"){ LeftTurn(); } else if (command == "right"){ RightTurn(); } } else{ wait1Msec(200); } } //The code below here makes sure the robot stays on the line. if(Convert(SensorValue[S3],minlight,maxlight) < 80){ Left(Convert(SensorValue[S3],minlight,maxlight),speed); } if(Convert(SensorValue[S4],mincolor,maxcolor) < 80){ Right(Convert(SensorValue[S4],mincolor,maxcolor),speed); } wait1Msec(1.5); } }
void CBE_Floater::SearchManeuver(CCopyEntity* pCopyEnt, SBE_EnemyExtraData *pExtraData) { Vector3& rvDesiredDirection = pCopyEnt->v1; Vector3& rvTargetPosition = pExtraData->vTargetPosition; float& rfSensoringInterval2 = pExtraData->fSensoringInterval2; float& rfCurrentManeuverTime = pExtraData->fCurrentManeuverTime; float& rfTotalManeuverTime = pExtraData->fTotalManeuverTime; Vector3& rvManeuverDir = pExtraData->vManeuverDirection; float fWishSpeed = 6.0f; const float frametime = m_pStage->GetFrameTime(); // if( pCopyEnt->vVelocity == Vector3(0,0,0) ) // return; ApplyFriction( pCopyEnt, 1.5f ); if( m_iRandomSearchManeuver != 0 ) { Vector3 vFromCurrentPosToDest = rvTargetPosition - pCopyEnt->GetWorldPosition(); float fDist = Vec3LengthSq( vFromCurrentPosToDest ); if( 0.20f < rfCurrentManeuverTime - rfTotalManeuverTime || rvManeuverDir == Vector3(0,0,0) || fDist < 0.2f ) { rfCurrentManeuverTime = 0; rfTotalManeuverTime = 1.0f + 0.6f * (float)rand() / (float)RAND_MAX; // set up a target locaion rvTargetPosition = pExtraData->vOriginalPosition + Vector3(1,0,0) * ( 12.0f * (float)rand()/(float)RAND_MAX - 6.0f ) + Vector3(0,1,0) * ( 6.0f * (float)rand()/(float)RAND_MAX - 3.0f ) + Vector3(0,0,1) * ( 12.0f * (float)rand()/(float)RAND_MAX - 6.0f ) + pCopyEnt->GetDirection() * 2.5f; Vec3Normalize( rvManeuverDir, rvManeuverDir ); } else rfCurrentManeuverTime += frametime; if( 0.16f < rfSensoringInterval2 ) { rfSensoringInterval2 = 0.0f; Vec3Normalize( rvManeuverDir, vFromCurrentPosToDest ); } else rfSensoringInterval2 += frametime; if( 0.1f < rfTotalManeuverTime - rfCurrentManeuverTime ) { float fWishSpeed = 4.5f; Accelerate( pCopyEnt, rvManeuverDir, fWishSpeed, 2.0f ); } UpdateDesiredYawAndPitch(pCopyEnt, rvManeuverDir); AimAlong(pCopyEnt, rvManeuverDir); } SlideMove( pCopyEnt ); }
void CSDKGameMovement::WalkMove( void ) { #if defined ( SDK_USE_SPRINTING ) float flSpeedCheck = m_pSDKPlayer->GetAbsVelocity().Length2D(); bool bSprintButtonPressed = ( mv->m_nButtons & IN_SPEED ) > 0; if( bSprintButtonPressed && ( mv->m_nButtons & IN_FORWARD ) && #if defined ( SDK_USE_PRONE ) !m_pSDKPlayer->m_Shared.IsProne() && #endif !m_pSDKPlayer->m_Shared.IsDucking() && flSpeedCheck > 80 ) { m_pSDKPlayer->SetSprinting( true ); } else { m_pSDKPlayer->SetSprinting( false ); } #endif // SDK_USE_SPRINTING // Get the movement angles. Vector vecForward, vecRight, vecUp; AngleVectors( mv->m_vecViewAngles, &vecForward, &vecRight, &vecUp ); vecForward.z = 0.0f; vecRight.z = 0.0f; VectorNormalize( vecForward ); VectorNormalize( vecRight ); // Copy movement amounts float flForwardMove = mv->m_flForwardMove; float flSideMove = mv->m_flSideMove; // Find the direction,velocity in the x,y plane. Vector vecWishDirection( ( ( vecForward.x * flForwardMove ) + ( vecRight.x * flSideMove ) ), ( ( vecForward.y * flForwardMove ) + ( vecRight.y * flSideMove ) ), 0.0f ); // Calculate the speed and direction of movement, then clamp the speed. float flWishSpeed = VectorNormalize( vecWishDirection ); flWishSpeed = clamp( flWishSpeed, 0.0f, mv->m_flMaxSpeed ); // Accelerate in the x,y plane. mv->m_vecVelocity.z = 0; Accelerate( vecWishDirection, flWishSpeed, sv_accelerate.GetFloat() ); Assert( mv->m_vecVelocity.z == 0.0f ); // Clamp the players speed in x,y. float flNewSpeed = VectorLength( mv->m_vecVelocity ); if ( flNewSpeed > mv->m_flMaxSpeed ) { float flScale = ( mv->m_flMaxSpeed / flNewSpeed ); mv->m_vecVelocity.x *= flScale; mv->m_vecVelocity.y *= flScale; } // Now reduce their backwards speed to some percent of max, if they are travelling backwards unless they are under some minimum if ( sdk_clamp_back_speed.GetFloat() < 1.0 && VectorLength( mv->m_vecVelocity ) > sdk_clamp_back_speed_min.GetFloat() ) { float flDot = DotProduct( vecForward, mv->m_vecVelocity ); // are we moving backwards at all? if ( flDot < 0 ) { Vector vecBackMove = vecForward * flDot; Vector vecRightMove = vecRight * DotProduct( vecRight, mv->m_vecVelocity ); // clamp the back move vector if it is faster than max float flBackSpeed = VectorLength( vecBackMove ); float flMaxBackSpeed = ( mv->m_flMaxSpeed * sdk_clamp_back_speed.GetFloat() ); if ( flBackSpeed > flMaxBackSpeed ) { vecBackMove *= flMaxBackSpeed / flBackSpeed; } // reassemble velocity mv->m_vecVelocity = vecBackMove + vecRightMove; } } // Add base velocity to the player's current velocity - base velocity = velocity from conveyors, etc. VectorAdd( mv->m_vecVelocity, player->GetBaseVelocity(), mv->m_vecVelocity ); // Calculate the current speed and return if we are not really moving. float flSpeed = VectorLength( mv->m_vecVelocity ); if ( flSpeed < 1.0f ) { // I didn't remove the base velocity here since it wasn't moving us in the first place. mv->m_vecVelocity.Init(); return; } // Calculate the destination. Vector vecDestination; vecDestination.x = mv->GetAbsOrigin().x + ( mv->m_vecVelocity.x * gpGlobals->frametime ); vecDestination.y = mv->GetAbsOrigin().y + ( mv->m_vecVelocity.y * gpGlobals->frametime ); vecDestination.z = mv->GetAbsOrigin().z; // Try moving to the destination. trace_t trace; TracePlayerBBox( mv->GetAbsOrigin(), vecDestination, PlayerSolidMask(), COLLISION_GROUP_PLAYER_MOVEMENT, trace ); if ( trace.fraction == 1.0f ) { // Made it to the destination (remove the base velocity). mv->SetAbsOrigin( trace.endpos ); VectorSubtract( mv->m_vecVelocity, player->GetBaseVelocity(), mv->m_vecVelocity ); // Save the wish velocity. mv->m_outWishVel += ( vecWishDirection * flWishSpeed ); // Try and keep the player on the ground. // NOTE YWB 7/5/07: Don't do this here, our version of CategorizePosition encompasses this test // StayOnGround(); return; } // Now try and do a step move. StepMove( vecDestination, trace ); // Remove base velocity. Vector baseVelocity = player->GetBaseVelocity(); VectorSubtract( mv->m_vecVelocity, baseVelocity, mv->m_vecVelocity ); // Save the wish velocity. mv->m_outWishVel += ( vecWishDirection * flWishSpeed ); // Try and keep the player on the ground. // NOTE YWB 7/5/07: Don't do this here, our version of CategorizePosition encompasses this test // StayOnGround(); }
//------------------------------------------------------------------------ void CRapid::Update(float frameTime, uint32 frameId) { FUNCTION_PROFILER( GetISystem(), PROFILE_GAME ); PlayStopRapidFireIfNeeded(); BaseClass::Update(frameTime, frameId); if (m_speed <= 0.0f && m_acceleration < 0.0001f) { FinishDeceleration(); return; } CActor* pOwnerActor = m_pWeapon->GetOwnerActor(); const bool isOwnerClient = pOwnerActor ? pOwnerActor->IsClient() : false; const bool isOwnerPlayer = pOwnerActor ? pOwnerActor->IsPlayer() : false; m_pWeapon->RequireUpdate(eIUS_FireMode); m_speed = m_speed + m_acceleration*frameTime; if (m_speed > m_fireParams->rapidparams.max_speed) { m_speed = m_fireParams->rapidparams.max_speed; m_rapidFlags &= ~eRapidFlag_accelerating; } if ((m_speed >= m_fireParams->rapidparams.min_speed) && !(m_rapidFlags & eRapidFlag_decelerating)) { float dt = 1.0f; if (cry_fabsf(m_speed)>0.001f && cry_fabsf(m_fireParams->rapidparams.max_speed)>0.001f) { dt = m_speed * (float)__fres(m_fireParams->rapidparams.max_speed); } CRY_ASSERT(m_fireParams->fireparams.rate > 0); m_next_shot_dt = 60.0f* (float)__fres((m_fireParams->fireparams.rate*dt)); if (CanFire(false)) { if (!OutOfAmmo()) { const bool firing = (m_rapidFlags & eRapidFlag_netShooting) || Shoot(true, m_fireParams->fireparams.autoReload); Firing(firing); } else { StopFire(); } } } else if (m_firing) { StopFire(); if (OutOfAmmo() && isOwnerPlayer) { m_pWeapon->Reload(); } } if ((m_speed < m_fireParams->rapidparams.min_speed) && (m_acceleration < 0.0f) && !(m_rapidFlags & eRapidFlag_decelerating)) Accelerate(m_fireParams->rapidparams.deceleration); UpdateRotation(frameTime); UpdateFiring(pOwnerActor, isOwnerClient, isOwnerPlayer, frameTime); }
void MovementController::Rotate(GLfloat r) { mObject->SetRotation(r); Accelerate(mAcceleration); }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CHL2WarsGameMovement::StrategicPlayerMove() { trace_t pm; Vector move; Vector forward, right, up; Vector wishvel; Vector wishdir; float wishspeed, heightchange; float maxspeed = strategic_cam_maxspeed.GetFloat(); // Server defined max speed CHL2WarsPlayer *warsplayer = dynamic_cast<CHL2WarsPlayer *>( player ); if( !warsplayer ) return; float speed = warsplayer->GetCamSpeed(); float maxacceleration = warsplayer->GetCamAcceleration(); float friction = warsplayer->GetCamFriction(); float stopspeed = warsplayer->GetCamStopSpeed(); // Determine our current height warsplayer->CalculateHeight( mv->GetAbsOrigin() ); // Determine movement angles AngleVectors (mv->m_vecViewAngles, &forward, &right, &up); up.z = 0.0f; right.z = 0.0f; VectorNormalize (up); VectorNormalize (right); VectorNormalize (forward); // Zoom direction // Copy movement amounts // Assume max move is 450.0, so we can scale it to the correct speed value // NOTE: Swapped fmove and umove in terms of usage. float smove = (mv->m_flSideMove/450.0f) * speed; float fmove = (mv->m_flForwardMove/450.0f) * speed; float umove = (mv->m_flUpMove/450.0f) * speed; // Zoom when there is no map boundary for (int i=0 ; i<2 ; i++) // Determine x and y parts of velocity wishvel[i] = up[i]*fmove + right[i]*smove; wishvel[2] = 0.0f; if( warsplayer->GetCamHeight() != -1 && warsplayer->GetCamHeight() > 2.0f ) ;//wishvel[2] = -warsplayer->GetCamHeight() * 4.0f; // Force player origin down else wishvel = wishvel + forward*umove*4.0; // Zooming is forward VectorCopy (wishvel, wishdir); // Determine maginitude of speed of move wishspeed = VectorNormalize(wishdir); // // Clamp to user defined wish speed // if (wishspeed > speed ) { VectorScale (wishvel, speed/wishspeed, wishvel); wishspeed = speed; } // // Clamp to server defined max speed // if (wishspeed > maxspeed ) { VectorScale (wishvel, maxspeed/wishspeed, wishvel); wishspeed = maxspeed; } if ( maxacceleration > 0.0 ) { // Set pmove velocity Accelerate ( wishdir, wishspeed, maxacceleration ); float spd = VectorLength( mv->m_vecVelocity ); if (spd < 1.0f) { mv->m_vecVelocity.Init(); return; } // Bleed off some speed, but if we have less than the bleed // threshhold, bleed the theshold amount. float control = (spd < stopspeed) ? stopspeed : spd; // Add the amount to the drop amount. float drop = control * friction * gpGlobals->frametime; // scale the velocity float newspeed = spd - drop; if (newspeed < 0) newspeed = 0; // Determine proportion of old speed we are using. newspeed /= spd; VectorScale( mv->m_vecVelocity, newspeed, mv->m_vecVelocity ); } else { VectorCopy( wishvel, mv->m_vecVelocity ); } #ifdef CLIENT_DLL if( cl_showmovementspeed.GetInt() == player->entindex() ) { engine->Con_NPrintf( 1, "CLIENT Movement speed: %6.1f | maxspeed: %6.1f | userspeed: %6.1f | pos: %6.1f %6.1f %6.1f | mins: %6.1f %6.1f %6.1f | maxs: %6.1f %6.1f %6.1f", mv->m_vecVelocity.Length(), maxspeed, speed, mv->GetAbsOrigin().x, mv->GetAbsOrigin().y, mv->GetAbsOrigin().z, GetPlayerMins().x, GetPlayerMins().y, GetPlayerMins().z, GetPlayerMaxs().x, GetPlayerMaxs().y, GetPlayerMaxs().z ); } #else if( sv_showmovementspeed.GetInt() == player->entindex() ) { engine->Con_NPrintf( 3, "SERVER Movement speed: %6.1f | maxspeed: %6.1f | userspeed: %6.1f | pos: %6.1f %6.1f %6.1f | mins: %6.1f %6.1f %6.1f | maxs: %6.1f %6.1f %6.1f", mv->m_vecVelocity.Length(), maxspeed, speed, mv->GetAbsOrigin().x, mv->GetAbsOrigin().y, mv->GetAbsOrigin().z, GetPlayerMins().x, GetPlayerMins().y, GetPlayerMins().z, GetPlayerMaxs().x, GetPlayerMaxs().y, GetPlayerMaxs().z ); } #endif // CLIENT_DLL //CheckVelocity(); // Store current height heightchange = mv->GetAbsOrigin().z; if( warsplayer->GetCamHeight() != -1 ) { //Vector vCamOffsetZ = Vector(0.0f, 0.0f, warsplayer->GetCameraOffset().z); //TracePlayerBBox( mv->GetAbsOrigin(), warsplayer->GetCamGroundPos()+vCamOffsetZ, PlayerSolidMask(), COLLISION_GROUP_PLAYER_MOVEMENT, pm ); TracePlayerBBox( mv->GetAbsOrigin(), warsplayer->GetCamGroundPos()+Vector(0, 0, warsplayer->GetCamMaxHeight()-48.0f), PlayerSolidMask(), COLLISION_GROUP_PLAYER_MOVEMENT, pm ); mv->SetAbsOrigin( pm.endpos ); //NDebugOverlay::Box( warsplayer->GetCamGroundPos()+vCamOffsetZ, -Vector(16, 16, 16), Vector(16, 16, 16), 255, 0, 0, 255, gpGlobals->frametime ); } // Try moving, only obstructed by the map boundaries. Vector destination; VectorMA( mv->GetAbsOrigin(), gpGlobals->frametime, mv->m_vecVelocity, destination ); TracePlayerBBox( mv->GetAbsOrigin(), destination, PlayerSolidMask(), COLLISION_GROUP_PLAYER_MOVEMENT, pm ); if (pm.fraction == 1) { mv->SetAbsOrigin( pm.endpos ); } else { // Try moving straight along out normal path. TryStrategicMove(); } // Determine new height and return player to the ground warsplayer->CalculateHeight( mv->GetAbsOrigin() ); if( warsplayer->GetCamHeight() != -1 ) { TracePlayerBBox( mv->GetAbsOrigin(), warsplayer->GetCamGroundPos(), PlayerSolidMask(), COLLISION_GROUP_PLAYER_MOVEMENT, pm ); mv->SetAbsOrigin( pm.endpos ); //NDebugOverlay::Box( pm.endpos, -Vector(16, 16, 16), Vector(16, 16, 16), 0, 255, 0, 255, gpGlobals->frametime ); // Determine new height again :) warsplayer->CalculateHeight( mv->GetAbsOrigin() ); } // Determine height change and notify input heightchange = mv->GetAbsOrigin().z - heightchange; #ifdef CLIENT_DLL if( heightchange > 0.1f ) { } #endif // CLIENT_DLL //CheckVelocity(); // Zero out velocity if in noaccel mode if ( maxacceleration < 0.0f ) { mv->m_vecVelocity.Init(); } }
//------------------------------------------------------------------------ void CRapid::Update(float frameTime, uint32 frameId) { FUNCTION_PROFILER( GetISystem(), PROFILE_GAME ); CSingle::Update(frameTime, frameId); if (m_speed <= 0.0f && m_acceleration < 0.0001f) { FinishDeceleration(); return; } m_pWeapon->RequireUpdate(eIUS_FireMode); m_speed = m_speed + m_acceleration*frameTime; if (m_speed > m_pShared->rapidparams.max_speed) { m_speed = m_pShared->rapidparams.max_speed; m_accelerating = false; } if ((m_speed >= m_pShared->rapidparams.min_speed) && (!m_decelerating)) { float dt = 1.0f; if (cry_fabsf(m_speed)>0.001f && cry_fabsf(m_pShared->rapidparams.max_speed>0.001f)) dt=m_speed/m_pShared->rapidparams.max_speed; m_next_shot_dt = 60.0f/(m_pShared->fireparams.rate*dt); bool canShoot = CanFire(false); if (canShoot) { if (!OutOfAmmo()) { if (m_netshooting) Firing(true); else Firing(Shoot(true, false)); if (m_firing && !(m_pShared->rapidparams.camshake_rotate.IsZero() && m_pShared->rapidparams.camshake_shift.IsZero())) { CActor *act = m_pWeapon->GetOwnerActor(); if (act && act->IsClient()) { IView *pView = g_pGame->GetIGameFramework()->GetIViewSystem()->GetActiveView(); if (pView) pView->SetViewShake(Ang3(m_pShared->rapidparams.camshake_rotate), m_pShared->rapidparams.camshake_shift, m_next_shot_dt/m_pShared->rapidparams.camshake_perShot, m_next_shot_dt/m_pShared->rapidparams.camshake_perShot, 0, 1); } } } else { Firing(false); Accelerate(m_pShared->rapidparams.deceleration); if (m_pWeapon->GetOwnerActor() && m_pWeapon->GetOwnerActor()->IsPlayer()) { SmokeEffect(); m_pWeapon->Reload(); } } } } else if (m_firing) { Firing(false); if (OutOfAmmo() && m_pWeapon->GetOwnerActor() && m_pWeapon->GetOwnerActor()->IsPlayer()) { SmokeEffect(); m_pWeapon->Reload(); } } if ((m_speed < m_pShared->rapidparams.min_speed) && (m_acceleration < 0.0f) && (!m_decelerating)) Accelerate(m_pShared->rapidparams.deceleration); UpdateRotation(frameTime); UpdateSound(frameTime); }