1+ #include " StdAfx.h"
2+ #include < utility>
3+
4+ #include " WeaponGrenadeLauncher.h"
5+ #include " ../xrPhysics/MathUtils.h"
6+ #include " Actor.h"
7+ #include " Level.h"
8+ #include " Entity.h"
9+ #include " Inventory.h"
10+ #include " InventoryOwner.h"
11+ #include " Weapon.h"
12+ #include " WeaponMagazined.h"
13+ #include " RocketLauncher.h"
14+ #include " ExplosiveRocket.h"
15+ #include " xrDebug.h"
16+
17+ BOOL g_launcher_dynamic_range = FALSE ;
18+ BOOL g_launcher_dynamic_range_zoom = TRUE ;
19+ BOOL g_launcher_dynamic_range_mode = FALSE ;
20+ float g_launcher_dynamic_range_max = 300 .0f ;
21+
22+ BOOL CWeaponGrenadeLauncher::use_dynamic_range (CWeapon* wpn)
23+ {
24+ if (wpn->IsZoomed ())
25+ {
26+ return g_launcher_dynamic_range_zoom;
27+ }
28+
29+ return g_launcher_dynamic_range;
30+ }
31+
32+ collide::rq_target CWeaponGrenadeLauncher::get_rq_target ()
33+ {
34+ if (g_launcher_dynamic_range_mode)
35+ return collide::rqtBoth;
36+
37+ return collide::rqtStatic;
38+ }
39+
40+ void CWeaponGrenadeLauncher::LaunchGrenade (CWeapon* wpn)
41+ {
42+ CWeaponMagazined* wm = smart_cast<CWeaponMagazined*>(wpn);
43+ VERIFY (wm);
44+
45+ CRocketLauncher* rl = smart_cast<CRocketLauncher*>(wpn);
46+ VERIFY (rl);
47+
48+ #ifdef CROCKETLAUNCHER_CHANGE
49+ LPCSTR ammo_name = wm->m_ammoTypes [wm->m_ammoType ].c_str ();
50+ float launch_speed = READ_IF_EXISTS (pSettings, r_float, ammo_name, " ammo_grenade_vel" , rl->m_fLaunchSpeed );
51+ #endif
52+ Fvector p1, d;
53+ p1.set (wpn->get_LastFP2 ());
54+ d.set (wpn->get_LastFD ());
55+ CEntity* E = smart_cast<CEntity*>(wpn->H_Parent ());
56+
57+ if (E)
58+ {
59+ CInventoryOwner* io = smart_cast<CInventoryOwner*>(wpn->H_Parent ());
60+ if (NULL == io->inventory ().ActiveItem ())
61+ {
62+ Log (" current_state" , wpn->GetState ());
63+ Log (" next_state" , wpn->GetNextState ());
64+ Log (" item_sect" , wpn->cNameSect ().c_str ());
65+ Log (" H_Parent" , wpn->H_Parent ()->cNameSect ().c_str ());
66+ }
67+ E->g_fireParams (wpn, p1, d);
68+ }
69+ if (IsGameTypeSingle ())
70+ p1.set (wpn->get_LastFP2 ());
71+
72+ Fmatrix launch_matrix;
73+ launch_matrix.identity ();
74+ launch_matrix.k .set (d);
75+ Fvector::generate_orthonormal_basis (launch_matrix.k ,
76+ launch_matrix.j ,
77+ launch_matrix.i );
78+
79+ launch_matrix.c .set (p1);
80+
81+ if (IsGameTypeSingle () && use_dynamic_range (wpn) && smart_cast<CActor*>(wpn->H_Parent ()))
82+ {
83+ wpn->H_Parent ()->setEnabled (FALSE );
84+ wpn->setEnabled (FALSE );
85+
86+ collide::rq_result RQ;
87+ BOOL HasPick = Level ().ObjectSpace .RayPick (p1, d, g_launcher_dynamic_range_max, get_rq_target (), RQ, wpn);
88+
89+ wpn->setEnabled (TRUE );
90+ wpn->H_Parent ()->setEnabled (TRUE );
91+
92+ if (HasPick)
93+ {
94+ Fvector Transference;
95+ Transference.mul (d, RQ.range );
96+ Fvector res[2 ];
97+ #ifdef DEBUG
98+ // . DBG_OpenCashedDraw();
99+ // . DBG_DrawLine(p1,Fvector().add(p1,d),D3DCOLOR_XRGB(255,0,0));
100+ #endif
101+ #ifdef CROCKETLAUNCHER_CHANGE
102+ u8 canfire0 = TransferenceAndThrowVelToThrowDir (Transference, launch_speed, wpn->EffectiveGravity (), res);
103+ #else
104+ u8 canfire0 = TransferenceAndThrowVelToThrowDir (Transference,
105+ rl->m_fLaunchSpeed ,
106+ rl->EffectiveGravity (),
107+ res);
108+ #endif
109+ #ifdef DEBUG
110+ // . if(canfire0>0)DBG_DrawLine(p1,Fvector().add(p1,res[0]),D3DCOLOR_XRGB(0,255,0));
111+ // . if(canfire0>1)DBG_DrawLine(p1,Fvector().add(p1,res[1]),D3DCOLOR_XRGB(0,0,255));
112+ // . DBG_ClosedCashedDraw(30000);
113+ #endif
114+
115+ if (canfire0 != 0 )
116+ {
117+ d = res[0 ];
118+ };
119+ }
120+ };
121+
122+ d.normalize ();
123+ #ifdef CROCKETLAUNCHER_CHANGE
124+ d.mul (launch_speed);
125+ #else
126+ d.mul (rl->m_fLaunchSpeed );
127+ #endif
128+ VERIFY2 (_valid (launch_matrix), " CWeaponMagazinedWGrenade::SwitchState. Invalid launch_matrix!" );
129+ rl->LaunchRocket (launch_matrix, d, zero_vel);
130+
131+ CExplosiveRocket* pGrenade = smart_cast<CExplosiveRocket*>(rl->getCurrentRocket ());
132+ VERIFY (pGrenade);
133+ pGrenade->SetInitiator (wpn->H_Parent ()->ID ());
134+
135+ if (wpn->Local () && OnServer ())
136+ {
137+ VERIFY (wm->m_magazine .size ());
138+ wm->m_magazine .pop_back ();
139+ --wm->iAmmoElapsed ;
140+ VERIFY ((u32 ) wpn->iAmmoElapsed == wm->m_magazine .size ());
141+
142+ NET_Packet P;
143+ wpn->u_EventGen (P, GE_LAUNCH_ROCKET, wpn->ID ());
144+ P.w_u16 (rl->getCurrentRocket ()->ID ());
145+ wpn->u_EventSend (P);
146+ };
147+ }
0 commit comments