예제 #1
0
void CWeaponKnife::Fire2Start () 
{
	inherited::Fire2Start();
	SwitchState(eFire2);

	// Real Wolf: Прерывание спринта при ударе. 17.07.2014.
#if defined(KNIFE_SPRINT_FIX)
	if (ParentIsActor() )
		g_actor->set_state_wishful(g_actor->get_state_wishful() & (~mcSprint) );
#endif
}
예제 #2
0
bool CWeaponMagazined::Action(s32 cmd, u32 flags)
{
	if (inherited::Action(cmd, flags)) return true;

	//если оружие чем-то занято, то ничего не делать
	if (IsPending()) return false;

	switch (cmd)
	{
	case kWPN_RELOAD:
	{
#if defined(LOCK_RELOAD_IN_SPRINT)
	if (!ParentIsActor() || !(g_actor->get_state() & mcSprint) )
#endif
		if (flags&CMD_START)
			if (iAmmoElapsed < iMagazineSize || IsMisfire())
				Reload();
	}
		return true;
	case kWPN_FIREMODE_PREV:
	{
		if (flags&CMD_START)
		{
			OnPrevFireMode();
			return true;
		};
	}break;
	case kWPN_FIREMODE_NEXT:
	{
		if (flags&CMD_START)
		{
			OnNextFireMode();
			return true;
		};
	}break;
	}
	return false;
}
예제 #3
0
void CWeaponMagazined::ReloadMagazine()
{
	m_dwAmmoCurrentCalcFrame = 0;

	//устранить осечку при перезарядке
	if (IsMisfire())	bMisfire = false;

	//переменная блокирует использование
	//только разных типов патронов
	//	static bool l_lockType = false;
	if (!m_bLockType) {
		m_ammoName = NULL;
		m_pAmmo = NULL;
	}

	if (!m_pCurrentInventory) return;

	if (m_set_next_ammoType_on_reload != u32(-1)){
		m_ammoType = m_set_next_ammoType_on_reload;
		m_set_next_ammoType_on_reload = u32(-1);
	}

	if (!unlimited_ammo())
	{
		//попытаться найти в инвентаре патроны текущего типа
		#if defined(AMMO_FROM_BELT)
		if (ParentIsActor())
			m_pAmmo = smart_cast<CWeaponAmmo*>(m_pCurrentInventory->GetAmmoOnBelt(*m_ammoTypes[m_ammoType]));
		else
			m_pAmmo = smart_cast<CWeaponAmmo*>(m_pCurrentInventory->GetAny(*m_ammoTypes[m_ammoType]));
		#else
		m_pAmmo = smart_cast<CWeaponAmmo*>(m_pCurrentInventory->GetAny(*m_ammoTypes[m_ammoType]));
		#endif

		if (!m_pAmmo && !m_bLockType)
		{
			for (u32 i = 0; i < m_ammoTypes.size(); ++i)
			{
				//проверить патроны всех подходящих типов
		#if defined(AMMO_FROM_BELT)
		if (ParentIsActor())
			m_pAmmo = smart_cast<CWeaponAmmo*>(m_pCurrentInventory->GetAmmoOnBelt(*m_ammoTypes[i]));
		else
			m_pAmmo = smart_cast<CWeaponAmmo*>(m_pCurrentInventory->GetAny(*m_ammoTypes[i]));
		#else
		m_pAmmo = smart_cast<CWeaponAmmo*>(m_pCurrentInventory->GetAny(*m_ammoTypes[i]));
		#endif
				if (m_pAmmo)
				{
					m_ammoType = i;
					break;
				}
			}
		}
	}
	else
		m_ammoType = m_ammoType;

	//нет патронов для перезарядки
	if (!m_pAmmo && !unlimited_ammo()) return;

	//разрядить магазин, если загружаем патронами другого типа
	if (!m_bLockType && !m_magazine.empty() &&
		(!m_pAmmo || xr_strcmp(m_pAmmo->cNameSect(),
		*m_magazine.back().m_ammoSect)))
		UnloadMagazine();

	VERIFY((u32)iAmmoElapsed == m_magazine.size());

	if (m_DefaultCartridge.m_LocalAmmoType != m_ammoType)
		m_DefaultCartridge.Load(*m_ammoTypes[m_ammoType], u8(m_ammoType));
	CCartridge l_cartridge = m_DefaultCartridge;
	while (iAmmoElapsed < iMagazineSize)
	{
		if (!unlimited_ammo())
		{
			if (!m_pAmmo->Get(l_cartridge)) break;
		}
		++iAmmoElapsed;
		l_cartridge.m_LocalAmmoType = u8(m_ammoType);
		m_magazine.push_back(l_cartridge);
	}
	m_ammoName = (m_pAmmo) ? m_pAmmo->m_nameShort : NULL;

	VERIFY((u32)iAmmoElapsed == m_magazine.size());

	//выкинуть коробку патронов, если она пустая
	if (m_pAmmo && !m_pAmmo->m_boxCurr && OnServer())
		m_pAmmo->SetDropManual(TRUE);

	if (iMagazineSize > iAmmoElapsed)
	{
		m_bLockType = true;
		ReloadMagazine();
		m_bLockType = false;
	}

	VERIFY((u32)iAmmoElapsed == m_magazine.size());
}
예제 #4
0
void CShootingObject::FireBullet(const Fvector& pos, 
								 const Fvector& shot_dir, 
								 float fire_disp,
								 const CCartridge& cartridge,
								 u16 parent_id,
								 u16 weapon_id,
								 bool send_hit)
{
	Fvector dir;
	random_dir(dir,shot_dir,fire_disp);

	m_vCurrentShootDir = dir;
	m_vCurrentShootPos = pos;
	m_iCurrentParentID = parent_id;
	
	bool aim_bullet;
	if (m_bUseAimBullet)
	{
		if (ParentMayHaveAimBullet())
		{
			if (m_fPredBulletTime==0.0)
			{
				aim_bullet=true;
			}
			else
			{
				if ((Device.fTimeGlobal-m_fPredBulletTime)>=m_fTimeToAim)
				{
					aim_bullet=true;
				}
				else
				{
					aim_bullet=false;
				}
			}
		}
		else
		{
			aim_bullet=false;
		}
	}
	else
	{
		aim_bullet=false;
	}
	m_fPredBulletTime = Device.fTimeGlobal;

	float l_fHitPower = 0.0f;
	float l_fHitPowerCritical = 0.0f;
	if (ParentIsActor())//если из оружия стреляет актёр(игрок)
	{
		if (GameID() == eGameIDSingle)
		{
			l_fHitPower			= fvHitPower[g_SingleGameDifficulty];
			l_fHitPowerCritical = fvHitPowerCritical[g_SingleGameDifficulty];
		}
		else
		{
			l_fHitPower			= fvHitPower[egdMaster];
			l_fHitPowerCritical = fvHitPowerCritical[egdMaster];
		}
	}
	else
	{
		l_fHitPower			= fvHitPower[egdMaster];
		l_fHitPowerCritical = fvHitPowerCritical[egdMaster];
	}

	Level().BulletManager().AddBullet( pos, dir,
		m_fStartBulletSpeed * cur_silencer_koef.bullet_speed,
		l_fHitPower * cur_silencer_koef.hit_power,
		l_fHitPowerCritical,
		fHitImpulse * cur_silencer_koef.hit_impulse,
		parent_id, weapon_id,
		ALife::eHitTypeFireWound, fireDistance, cartridge, send_hit, aim_bullet);
}
예제 #5
0
파일: WeaponKnife.cpp 프로젝트: 2asoft/xray
void CWeaponKnife::OnStateSwitch	(u32 S)
{
	inherited::OnStateSwitch(S);
	switch (S)
	{
	case eIdle:
		switch2_Idle	();
		break;
	case eShowing:
		switch2_Showing	();
		break;
	case eHiding:
		switch2_Hiding	();
		break;
	case eHidden:
		switch2_Hidden	();
		break;
	case eFire:
		{
			//-------------------------------------------
			m_eHitType		= m_eHitType_1;
			//fHitPower		= fHitPower_1;
			if (ParentIsActor())
			{
				if (GameID() == eGameIDSingle)
				{
					fCurrentHit			= fvHitPower_1[g_SingleGameDifficulty];
					fCurrentHitCritical	= fvHitPowerCritical_1[g_SingleGameDifficulty];
				}
				else
				{
					fCurrentHit			= fvHitPower_1[egdMaster];
					fCurrentHitCritical	= fvHitPowerCritical_1[egdMaster];
				}
			}
			else
			{
				fCurrentHit			= fvHitPower_1[egdMaster];
				fCurrentHitCritical	= fvHitPowerCritical_1[egdMaster];
			}
			fHitImpulse_cur	= fHitImpulse_1;
			//-------------------------------------------
			switch2_Attacking	(S);
		}break;
	case eFire2:
		{
			//-------------------------------------------
			m_eHitType		= m_eHitType_2;
			//fHitPower		= fHitPower_2;
			if (ParentIsActor())
			{
				if (GameID() == eGameIDSingle)
				{
					fCurrentHit			= fvHitPower_2[g_SingleGameDifficulty];
					fCurrentHitCritical	= fvHitPowerCritical_2[g_SingleGameDifficulty];
				}
				else
				{
					fCurrentHit			= fvHitPower_2[egdMaster];
					fCurrentHitCritical	= fvHitPowerCritical_2[egdMaster];
				}
			}
			else
			{
				fCurrentHit			= fvHitPower_2[egdMaster];
				fCurrentHitCritical	= fvHitPowerCritical_2[egdMaster];
			}
			fHitImpulse_cur	= fHitImpulse_2;
			//-------------------------------------------
			switch2_Attacking	(S);
		}break;
	}
}
예제 #6
0
void CShootingObject::FireBullet(const Fvector& pos, 
								 const Fvector& shot_dir, 
								 float fire_disp,
								 const CCartridge& cartridge,
								 u16 parent_id,
								 u16 weapon_id,
								 bool send_hit)
{
	Fvector dir;
	random_dir(dir,shot_dir,fire_disp);

	if (constDeviation.pitch != 0 || constDeviation.yaw != 0) // WARN: при больших значениях девиации стрелок может отсрелить себе голову!
	{
		float dir_yaw, dir_pitch;
		dir.getHP(dir_yaw, dir_pitch);
		dir_pitch += constDeviation.pitch;		
		dir_yaw += constDeviation.yaw;
		dir.setHP(dir_yaw, dir_pitch);
	}

	m_vCurrentShootDir = dir;
	m_vCurrentShootPos = pos;
	m_iCurrentParentID = parent_id;
	
	bool aim_bullet;
	if (m_bUseAimBullet)
	{
		if (ParentMayHaveAimBullet())
		{
			if (m_fPredBulletTime==0.0)
			{
				aim_bullet=true;
			}
			else
			{
				if ((Device.fTimeGlobal-m_fPredBulletTime)>=m_fTimeToAim)
				{
					aim_bullet=true;
				}
				else
				{
					aim_bullet=false;
				}
			}
		}
		else
		{
			aim_bullet=false;
		}
	}
	else
	{
		aim_bullet=false;
	}
	m_fPredBulletTime = Device.fTimeGlobal;

	float l_fHitPower;
	if (ParentIsActor())//если из оружия стреляет актёр(игрок)
	{
		if (GameID() == GAME_SINGLE)
		{
			l_fHitPower=fvHitPower[g_SingleGameDifficulty];
		}
		else
		{
			l_fHitPower=fvHitPower[egdMaster];
		}
	}
	else
	{
		l_fHitPower=fvHitPower[egdMaster];
	}

	Level().BulletManager().AddBullet(	pos, dir, m_fStartBulletSpeed, l_fHitPower, 
										fHitImpulse, parent_id, weapon_id, 
										m_eHitType, fireDistance, cartridge, send_hit, aim_bullet);
}