MCPcopy Create free account
hub / github.com/ddnet/ddnet / FireWeapon

Method FireWeapon

src/game/server/entities/character.cpp:443–645  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

441}
442
443void CCharacter::FireWeapon()
444{
445 if(m_ReloadTimer != 0)
446 {
447 if(m_LatestInput.m_Fire & 1)
448 {
449 Antibot()->OnHammerFireReloading(m_pPlayer->GetCid());
450 }
451 return;
452 }
453
454 DoWeaponSwitch();
455 vec2 MouseTarget = vec2(m_LatestInput.m_TargetX, m_LatestInput.m_TargetY);
456 vec2 Direction = normalize(MouseTarget);
457
458 bool FullAuto = false;
459 if(m_Core.m_ActiveWeapon == WEAPON_GRENADE || m_Core.m_ActiveWeapon == WEAPON_SHOTGUN || m_Core.m_ActiveWeapon == WEAPON_LASER)
460 FullAuto = true;
461 if(m_Core.m_Jetpack && m_Core.m_ActiveWeapon == WEAPON_GUN)
462 FullAuto = true;
463 // allow firing directly after coming out of freeze or being unfrozen
464 // by something
465 if(m_FrozenLastTick)
466 FullAuto = true;
467
468 // don't fire hammer when player is deep and sv_deepfly is disabled
469 if(!g_Config.m_SvDeepfly && m_Core.m_ActiveWeapon == WEAPON_HAMMER && m_Core.m_DeepFrozen)
470 return;
471
472 // check if we gonna fire
473 bool WillFire = false;
474 if(CountInput(m_LatestPrevInput.m_Fire, m_LatestInput.m_Fire).m_Presses)
475 WillFire = true;
476
477 if(FullAuto && (m_LatestInput.m_Fire & 1) && m_Core.m_aWeapons[m_Core.m_ActiveWeapon].m_Ammo)
478 WillFire = true;
479
480 if(!WillFire)
481 return;
482
483 if(m_FreezeTime)
484 {
485 // Timer stuff to avoid shrieking orchestra caused by unfreeze-plasma
486 if(m_PainSoundTimer <= 0 && !(m_LatestPrevInput.m_Fire & 1))
487 {
488 m_PainSoundTimer = 1 * Server()->TickSpeed();
489 GameServer()->CreateSound(m_Pos, SOUND_PLAYER_PAIN_LONG, TeamMask()); // NOLINT(clang-analyzer-unix.Malloc)
490 }
491 return;
492 }
493
494 // check for ammo
495 if(!m_Core.m_aWeapons[m_Core.m_ActiveWeapon].m_Ammo)
496 return;
497
498 vec2 ProjStartPos = m_Pos + Direction * GetProximityRadius() * 0.75f;
499
500 switch(m_Core.m_ActiveWeapon)

Callers

nothing calls this directly

Calls 15

normalizeFunction · 0.85
CountInputFunction · 0.85
lengthFunction · 0.85
ClampVelFunction · 0.85
OnHammerFireReloadingMethod · 0.80
TickSpeedMethod · 0.80
CreateSoundMethod · 0.80
OnHammerFireMethod · 0.80
IsAliveMethod · 0.80
CreateHammerHitMethod · 0.80
OnHammerHitMethod · 0.80
ServerClass · 0.50

Tested by

no test coverage detected