Пример #1
0
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
bool CWarsWeapon::IsWeaponVisible( void )
{
	CBaseViewModel *vm = NULL;

	CUnitBase *pUnit;

	CBasePlayer *pOwner = NULL;
	if( GetOwner() )
	{
		pUnit = GetOwner()->MyUnitPointer();
		if( pUnit && pUnit->GetCommander() )
		{
			pOwner = ToBasePlayer( pUnit->GetCommander() );
		}
	}

	if ( pOwner )
	{
		vm = pOwner->GetViewModel( m_nViewModelIndex );
		if ( vm )
			return ( !vm->IsEffectActive(EF_NODRAW) );
	}

	return BaseClass::IsWeaponVisible();
}
Пример #2
0
//-----------------------------------------------------------------------------
// Purpose: Show/hide weapon and corresponding view model if any
// Input  : visible - 
//-----------------------------------------------------------------------------
void CWarsWeapon::SetWeaponVisible( bool visible )
{
	CBaseViewModel *vm = NULL;
	CUnitBase *pUnit;

	if( GetOwner() )
	{
		pUnit = GetOwner()->MyUnitPointer();
		if( pUnit && pUnit->GetCommander() )
		{
			CBasePlayer *pOwner = ToBasePlayer( pUnit->GetCommander() );
			if ( pOwner )
			{
				vm = pOwner->GetViewModel( m_nViewModelIndex );
			}
		}
	}

	if ( vm )
	{
		if ( visible )
		{
			vm->RemoveEffects( EF_NODRAW );
		}
		else
		{
			vm->AddEffects( EF_NODRAW );
		}
	}
	BaseClass::SetWeaponVisible( visible );
}
Пример #3
0
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CWarsWeapon::GetShootOriginAndDirection( Vector &vShootOrigin, Vector &vShootDirection)
{
	CBaseEntity *pOwner = GetOwner();
	if( !pOwner )
		return;

	CUnitBase *pUnit = pOwner->MyUnitPointer();
	if( !pUnit )
		return;

#if 0
#ifdef CLIENT_DLL
	if( pUnit->GetCommander() && !ShouldDrawLocalPlayer() )
	{
		QAngle vDummy;
		C_BasePlayer *player = ToBasePlayer( pUnit->GetCommander() );
		C_BaseViewModel *vm = player ? player->GetViewModel( 0 ) : NULL;
		if ( vm )
		{
			int iAttachment = vm->LookupAttachment( "muzzle" );
			if ( vm->GetAttachment( iAttachment, vShootOrigin, vDummy ) )
			{
				AngleVectors( QAngle(pUnit->m_fEyePitch, pUnit->m_fEyeYaw, 0.0), &vShootDirection );
				return;
			}
		}
	}
#endif // CLIENT_DLL
#endif // 0
	vShootOrigin = pUnit->Weapon_ShootPosition();
	AngleVectors( QAngle(pUnit->m_fEyePitch, pUnit->m_fEyeYaw, 0.0), &vShootDirection );
}
Пример #4
0
void MapUnits( boost::python::object method )
{
	CUnitBase *pUnit;
	UnitListInfo *pUnitList;
	for( pUnitList=g_pUnitListHead; pUnitList; pUnitList=pUnitList->m_pNext )
	{
		// For each unit
		for( pUnit=pUnitList->m_pHead; pUnit; pUnit=pUnit->GetNext() )
		{
			method( pUnit->GetPyInstance() );
		}
	}
}
Пример #5
0
//-----------------------------------------------------------------------------
// Regenerate the texture
//-----------------------------------------------------------------------------
void CDensityTextureRegen::RegenerateTextureBits( ITexture *pTexture, IVTFTexture *pVTFTexture, Rect_t *pSubRect )
{
	unsigned char *imageData = pVTFTexture->ImageData( 0, 0, 0 );
	int x, y, unitx, unity, offset, width, height, radius;

	Msg("Generating density texture...\n");

	width = pVTFTexture->Width();
	height = pVTFTexture->Height();

	memset( imageData, 0, width * height );

	CUnitBase *pUnit;
	CUnitBase **pList = g_Unit_Manager.AccessUnits();
	for( int i = 0; i < g_Unit_Manager.NumUnits(); i++ )
	{
		pUnit = pList[i];
		DensityWeightsMap map;
		map.Init( pUnit );
		map.SetType( DENSITY_GAUSSIAN );
		map.OnCollisionSizeChanged();
		

		const Vector &vOrigin = pUnit->GetAbsOrigin();
		unitx = (vOrigin.x + (FOW_WORLDSIZE / 2)) / (float)DENSITY_TILESIZE;
		unity = (vOrigin.y + (FOW_WORLDSIZE / 2)) / (float)DENSITY_TILESIZE;
		radius = (int)((pUnit->CollisionProp()->BoundingRadius2D() * 2) / DENSITY_TILESIZE);

		Msg("%d Density %d %d %d %d %d %d %d\n", pUnit->entindex(), map.GetSizeX(), map.GetSizeY(), unitx, unity, radius, MAX(unity-radius, 0), MIN(unity+radius, height) );

		for( y = MAX(unity-radius, 0); y < MIN(unity+radius, height); y++ )
		{
			for( x = MAX(unitx-radius, 0); x < MIN(unitx+radius, width); x++ )
			{
				offset = ( x + y * width );

				Vector vTest = Vector(
							x * DENSITY_TILESIZE - ( FOW_WORLDSIZE / 2 ),
							y * DENSITY_TILESIZE - ( FOW_WORLDSIZE / 2 ),
							0.0f	
						);

				imageData[offset] += map.Get( vTest ) * 255;
			}
		}
	}
}
Пример #6
0
// get the player owner of this weapon (either the unit's commander if the weapon is
//  being held by unit, or the player directly if a player is holding this weapon)
CHL2WarsPlayer* CWarsWeapon::GetCommander()
{
	CHL2WarsPlayer *pOwner = NULL;
	CUnitBase *pUnit = NULL;

	pUnit = dynamic_cast<CUnitBase*>( GetOwner() );
	if ( pUnit )
	{
		pOwner = pUnit->GetCommander();
	}
	else
	{
		pOwner = ToHL2WarsPlayer( dynamic_cast<CBasePlayer*>( GetOwner() ) );
	}

	return pOwner;
}
Пример #7
0
void CPotentialField::Update()
{
	int iPosX, iPosY, iMinX, iMinY, iMaxX, iMaxY, x, y;
	CUnitBase *pUnit;
	CUnitBase **ppUnits = g_Unit_Manager.AccessUnits();
	int i;
	for ( i = 0; i < g_Unit_Manager.NumUnits(); i++ )
	{
		pUnit = ppUnits[i];

		if( !pUnit->IsSolid() || !pUnit->CanBeSeen() )
			continue;

		const Vector &origin = pUnit->GetAbsOrigin();

		iPosX = (origin.x + (PF_SIZE / 2)) / (float)PF_TILESIZE;
		iPosY = (origin.y + (PF_SIZE / 2)) / (float)PF_TILESIZE;

		iMinX = MAX(iPosX-PF_CONSIDER, 0);
		iMaxX = MIN(PF_SIZE-1, iPosX+PF_CONSIDER);
		iMinY = MAX(iPosY-PF_CONSIDER, 0);
		iMaxY = MIN(PF_SIZE-1, iPosY+PF_CONSIDER);

		for(x=iMinX; x <= iMaxX; x++)
		{
			for(y=iMinY; y <= iMaxY; y++)
			{
				m_Density[x][y] += gaussian(x-iPosX, y-iPosY, unit_potential_stdev.GetFloat());
				m_AvgVelocities[x][y] += pUnit->GetAbsVelocity()*m_Density[x][y];
			}
		}
	};

	for(x=0; x<PF_ARRAYSIZE; x++)
	{
		for(y=0; y<PF_ARRAYSIZE; y++)
		{
			if( m_Density[x][y] != 0 )
				m_AvgVelocities[x][y] /=  m_Density[x][y];
		}
	}
}
Пример #8
0
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CWarsWeapon::SetViewModel()
{
	CUnitBase *pUnit;
	CHL2WarsPlayer *pOwner;

	pUnit = GetOwner()->MyUnitPointer();
	if ( pUnit )
	{
		pOwner = pUnit->GetCommander();
		if( pOwner )
		{
			CBaseViewModel *vm = pOwner->GetViewModel( m_nViewModelIndex );
			if ( vm == NULL )
				return;
			Assert( vm->ViewModelIndex() == m_nViewModelIndex );
			vm->SetWeaponModel( GetViewModel( m_nViewModelIndex ), this );
		}
	}
	BaseClass::SetViewModel();
}
Пример #9
0
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
Vector CUnitBase::GetShootEnemyDir( Vector &shootOrigin, bool noisy )
{
	CBaseEntity *pEnemy = GetEnemy();

	if( !pEnemy ) 
	{
        Vector forward;
        AngleVectors( GetLocalAngles(), &forward );
		return forward;
	}

    const Vector &vecEnemy = pEnemy->GetAbsOrigin();

	Vector vecEnemyOffset;
	CUnitBase *pUnit = pEnemy->MyUnitPointer();
    if( pUnit )
        vecEnemyOffset = pUnit->BodyTarget( shootOrigin, noisy ) - vecEnemy;
    else
        vecEnemyOffset = vec3_origin;
        
    Vector retval = vecEnemyOffset + vecEnemy - shootOrigin;
    VectorNormalize( retval );
    return retval;
}
Пример #10
0
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CWarsWeapon::PrimaryAttack( void )
{
	VPROF_BUDGET( "CWarsWeapon::PrimaryAttack", VPROF_BUDGETGROUP_UNITS );

	CUnitBase *pOwner = GetOwner()  ? GetOwner()->MyUnitPointer() : NULL;
	if( !pOwner )
		return;

#ifndef CLIENT_DLL
	if( m_bEnableBurst )
	{
		// Auto reset burst shots next time we fire
		if( m_nBurstShotsRemaining <= 0 )
		{
			m_nBurstShotsRemaining = GetRandomBurst();
		}
	}
#endif // CLIENT_DLL

	pOwner->DoMuzzleFlash();
	
	SendWeaponAnim( GetPrimaryAttackActivity() );

	Vector vecShootOrigin, vecShootDir;
	GetShootOriginAndDirection(vecShootOrigin, vecShootDir);

    int shots = 0;

	// Assume still firing if gpGlobals.curtime-nextprimaryattack falss within this range
	// In the other case reset nextprimaryattack, so we only fire one shot
	if( (gpGlobals->curtime - m_flNextPrimaryAttack) > m_fFireTimeOut )
		m_flNextPrimaryAttack = gpGlobals->curtime;

	//WeaponSound(SINGLE, m_flNextPrimaryAttack);
	while( m_flNextPrimaryAttack <= gpGlobals->curtime )
	{
#ifdef CLIENT_DLL
		// MUST call sound before removing a round from the clip of a CMachineGun
		WeaponSound(SINGLE, m_flNextPrimaryAttack);
#endif // CLIENT_DLL
		m_flNextPrimaryAttack = m_flNextPrimaryAttack + m_fFireRate;
		shots += 1;
		if( !m_fFireRate )
			break;
	}
    
	// Fill in bullets info
	FireBulletsInfo_t info;
	info.m_vecSrc = vecShootOrigin;
	info.m_vecDirShooting = vecShootDir;
	info.m_iShots = shots;
	info.m_flDistance = m_fMaxBulletRange;
	info.m_iAmmoType = GetPrimaryAmmoType();
	info.m_iTracerFreq = 2;
	info.m_vecSpread = m_vBulletSpread;
	info.m_flDamage = m_fOverrideAmmoDamage;

	pOwner->FireBullets( info );

#ifndef CLIENT_DLL
	if( m_bEnableBurst )
	{
		m_nBurstShotsRemaining -= shots;
		// Dispatch burst finished event if we have no shots left
		// It's up to the AI to rest
		if( m_nBurstShotsRemaining <= 0 )
		{
			pOwner->DispatchBurstFinished();
		}
	}
#endif // CLIENT_DLL

	// Add our view kick in
	AddViewKick();
}