bool CASW_Weapon::ShouldAlienFlinch(CBaseEntity *pAlien, const CTakeDamageInfo &info) { if (!GetWeaponInfo()) return false; float fFlinchChance = GetWeaponInfo()->m_fFlinchChance; CASW_Marine *pMarine = dynamic_cast<CASW_Marine*>(GetOwner()); if (asw_debug_alien_damage.GetBool()) Msg("BaseFlinch chance %f ", fFlinchChance); if (pMarine && pMarine->GetMarineProfile() && pMarine->GetMarineProfile()->GetMarineClass() == MARINE_CLASS_SPECIAL_WEAPONS) { // this is a special weapons marine, so we need to add our flinch bonus onto it fFlinchChance += GetWeaponInfo()->m_fStoppingPowerFlinchBonus * MarineSkills()->GetSkillBasedValueByMarine(pMarine, ASW_MARINE_SKILL_STOPPING_POWER); if (asw_debug_alien_damage.GetBool()) Msg("Boosted by specialweaps to %f ", fFlinchChance); } //CALL_ATTRIB_HOOK_FLOAT( fFlinchChance, mod_stopping ); if (pAlien) { int iHealth = pAlien->GetHealth(); int iDamage = info.GetDamage(); float fAlienHealth = float(iHealth + iDamage) / float(pAlien->GetMaxHealth()); fFlinchChance *= fAlienHealth; if (asw_debug_alien_damage.GetBool()) Msg("adjusted by alien health (%f) to %f ", fAlienHealth, fFlinchChance); } float f = random->RandomFloat(); bool bResult = ( f < fFlinchChance); if (asw_debug_alien_damage.GetBool()) Msg("random float is %f shouldflinch = %d\n", f, bResult); return bResult; }
void CASW_Weapon_Chainsaw::EndAttack( void ) { if ( m_fireState != FIRE_OFF ) { StartAttackOffSound(); #ifdef CLIENT_DLL DispatchParticleEffect( "mining_laser_exhaust", PATTACH_POINT_FOLLOW, this, "eject1" ); #endif } StopChainsawSound(); SetWeaponIdleTime( gpGlobals->curtime + 2.0 ); m_flNextPrimaryAttack = gpGlobals->curtime + GetWeaponInfo()->m_flFireRate; m_flNextSecondaryAttack = gpGlobals->curtime + GetWeaponInfo()->m_flFireRate; SetFiringState(FIRE_OFF); ClearIsFiring(); DestroyEffect(); }
/** * Fills the ammo array with the ammo currently owned by the local player */ void FillClientAmmo( int ammo[MAX_AMMO_TYPES] ) { int i; for ( i=0; i<MAX_AMMO_TYPES; ++i ) { ammo[i] = 0; } C_CSPlayer *localPlayer = CCSPlayer::GetLocalCSPlayer(); if ( !localPlayer ) return; for ( i=0; i<WEAPON_MAX; ++i ) { CSWeaponID gameWeaponID = (CSWeaponID)i; if ( gameWeaponID == WEAPON_NONE || gameWeaponID >= WEAPON_SHIELDGUN ) continue; const CCSWeaponInfo *info = GetWeaponInfo( gameWeaponID ); if ( !info ) continue; int clientAmmoType = info->iAmmoType; int clientAmmoCount = localPlayer->GetAmmoCount( clientAmmoType ); if ( clientAmmoCount > 0 ) { ammo[ clientAmmoType ] = max( ammo[ clientAmmoType ], clientAmmoCount ); } } }
int CallPriceForwardCSGO(int client, const char *weapon) { const char *weaponalias = GetTranslatedWeaponAlias(weapon); int weaponID = AliasToWeaponID(weaponalias); if (weaponID <= 0) { return -1; } void *info = GetWeaponInfo(weaponID); if (!info) { return -1; } const char *weapon_name = (const char *)((intptr_t)info + weaponNameOffset); int price = *(int *)((intptr_t)info + g_iPriceOffset); int changedprice = price; cell_t result = Pl_Continue; g_pPriceForward->PushCell(client); g_pPriceForward->PushString(weapon_name); g_pPriceForward->PushCellByRef(&changedprice); g_pPriceForward->Execute(&result); if (result == Pl_Continue) return -1; if (SetWeaponPrice(weaponID, changedprice)) return price; else return -1; }
/** * Returns true if the client can currently buy the weapon according to class/gamemode restrictions. Returns * true also if the player owns the weapon already. */ bool CanBuyWeapon( CSWeaponID currentPrimaryID, CSWeaponID currentSecondaryID, CSWeaponID weaponID ) { if ( currentPrimaryID == WEAPON_SHIELDGUN && weaponID == WEAPON_ELITE ) { return false; } if ( currentSecondaryID == WEAPON_ELITE && weaponID == WEAPON_SHIELDGUN ) { return false; } C_CSPlayer *pPlayer = C_CSPlayer::GetLocalCSPlayer(); if ( !pPlayer ) return false; CCSWeaponInfo *info = GetWeaponInfo( weaponID ); if ( !info ) return false; /// @TODO: assasination maps have a specific set of weapons that can be used in them. if ( info->m_iTeam != TEAM_UNASSIGNED && pPlayer->GetTeamNumber() != info->m_iTeam ) return false; return true; }
int CASW_Weapon_Assault_Shotgun::GetNumPellets() { if (GetMarine()) return MarineSkills()->GetSkillBasedValueByMarine(GetMarine(), ASW_MARINE_SKILL_VINDICATOR, ASW_MARINE_SUBSKILL_VINDICATOR_PELLETS); return GetWeaponInfo()->m_iNumPellets; }
float CASW_Weapon_Pistol::GetFireRate( void ) { CASW_Marine *pMarine = GetMarine(); float flRate = GetWeaponInfo()->m_flFireRate; // player firing rate if (!pMarine || pMarine->IsInhabited()) { return flRate; } #ifdef CLIENT_DLL return flRate; #else float randomness = 0.1f * random->RandomFloat() - 0.05f; // AI firing rate: depends on distance to enemy if (!pMarine->GetEnemy()) return 0.3f + randomness; float dist = pMarine->GetAbsOrigin().DistTo(pMarine->GetEnemy()->GetAbsOrigin()); if (dist > 500) return 0.3f + randomness; if (dist < 100) return 0.14f + randomness; float factor = (dist - 100) / 400.0f; return 0.14f + factor * 0.16f + randomness; #endif }
bool CBasePlayerWeapon::DefaultReload( int iAnim, float fDelay, int body ) { if( m_pPlayer->m_rgAmmo[ PrimaryAmmoIndex() ] <= 0 ) return false; int j = min( GetWeaponInfo()->GetMaxMagazine() - m_iClip, m_pPlayer->m_rgAmmo[ PrimaryAmmoIndex() ] ); if( j == 0 ) return false; m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + fDelay; #ifdef SERVER_DLL //The server doesn't pass this, so always 0 it out. - Solokiller //TODO: why? - Solokiller body = 0; #endif //!!UNDONE -- reload sound goes here !!! SendWeaponAnim( iAnim, body ); m_fInReload = true; m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 3; return true; }
void CASW_Weapon::Precache() { BaseClass::Precache(); PrecacheModel( "models/swarm/Bayonet/bayonet.mdl" ); PrecacheScriptSound("ASW_Rifle.ReloadA"); PrecacheScriptSound("ASW_Rifle.ReloadB"); PrecacheScriptSound("ASW_Rifle.ReloadC"); PrecacheScriptSound("FastReload.Success"); PrecacheScriptSound("FastReload.Miss"); const CASW_WeaponInfo* pWeaponInfo = GetWeaponInfo(); if ( pWeaponInfo ) { // find equipment list index if ( ASWEquipmentList() ) { if ( pWeaponInfo->m_bExtra ) m_iEquipmentListIndex = ASWEquipmentList()->GetExtraIndex(GetClassname()); else m_iEquipmentListIndex = ASWEquipmentList()->GetRegularIndex(GetClassname()); } if ( pWeaponInfo->szDisplayModel && pWeaponInfo->szDisplayModel[0] ) { CBaseEntity::PrecacheModel( pWeaponInfo->szDisplayModel ); } if ( pWeaponInfo->szDisplayModel2 && pWeaponInfo->szDisplayModel2[0] ) { CBaseEntity::PrecacheModel( pWeaponInfo->szDisplayModel2 ); } } }
void CBasePlayerWeapon::Precache() { BaseClass::Precache(); m_pWeaponInfo = g_WeaponInfoCache.LoadWeaponInfo( m_iId, GetClassname() ); m_iDefaultAmmo = GetWeaponInfo()->GetDefaultAmmo(); }
float CASW_Weapon::GetFireRate() { float flRate = GetWeaponInfo()->m_flFireRate; //CALL_ATTRIB_HOOK_FLOAT( flRate, mod_fire_rate ); return flRate; }
float CASW_Weapon_Flechette::GetFireRate() { //float flRate = 0.125f; float flRate = GetWeaponInfo()->m_flFireRate; //CALL_ATTRIB_HOOK_FLOAT( flRate, mod_fire_rate ); return flRate; }
void CASW_Weapon::Spawn() { //InitializeAttributes(); BaseClass::Spawn(); SetModel( GetWorldModel() ); m_nSkin = GetWeaponInfo()->m_iPlayerModelSkin; }
bool SetWeaponPrice(int weaponID, int price) { void *info = GetWeaponInfo(weaponID); if (!info) { return false; } *(int *)((intptr_t)info+g_iPriceOffset) = price; return true; }
float CASW_Weapon_Autogun::GetWeaponDamage() { float flDamage = GetWeaponInfo()->m_flBaseDamage; if ( GetMarine() ) { flDamage += MarineSkills()->GetSkillBasedValueByMarine(GetMarine(), ASW_MARINE_SKILL_AUTOGUN, ASW_MARINE_SUBSKILL_AUTOGUN_DMG); } return flDamage; }
/** * Returns true if the weapon ID is for a secondary weapon */ static bool IsSecondaryWeaponID( CSWeaponID id ) { if ( id == WEAPON_SHIELDGUN ) return false; CCSWeaponInfo *info = GetWeaponInfo( id ); if ( !info ) return false; return IsSecondaryWeaponClassID( info->m_WeaponType ); }
float CASW_Weapon_Sniper_Rifle::GetWeaponDamage() { float flDamage = GetWeaponInfo()->m_flBaseDamage; if ( GetMarine() ) { flDamage += MarineSkills()->GetSkillBasedValueByMarine(GetMarine(), ASW_MARINE_SKILL_ACCURACY, ASW_MARINE_SUBSKILL_ACCURACY_SNIPER_RIFLE_DMG); } return flDamage; }
float CASW_Weapon_Shotgun::GetWeaponDamage() { float flDamage = GetWeaponInfo()->m_flBaseDamage; if ( GetMarine() ) { flDamage += MarineSkills()->GetSkillBasedValueByMarine(GetMarine(), ASW_MARINE_SKILL_ACCURACY, ASW_MARINE_SUBSKILL_ACCURACY_SHOTGUN_DMG); } //CALL_ATTRIB_HOOK_FLOAT( flDamage, mod_damage_done ); return flDamage; }
float CASW_Weapon_Assault_Shotgun::GetWeaponDamage() { //float flDamage = 7.0f; float flDamage = GetWeaponInfo()->m_flBaseDamage; if ( GetMarine() ) { flDamage += MarineSkills()->GetSkillBasedValueByMarine(GetMarine(), ASW_MARINE_SKILL_VINDICATOR, ASW_MARINE_SUBSKILL_VINDICATOR_DAMAGE); } //CALL_ATTRIB_HOOK_FLOAT( flDamage, mod_damage_done ); return flDamage; }
float CASW_Weapon_Minigun::GetWeaponDamage() { //float flDamage = 7.0f; float flDamage = GetWeaponInfo()->m_flBaseDamage; if ( GetMarine() ) { flDamage += MarineSkills()->GetSkillBasedValueByMarine(GetMarine(), ASW_MARINE_SKILL_AUTOGUN, ASW_MARINE_SUBSKILL_AUTOGUN_DMG); } //CALL_ATTRIB_HOOK_FLOAT( flDamage, mod_damage_done ); return flDamage; }
bool SetWeaponPrice(const char *weapon, int price) { const char *weaponalias = GetTranslatedWeaponAlias(weapon); int weaponID = AliasToWeaponID(weaponalias); if (weaponID <= 0) { return false; } void *info = GetWeaponInfo(weaponID); if (!info) { return false; } *(int *)((intptr_t)info+g_iPriceOffset) = price; return true; }
int CHEGrenade::__MAKE_VHOOK(GetItemInfo)(ItemInfo *p) { auto info = GetWeaponInfo(WEAPON_HEGRENADE); p->pszName = STRING(pev->classname); p->pszAmmo1 = "HEGrenade"; p->iMaxAmmo1 = info ? info->maxRounds : MAX_AMMO_HEGRENADE; p->iMaxClip = info ? info->gunClipSize : WEAPON_NOCLIP; p->pszAmmo2 = NULL; p->iMaxAmmo2 = -1; p->iSlot = 3; p->iPosition = 1; p->iId = m_iId = WEAPON_HEGRENADE; p->iWeight = HEGRENADE_WEIGHT; p->iFlags = ITEM_FLAG_LIMITINWORLD | ITEM_FLAG_EXHAUSTIBLE; return 1; }
float CASW_Weapon::GetReloadTime() { // can adjust for marine's weapon skill here float fReloadTime = GetWeaponInfo()->flReloadTime; if (GetMarine()) { float fSpeedScale = MarineSkills()->GetSkillBasedValueByMarine(GetMarine(), ASW_MARINE_SKILL_RELOADING, ASW_MARINE_SUBSKILL_RELOADING_SPEED_SCALE); fReloadTime *= fSpeedScale; // riflemod: bots reload very fast because they are stupid to die // during long reloads if ( !GetMarine()->IsInhabited() ) { fReloadTime = 1.0f; } } //CALL_ATTRIB_HOOK_FLOAT( fReloadTime, mod_reload_time ); return fReloadTime; }
void CASW_Weapon_Chainsaw::Fire( const Vector &vecOrigSrc, const Vector &vecDir ) { CASW_Marine *pMarine = GetMarine(); if ( !pMarine ) { return; } StopAttackOffSound(); StartChainsawSound(); if ( m_flFireAnimTime < gpGlobals->curtime ) { pMarine->DoAnimationEvent( PLAYERANIMEVENT_FIRE_GUN_PRIMARY ); m_flFireAnimTime = gpGlobals->curtime + 0.1f; } Vector vecDest = vecOrigSrc + (vecDir * ASW_CHAINSAW_RANGE); bool bDamageTime = m_flDmgTime < gpGlobals->curtime; bool bHit = false; Ray_t ray; ray.Init( vecOrigSrc, vecDest, Vector( -5, -5, -5 ), Vector( 5, 5, 25 ) ); CBaseEntity *(pEntities[ 8 ]); CHurtableEntitiesEnum hurtableEntities( pEntities, 8 ); partition->EnumerateElementsAlongRay( PARTITION_ENGINE_NON_STATIC_EDICTS | PARTITION_ENGINE_SOLID_EDICTS, ray, false, &hurtableEntities ); trace_t tr; for ( int i = 0; i < hurtableEntities.GetCount(); ++i ) { CBaseEntity *pEntity = pEntities[ i ]; if ( pEntity == NULL || pEntity == pMarine ) continue; bHit = true; if ( bDamageTime ) { // wide mode does damage to the ent, and radius damage if ( pEntity->m_takedamage != DAMAGE_NO ) { CTraceFilterOnlyHitThis filter( pEntity ); UTIL_TraceHull( vecOrigSrc, vecDest, Vector( -5, -5, -2 ), Vector( 5, 5, 25 ), MASK_SHOT, &filter, &tr ); ClearMultiDamage(); float fDamage = 0.5f * GetWeaponInfo()->m_flBaseDamage + MarineSkills()->GetSkillBasedValueByMarine( pMarine, ASW_MARINE_SKILL_MELEE, ASW_MARINE_SUBSKILL_MELEE_DMG ); CTakeDamageInfo info( this, pMarine, fDamage * g_pGameRules->GetDamageMultiplier(), DMG_SLASH ); info.SetWeapon( this ); CalculateMeleeDamageForce( &info, vecDir, tr.endpos ); pEntity->DispatchTraceAttack( info, vecDir, &tr ); ApplyMultiDamage(); } // radius damage a little more potent in multiplayer. #ifndef CLIENT_DLL //RadiusDamage( CTakeDamageInfo( this, pMarine, sk_plr_dmg_asw_ml.GetFloat() * g_pGameRules->GetDamageMultiplier() / 4, DMG_ENERGYBEAM | DMG_BLAST | DMG_ALWAYSGIB ), tr.endpos, 128, CLASS_NONE, NULL ); #endif } } if ( bHit ) { if ( bDamageTime ) { m_bIsFiring = true; m_flLastHitTime = gpGlobals->curtime; m_flTargetChainsawPitch = 0.0f; #ifndef CLIENT_DLL pMarine->OnWeaponFired( this, 1 ); #endif if ( !pMarine->IsAlive() ) return; // uses 5 ammo/second if ( gpGlobals->curtime >= m_flAmmoUseTime ) { // chainsaw no longer uses ammo m_flAmmoUseTime = gpGlobals->curtime + 0.2; /* // decrement ammo //m_iClip1 -= 1; #ifdef GAME_DLL CASW_Marine *pMarine = GetMarine(); if (pMarine && m_iClip1 <= 0 && pMarine->GetAmmoCount(m_iPrimaryAmmoType) <= 0 ) { // check he doesn't have ammo in an ammo bay CASW_Weapon_Ammo_Bag* pAmmoBag = dynamic_cast<CASW_Weapon_Ammo_Bag*>(pMarine->GetASWWeapon(0)); if (!pAmmoBag) pAmmoBag = dynamic_cast<CASW_Weapon_Ammo_Bag*>(pMarine->GetASWWeapon(1)); if (!pAmmoBag || !pAmmoBag->CanGiveAmmoToWeapon(this)) pMarine->GetMarineSpeech()->Chatter(CHATTER_NO_AMMO); } #endif */ } m_flDmgTime = gpGlobals->curtime + ASW_CHAINSAW_DISCHARGE_INTERVAL; if ( m_flShakeTime < gpGlobals->curtime ) { CASW_Player *pPlayer = pMarine->GetCommander(); if (pPlayer && pMarine->IsInhabited()) { // #ifndef CLIENT_DLL // if (gpGlobals->maxClients == 1) // only shake the screen from the server in singleplayer (in multi it'll be predicted) // { // ASW_TransmitShakeEvent( pPlayer, 5.0f, 100.0f, 1.75f, SHAKE_START ); // } // #else // ASW_TransmitShakeEvent( pPlayer, 5.0f, 100.0f, 1.75f, SHAKE_START ); // #endif } m_flShakeTime = gpGlobals->curtime + 0.5; } } Vector vecUp, vecRight; QAngle angDir; VectorAngles( vecDir, angDir ); AngleVectors( angDir, NULL, &vecRight, &vecUp ); Vector tmpSrc = vecOrigSrc + (vecUp * -8) + (vecRight * 3); //UTIL_ImpactTrace( &tr, DMG_SLASH ); UpdateEffect( tmpSrc, tr.endpos ); } }
int CBasePlayerWeapon::PrimaryAmmoIndex() const { return GetWeaponInfo()->GetPrimaryAmmo() ? GetWeaponInfo()->GetPrimaryAmmo()->GetID() : WEAPON_NOCLIP; }
int CBasePlayerWeapon::SecondaryAmmoIndex() const { //Used to return -1 unconditionally. - Solokiller return GetWeaponInfo()->GetSecondaryAmmo() ? GetWeaponInfo()->GetSecondaryAmmo()->GetID() : WEAPON_NOCLIP; }
int CASW_Weapon_Shotgun::GetNumPellets() { return GetWeaponInfo()->m_iNumPellets; }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CASW_Weapon_Chainsaw::PrimaryAttack( void ) { // If my clip is empty (and I use clips) start reload //if ( UsesClipsForAmmo1() && !m_iClip1 ) //{ //Reload(); //return; //} CASW_Player *pPlayer = GetCommander(); CASW_Marine *pMarine = GetMarine(); if ( !pMarine || !pMarine->IsAlive()) { EndAttack(); return; } // don't fire underwater if ( pMarine->GetWaterLevel() == 3 ) { if ( m_fireState != FIRE_OFF || m_hBeam ) { EndAttack(); } else { WeaponSound( EMPTY ); } m_flNextPrimaryAttack = gpGlobals->curtime + GetWeaponInfo()->m_flFireRate; m_flNextSecondaryAttack = gpGlobals->curtime + GetWeaponInfo()->m_flFireRate; return; } #ifdef GAME_DLL // check for turning on lag compensation if (pPlayer && pMarine->IsInhabited()) { CASW_Lag_Compensation::RequestLagCompensation( pPlayer, pPlayer->GetCurrentUserCommand() ); } #endif Vector vecSrc = pMarine->Weapon_ShootPosition( ); Vector vecAiming = vec3_origin; if ( pPlayer && pMarine->IsInhabited() ) { vecAiming = pPlayer->GetAutoaimVectorForMarine(pMarine, GetAutoAimAmount(), GetVerticalAdjustOnlyAutoAimAmount()); // 45 degrees = 0.707106781187 } else { #ifndef CLIENT_DLL vecAiming = pMarine->GetActualShootTrajectory( vecSrc ); #endif } // make vecaiming go down at 45 degrees vecAiming.z = 0; VectorNormalize(vecAiming); vecAiming.z = -1.0f; VectorNormalize(vecAiming); switch( m_fireState ) { case FIRE_OFF: { //if ( !HasAmmo() ) //{ //m_flNextPrimaryAttack = gpGlobals->curtime + 0.25; //m_flNextSecondaryAttack = gpGlobals->curtime + 0.25; //WeaponSound( EMPTY ); //return; //} m_flAmmoUseTime = gpGlobals->curtime;// start using ammo ASAP. SendWeaponAnim( ACT_VM_PRIMARYATTACK ); m_flShakeTime = 0; m_flStartFireTime = gpGlobals->curtime; SetWeaponIdleTime( gpGlobals->curtime + 0.1 ); m_flDmgTime = gpGlobals->curtime + ASW_CHAINSAW_PULSE_INTERVAL; SetFiringState(FIRE_STARTUP); } break; case FIRE_STARTUP: { Fire( vecSrc, vecAiming ); #ifndef CLIENT_DLL pMarine->OnWeaponFired( this, 1 ); #endif if ( gpGlobals->curtime >= ( m_flStartFireTime + ASW_CHAINSAW_CHARGE_UP_TIME ) ) { //EmitSound( "ASW_Chainsaw.AttackLoop" ); SetFiringState(FIRE_CHARGE); } if ( !HasAmmo() ) { EndAttack(); m_flNextPrimaryAttack = gpGlobals->curtime + 1.0; m_flNextSecondaryAttack = gpGlobals->curtime + 1.0; } } break; case FIRE_CHARGE: { Fire( vecSrc, vecAiming ); #ifndef CLIENT_DLL pMarine->OnWeaponFired( this, 1 ); #endif if ( !HasAmmo() ) { EndAttack(); m_flNextPrimaryAttack = gpGlobals->curtime + 1.0; m_flNextSecondaryAttack = gpGlobals->curtime + 1.0; } } break; } }