void asw_gimme_ammo_f(void) { CASW_Game_Resource *pGameResource = ASWGameResource(); if ( !pGameResource ) return; for (int i=0;i<pGameResource->GetMaxMarineResources();i++) { if (pGameResource->GetMarineResource(i) != NULL && pGameResource->GetMarineResource(i)->GetMarineEntity()) { CASW_Marine *pMarine = pGameResource->GetMarineResource(i)->GetMarineEntity(); for (int k=0;k<ASW_MAX_MARINE_WEAPONS;k++) { CASW_Weapon *pWeapon = pMarine->GetASWWeapon(k); if (!pWeapon) continue; // refill bullets in the gun pWeapon->m_iClip1 = pWeapon->GetMaxClip1(); pWeapon->m_iClip2 = pWeapon->GetMaxClip2(); // give the marine a load of ammo of that type pMarine->GiveAmmo(10000, pWeapon->GetPrimaryAmmoType()); pMarine->GiveAmmo(10000, pWeapon->GetSecondaryAmmoType()); } } } }
void CASW_Health_Regen::Think() { BaseClass::Think(); CBaseEntity* pEntity = NULL; while ((pEntity = gEntList.FindEntityByClassname( pEntity, "asw_marine" )) != NULL) { CASW_Marine *pMarine = dynamic_cast<CASW_Marine*>(pEntity); if (pMarine) { float currentHealth = pMarine->GetHealth(); float maxHealth = pMarine->GetMaxHealth(); int normalHealing = asw_marine_health_regen_amount.GetInt(); int lowHealing = asw_marine_health_regen_amount_low.GetInt(); int infestedLowHealing = asw_marine_health_regen_infestation_boost.GetInt() + asw_marine_health_regen_amount_low.GetInt(); float threshold = asw_marine_health_regen_threshold.GetFloat(); int medicHealing = asw_marine_health_regen_medicboost.GetInt(); int medicBoost = 0; if ( pMarine->GetMarineProfile() && pMarine->GetMarineProfile()->CanUseFirstAid() ) { medicBoost = medicHealing; } if (currentHealth < maxHealth) { //Check if this player is carrying a medkit, and don't heal them if they are. CASW_Weapon *pExtra = pMarine->GetASWWeapon(2); if (pExtra) { if (pExtra->Classify() == CLASS_ASW_MEDKIT && asw_marine_health_regen_medkitcheck.GetBool()) continue; } //Check if this marine is dead. if (currentHealth < 1) continue; if ((currentHealth / maxHealth) < threshold) { if (pMarine->IsInfested()) SetMarineHealth(pMarine, currentHealth + infestedLowHealing + medicBoost); else SetMarineHealth(pMarine, currentHealth + lowHealing + medicBoost); } else SetMarineHealth(pMarine, currentHealth + normalHealing + medicBoost); } } } SetNextThink( gpGlobals->curtime + asw_marine_health_regen_speed.GetFloat()); }
bool CASW_Weapon::AllowedToPickup(CASW_Marine *pMarine) { if (!pMarine || !ASWGameRules() || !pMarine->GetMarineResource()) return false; // check if we're swapping for an existing item int index = pMarine->GetWeaponPositionForPickup(GetClassname()); CASW_Weapon* pWeapon = pMarine->GetASWWeapon(index); const char* szSwappingClass = pWeapon ? pWeapon->GetClassname() : ""; // first check if the gamerules will allow it bool bAllowed = ASWGameRules()->MarineCanPickup(pMarine->GetMarineResource(), GetClassname(), szSwappingClass); #ifdef CLIENT_DLL m_bSwappingWeapon = ( pWeapon != NULL ); #endif return bAllowed; }
C_ASW_Weapon* C_ASW_Ammo_Drop::GetAmmoUseUnits( C_ASW_Marine *pMarine ) { if ( pMarine ) { CASW_Weapon *pWeapon = pMarine->GetActiveASWWeapon(); if ( !pWeapon || pWeapon->Classify() == CLASS_ASW_AMMO_SATCHEL ) { //pWeapon C_ASW_Weapon *pOtherWeapon = pMarine->GetASWWeapon( 0 ); if ( pOtherWeapon && pOtherWeapon != pWeapon ) { pWeapon = pOtherWeapon; } else { pOtherWeapon = pMarine->GetASWWeapon( 1 ); if ( pOtherWeapon && pOtherWeapon != pWeapon ) { pWeapon = pOtherWeapon; } } } if ( pWeapon && pWeapon->IsOffensiveWeapon() ) { int iAmmoType = pWeapon->GetPrimaryAmmoType(); int iGuns = pMarine->GetNumberOfWeaponsUsingAmmo( iAmmoType ); int iMaxAmmoCount = GetAmmoDef()->MaxCarry( iAmmoType, pMarine ) * iGuns; int iBullets = pMarine->GetAmmoCount( iAmmoType ); int iAmmoCost = CASW_Ammo_Drop_Shared::GetAmmoUnitCost( iAmmoType ); m_bEnoughAmmo = m_iAmmoUnitsRemaining >= iAmmoCost; if ( ( iBullets < iMaxAmmoCount ) && m_bEnoughAmmo ) { return pWeapon; } } } return NULL; }
//----------------------------------------------------------------------------- // Purpose: Only send to local player if this weapon is the active weapon and this marine is the active marine // Input : *pStruct - // *pVarData - // *pRecipients - // objectID - // Output : void* //----------------------------------------------------------------------------- void* SendProxy_SendASWActiveLocalWeaponDataTable( const SendProp *pProp, const void *pStruct, const void *pVarData, CSendProxyRecipients *pRecipients, int objectID ) { // Get the weapon entity CASW_Weapon *pWeapon = (CASW_Weapon*)pVarData; if ( pWeapon ) { // Only send this chunk of data to the commander of the marine carrying this weapon CASW_Player *pPlayer = pWeapon->GetCommander(); if ( pPlayer && pPlayer->GetMarine() == pWeapon->GetOwner() ) { pRecipients->SetOnly( pPlayer->GetClientIndex() ); } else { pRecipients->ClearAllRecipients(); } } return (void*)pVarData; }
int CASW_Ammo_Drop::GetWeaponAmmoInUnits( CASW_Marine *pMarine ) { if ( pMarine ) { CASW_Weapon *pWeapon = pMarine->GetActiveASWWeapon(); if ( pWeapon && pWeapon->IsOffensiveWeapon() && ( pWeapon->GetMaxClip1() > 0 ) ) { int iAmmoType = pWeapon->GetPrimaryAmmoType(); //int iGuns = pMarine->GetNumberOfWeaponsUsingAmmo( iAmmoType ); int iClipsRemaining = pMarine->GetAmmoCount( iAmmoType ) / pWeapon->GetMaxClip1(); int iAmmoCost = GetAmmoUnitCost( iAmmoType ); return iClipsRemaining * iAmmoCost; } else { return AMMO_UNITS_MAX; // no need for ammo if no offensive weapon } } return AMMO_UNITS_MAX; // no need for ammo if no marine }
void CASW_Item_Crate::Event_Killed( const CTakeDamageInfo &info ) { BaseClass::Event_Killed( info ); randomitemcriteria_t pCriteria; pCriteria.iItemLevel = 1; pCriteria.pszItemName = NULL; // weapon class pCriteria.iItemQuality = AE_NORMAL; float fQuality = RandomFloat(); if ( fQuality < 0.25f ) { pCriteria.iItemQuality = AE_RARE; } else if ( fQuality < 0.5f ) { pCriteria.iItemQuality = AE_COMMON; } pCriteria.vecAbsOrigin = GetAbsOrigin() + Vector(0, 0, 20); pCriteria.vecAbsAngles = GetAbsAngles(); CASW_Weapon* pWeapon = dynamic_cast<CASW_Weapon*>( ItemGeneration()->GenerateRandomItem( &pCriteria ) ); if ( pWeapon ) { // fill it with ammo int iPrimaryAmmo = pWeapon->GetDefaultClip1(); int iSecondaryAmmo = pWeapon->GetDefaultClip2(); pWeapon->SetClip1( iPrimaryAmmo ); pWeapon->SetClip2( iSecondaryAmmo ); if ( pWeapon->GetPrimaryAmmoType()!=-1 ) { int iBullets = GetAmmoDef()->MaxCarry( pWeapon->GetPrimaryAmmoType() ); pWeapon->SetPrimaryAmmoCount( iBullets - iPrimaryAmmo ); } } }
//----------------------------------------------------------------------------- // Purpose: Message handler for ASWOrderUseItemFX message //----------------------------------------------------------------------------- void CASW_Hud_Squad_Hotbar::MsgFunc_ASWOrderUseItemFX( bf_read &msg ) { int iMarine = msg.ReadShort(); C_ASW_Marine *pMarine = dynamic_cast<C_ASW_Marine*>(ClientEntityList().GetEnt(iMarine)); // turn iMarine ent index into the marine if ( !pMarine ) return; int iOrderType = msg.ReadShort(); int iInventorySlot = msg.ReadShort(); Vector vecPosition; vecPosition.x = msg.ReadFloat(); vecPosition.y = msg.ReadFloat(); vecPosition.z = msg.ReadFloat(); // loops through to see if we already have an order effect for this marine StopItemFX( pMarine ); const char *pszClassName = NULL; switch( iOrderType ) { case ASW_USE_ORDER_WITH_ITEM: { // check we have an item in that slot CASW_Weapon* pWeapon = pMarine->GetASWWeapon( iInventorySlot ); if ( !pWeapon || !pWeapon->GetWeaponInfo() || !pWeapon->GetWeaponInfo()->m_bOffhandActivate ) return; pszClassName = pWeapon->GetClassname(); } break; case ASW_USE_ORDER_HACK: { pszClassName = "asw_weapon_t75"; // for now, we're using the t75 icon for hacking } break; default: { Assert( false ); // unspecified order type return; } break; } //CNewParticleEffect *pEffect = pMarine->ParticleProp()->Create( "order_use_item", PATTACH_CUSTOMORIGIN, -1, vecPosition - pMarine->GetAbsOrigin() ); CNewParticleEffect *pEffect = pMarine->ParticleProp()->Create( "order_use_item", PATTACH_ABSORIGIN ); if ( pEffect ) { pMarine->ParticleProp()->AddControlPoint( pEffect, 1, pMarine, PATTACH_CUSTOMORIGIN ); pEffect->SetControlPoint( 1, vecPosition );//vecPosition - pMarine->GetAbsOrigin() for ( int i = 0; i < NUM_USE_ITEM_ORDER_CLASSES; i++ ) { if ( pszUseItemOrderClasses[i] && !Q_strcmp ( pszUseItemOrderClasses[i] , pszClassName ) ) { pEffect->SetControlPoint( 2, Vector( i, 0, 0 ) ); break; } } HotbarOrderEffectsList_t::IndexLocalType_t iIndex = m_hHotbarOrderEffects.AddToTail(); m_hHotbarOrderEffects[iIndex].iEffectID = iMarine; m_hHotbarOrderEffects[iIndex].pEffect = pEffect; } }
void CASW_Ammo_Drop::ActivateUseIcon( CASW_Marine* pMarine, int nHoldType ) { if ( nHoldType == ASW_USE_HOLD_START ) return; CASW_Weapon *pWeapon = GetAmmoUseUnits( pMarine ); if( pWeapon ) { int iAmmoType = pWeapon->GetPrimaryAmmoType(); int iGuns = pMarine->GetNumberOfWeaponsUsingAmmo( iAmmoType ); int iMaxAmmoCount = GetAmmoDef()->MaxCarry( iAmmoType, pMarine ) * iGuns; int iBullets = pMarine->GetAmmoCount( iAmmoType ); int iAmmoCost = GetAmmoUnitCost( iAmmoType ); int iClipsToGive = CASW_Ammo_Drop_Shared::GetAmmoClipsToGive( iAmmoType ); pMarine->SetAmmoCount( MIN( iBullets + pWeapon->GetMaxClip1() * iClipsToGive, iMaxAmmoCount ), iAmmoType ); m_iAmmoUnitsRemaining -= iAmmoCost; pMarine->GetMarineSpeech()->Chatter(CHATTER_USE); IGameEvent * event = gameeventmanager->CreateEvent( "ammo_pickup" ); if ( event ) { CASW_Player *pPlayer = pMarine->GetCommander(); event->SetInt( "userid", ( pPlayer ? pPlayer->GetUserID() : 0 ) ); event->SetInt( "entindex", pMarine->entindex() ); gameeventmanager->FireEvent( event ); } if ( m_iAmmoUnitsRemaining <= 0 ) { CTakeDamageInfo info; BaseClass::Event_Killed( info ); } CASW_Marine *pDeployer = m_hDeployer.Get(); if ( pDeployer && pMarine != pDeployer && !m_bSuppliedAmmo ) { m_bSuppliedAmmo = true; if ( pDeployer->GetCommander() ) { pDeployer->GetCommander()->AwardAchievement( ACHIEVEMENT_ASW_AMMO_RESUPPLY ); } } } else { if ( pMarine->IsInhabited() ) { CASW_Player *pCommander = pMarine->GetCommander(); if ( pCommander ) { CSingleUserRecipientFilter filter( pCommander ); EmitSound( filter, pMarine->entindex(), "ASW_Ammobag.Fail", NULL, 0.0f ); } } } }