//------------------------------------------------------------------------ int CScriptBind_Weapon::AutoShoot(IFunctionHandler *pH, int shots, bool autoReload) { struct AutoShootHelper : public IWeaponEventListener { AutoShootHelper(int n, bool autoreload): m_nshots(n), m_reload(autoreload) {}; virtual ~AutoShootHelper() {}; int m_nshots; bool m_reload; virtual void OnShoot(IWeapon *pWeapon, EntityId shooterId, EntityId ammoId, IEntityClass* pAmmoType, const Vec3 &pos, const Vec3 &dir, const Vec3 &vel) {}; virtual void OnStartFire(IWeapon *pWeapon, EntityId shooterId) {}; virtual void OnStopFire(IWeapon *pWeapon, EntityId shooterId) {}; virtual void OnStartReload(IWeapon *pWeapon, EntityId shooterId, IEntityClass* pAmmoType) {}; virtual void OnEndReload(IWeapon *pWeapon, EntityId shooterId, IEntityClass* pAmmoType) {}; virtual void OnOutOfAmmo(IWeapon *pWeapon, IEntityClass* pAmmoType) { if (m_reload) pWeapon->Reload(false); else { pWeapon->StopFire(); pWeapon->RemoveEventListener(this); } }; virtual void OnReadyToFire(IWeapon *pWeapon) { if (!(--m_nshots)) { pWeapon->StopFire(); pWeapon->RemoveEventListener(this); } else { pWeapon->StartFire(); pWeapon->StopFire(); } }; virtual void OnPickedUp(IWeapon *pWeapon, EntityId actorId, bool destroyed){} virtual void OnDropped(IWeapon *pWeapon, EntityId actorId){} virtual void OnMelee(IWeapon* pWeapon, EntityId shooterId){} virtual void OnStartTargetting(IWeapon *pWeapon) {} virtual void OnStopTargetting(IWeapon *pWeapon) {} virtual void OnSelected(IWeapon *pWeapon, bool select) {} }; CWeapon *pWeapon = GetWeapon(pH); if (!pWeapon) return pH->EndFunction(); pWeapon->AddEventListener(new AutoShootHelper(shots, autoReload), __FUNCTION__); // FIXME: possible small memory leak here. pWeapon->StartFire(); pWeapon->StopFire(); return pH->EndFunction(); }
//-------------------------------------------------------------------- bool CWeapon::OnActionAttack(EntityId actorId, const ActionId& actionId, int activationMode, float value) { if(!m_modifying) { COffHand * offHandWeapon = NULL; bool isOffHandSelected = false; GetOffHandInfo(this,isOffHandSelected,&offHandWeapon); if(IsTwoHand()) { if(offHandWeapon && (offHandWeapon->GetOffHandState()&(eOHS_HOLDING_GRENADE|eOHS_SWITCHING_GRENADE|eOHS_PICKING_ITEM))) return false; } if (activationMode == eAAM_OnPress) { if(PreActionAttack(true)) return true; bool isDualWield = false; CWeapon *dualWield = NULL; GetDualWieldInfo(this,isDualWield,&dualWield); // EXPANSION: Dino has rewritten dual wield control! /*if (isDualWield) { m_fire_alternation = !m_fire_alternation; m_requestedFire = true; if (!m_fire_alternation && dualWield->OutOfAmmo(false) && dualWield->CanReload()) { dualWield->Reload(); return true; } else if(m_fire_alternation && OutOfAmmo(false) && CanReload()) { Reload(); return true; } if (m_fire_alternation || (!dualWield->CanFire() || !dualWield->IsSelected())) { if(!IsWeaponRaised() && CanFire()) StartFire(); else if(!dualWield->IsWeaponRaised() && dualWield->IsSelected()) dualWield->StartFire(); } else if (dualWield->CanFire()) { if(!dualWield->IsWeaponRaised() && dualWield->CanFire()) dualWield->StartFire(); else if(!IsWeaponRaised()) StartFire(); } }*/ // /EXPANSION if (isDualWield) { if (offHandWeapon && !(offHandWeapon->GetOffHandState() & (eOHS_INIT_STATE))) return false; m_fire_alternation = false; if (!dualWield->IsWeaponRaised())// && dualWield->CanFire()) { dualWield->StartFire(); } /* else if(dualWield->OutOfAmmo(false) && !dualWield->IsReloading()) { dualWield->Reload(); }*/ dualWield->m_requestedFire = true; } else { if(!m_weaponRaised) { StartFire(); } m_requestedFire = true; } } else if (activationMode == eAAM_OnRelease) { PreActionAttack(false); // EXP 1: Don't stop both slave and master simultaneously!!! //Stop slave if(IsDualWieldMaster()) { //FireSlave(actorId,false); CWeapon *dualWield = NULL; IItem *slave = GetDualWieldSlave(); if (slave && slave->GetIWeapon()) dualWield = static_cast<CWeapon *>(slave); if(dualWield) { dualWield->StopFire(); dualWield->m_requestedFire=false; } } else if (m_fm) { m_fm->StopFire(); m_requestedFire = false; } // StopFire(); // /EXP 1 } } return true; }
//-------------------------------------------------------------------- bool CWeapon::OnActionAttack(EntityId actorId, const ActionId& actionId, int activationMode, float value) { if(!m_modifying) { if(IsTwoHand()) { COffHand * offHandWeapon = NULL; bool isOffHandSelected = false; GetOffHandInfo(this,isOffHandSelected,&offHandWeapon); if(offHandWeapon && (offHandWeapon->GetOffHandState()&(eOHS_HOLDING_GRENADE|eOHS_SWITCHING_GRENADE|eOHS_PICKING_ITEM))) return false; } if (activationMode == eAAM_OnPress) { if(PreActionAttack(true)) return true; bool isDualWield = false; CWeapon *dualWield = NULL; GetDualWieldInfo(this,isDualWield,&dualWield); if (isDualWield) { m_fire_alternation = !m_fire_alternation; m_requestedFire = true; if (m_fire_alternation || !dualWield->CanFire()) { if(!IsWeaponRaised() && CanFire()) StartFire(); else if(!dualWield->IsWeaponRaised()) dualWield->StartFire(); } else if (dualWield->CanFire()) { if(!dualWield->IsWeaponRaised() && dualWield->CanFire()) dualWield->StartFire(); else if(!IsWeaponRaised()) StartFire(); } else if(OutOfAmmo(false)) { Reload(); dualWield->Reload(); } } else { if(!m_weaponRaised) StartFire(); m_requestedFire = true; } } else if (activationMode == eAAM_OnRelease) { PreActionAttack(false); StopFire(); m_requestedFire = false; } } return true; }