‪Black Ops 3 Source Code Explorer  0.1
‪An script explorer for Black Ops 3 by ZeRoY
weapons_shared.gsc
Go to the documentation of this file.
1 #using scripts\codescripts\struct;
2 
3 #using scripts\shared\gameobjects_shared;
4 #using scripts\shared\util_shared;
5 #using scripts\shared\weapons\_weapons;
6 
7 #insert scripts\shared\shared.gsh;
8 #insert scripts\shared\abilities\_ability_util.gsh;
9 
10 #namespace weapons;
11 
12 // weapon stowing logic ===================================================================
13 
14 // weapon class boolean helpers
15 function ‪is_primary_weapon( weapon )
16 {
17  root_weapon = weapon.rootWeapon;
18  return root_weapon != level.weaponNone && isdefined( level.primary_weapon_array[root_weapon] );
19 }
20 function ‪is_side_arm( weapon )
21 {
22  root_weapon = weapon.rootWeapon;
23  return root_weapon != level.weaponNone && isdefined( level.side_arm_array[root_weapon] );
24 }
25 function ‪is_inventory( weapon )
26 {
27  root_weapon = weapon.rootWeapon;
28  return root_weapon != level.weaponNone && isdefined( level.inventory_array[root_weapon] );
29 }
30 function ‪is_grenade( weapon )
31 {
32  root_weapon = weapon.rootWeapon;
33  return root_weapon != level.weaponNone && isdefined( level.grenade_array[root_weapon] );
34 }
35 
37 {
41 }
42 
44 {
45  if ( isdefined( self.carryObject ) && isdefined(self.carryObject ‪gameobjects::get_visible_carrier_model()) )
46  {
47  if( isdefined( self.tag_stowed_back ) )
48  {
49  self detach( self.tag_stowed_back, "tag_stowed_back" );
50  self.tag_stowed_back = undefined;
51  }
52  }
53 }
54 
56 {
57  if( isdefined( self.tag_stowed_back ) )
58  {
59  clear_weapon = true;
60 
61  if ( isdefined( self.carryObject ))
62  {
63  carrierModel = self.carryObject ‪gameobjects::get_visible_carrier_model();
64 
65  if ( isdefined( carrierModel ) && carrierModel == self.tag_stowed_back )
66  {
67  self detach( self.tag_stowed_back, "tag_stowed_back" );
68  clear_weapon = false;
69  }
70  }
71 
72  if ( clear_weapon )
73  {
74  self ClearStowedWeapon();
75  }
76 
77  self.tag_stowed_back = undefined;
78  }
79  else
80  {
81  self ClearStowedWeapon();
82  }
83 
84  if( isdefined( self.tag_stowed_hip ) )
85  {
86  detach_model = self.tag_stowed_hip.worldModel;
87  self detach( detach_model, "tag_stowed_hip_rear" );
88  self.tag_stowed_hip = undefined;
89  }
90 }
91 
92 function ‪stow_on_back(current)
93 {
94  currentWeapon = self getCurrentWeapon();
95  currentAltWeapon = currentWeapon.altWeapon;
96 
97  self.tag_stowed_back = undefined;
98  weaponOptions = 0;
99  index_weapon = level.weaponNone;
100 
101  // carry objects take priority
102  if ( isdefined( self.carryObject ) && isdefined(self.carryObject ‪gameobjects::get_visible_carrier_model()) )
103  {
104  self.tag_stowed_back = self.carryObject ‪gameobjects::get_visible_carrier_model();
105  self attach( self.tag_stowed_back, "tag_stowed_back", true );
106  return;
107  }
108  else if ( currentWeapon != level.weaponNone )
109  {
110  for ( idx = 0; idx < self.weapon_array_primary.size; idx++ )
111  {
112 
113  temp_index_weapon = self.weapon_array_primary[idx];
114  assert( isdefined( temp_index_weapon ), "Primary weapon list corrupted." );
115 
116  if ( temp_index_weapon == currentWeapon )
117  continue;
118 
119  if ( temp_index_weapon == currentAltWeapon )
120  continue;
121 
122  if ( temp_index_weapon.nonStowedWeapon )
123  continue;
124 
125  index_weapon = temp_index_weapon;
126  }
127  }
128 
129  self SetStowedWeapon( index_weapon );
130 }
131 
132 function ‪stow_on_hip()
133 {
134  currentWeapon = self getCurrentWeapon();
135 
136  self.tag_stowed_hip = undefined;
137 
138  for ( idx = 0; idx < self.weapon_array_inventory.size; idx++ )
139  {
140  if ( self.weapon_array_inventory[idx] == currentWeapon )
141  continue;
142 
143  if ( !self GetWeaponAmmoStock( self.weapon_array_inventory[idx] ) )
144  continue;
145 
146  self.tag_stowed_hip = self.weapon_array_inventory[idx];
147  }
148 
149  if ( !isdefined( self.tag_stowed_hip ) )
150  return;
151 
152  self attach( self.tag_stowed_hip.worldmodel, "tag_stowed_hip_rear", true );
153 }
154 
155 function ‪weaponDamageTracePassed(from, to, startRadius, ‪ignore)
156 {
157  ‪trace = ‪weaponDamageTrace(from, to, startRadius, ‪ignore);
158  return (‪trace["fraction"] == 1);
159 }
160 
161 function ‪weaponDamageTrace(from, to, startRadius, ‪ignore)
162 {
163  midpos = undefined;
164 
165  diff = to - from;
166  if ( lengthsquared( diff ) < startRadius*startRadius )
167  midpos = to;
168  dir = vectornormalize( diff );
169  midpos = from + (dir[0]*startRadius, dir[1]*startRadius, dir[2]*startRadius);
170 
171  ‪trace = bullettrace(midpos, to, false, ‪ignore);
172 
173  if ( GetDvarint( "scr_damage_debug") != 0 )
174  {
175  if (‪trace["fraction"] == 1)
176  {
177  thread ‪weapons::debugline(midpos, to, (1,1,1));
178  }
179  else
180  {
181  thread ‪weapons::debugline(midpos, ‪trace["position"], (1,.9,.8));
182  thread ‪weapons::debugline(‪trace["position"], to, (1,.4,.3));
183  }
184  }
185 
186  return ‪trace;
187 }
188 
189 function ‪has_lmg()
190 {
191  weapon = self GetCurrentWeapon();
192  return ( weapon.weapClass == "mg" );
193 }
194 
195 function ‪has_launcher()
196 {
197  weapon = self GetCurrentWeapon();
198  return weapon.isRocketLauncher;
199 }
200 
202 {
203  weapon = self GetCurrentWeapon();
204  return ( weapon.gadget_type == ‪GADGET_TYPE_HERO_WEAPON );
205 }
206 
207 function ‪has_lockon( target )
208 {
209  player = self;
210  clientNum = player getEntityNumber();
211  return isdefined( target.locked_on ) && ( target.locked_on & ( 1 << clientNum ) );
212 }
‪is_side_arm
‪function is_side_arm(weapon)
Definition: weapons_shared.gsc:20
‪has_lockon
‪function has_lockon(target)
Definition: weapons_shared.gsc:207
‪GADGET_TYPE_HERO_WEAPON
‪#define GADGET_TYPE_HERO_WEAPON
Definition: _ability_util.gsh:18
‪ignore
‪function ignore(str_system)
Definition: system_shared.csc:165
‪has_launcher
‪function has_launcher()
Definition: weapons_shared.gsc:195
‪detach_carry_object_model
‪function detach_carry_object_model()
Definition: weapons_shared.gsc:43
‪stow_on_back
‪function stow_on_back(current)
Definition: weapons_shared.gsc:92
‪trace
‪function trace(from, to, target)
Definition: grapple.gsc:369
‪get_visible_carrier_model
‪function get_visible_carrier_model()
Definition: gameobjects_shared.gsc:3867
‪debugline
‪function debugline(a, b, color)
Definition: _weapons.gsc:1247
‪detach_all_weapons
‪function detach_all_weapons()
Definition: weapons_shared.gsc:55
‪weaponDamageTrace
‪function weaponDamageTrace(from, to, startRadius, ignore)
Definition: weapons_shared.gsc:161
‪force_stowed_weapon_update
‪function force_stowed_weapon_update()
Definition: weapons_shared.gsc:36
‪is_primary_weapon
‪function is_primary_weapon(weapon)
Definition: weapons_shared.gsc:15
‪is_inventory
‪function is_inventory(weapon)
Definition: weapons_shared.gsc:25
‪stow_on_hip
‪function stow_on_hip()
Definition: weapons_shared.gsc:132
‪is_grenade
‪function is_grenade(weapon)
Definition: weapons_shared.gsc:30
‪has_hero_weapon
‪function has_hero_weapon()
Definition: weapons_shared.gsc:201
‪has_lmg
‪function has_lmg()
Definition: weapons_shared.gsc:189
‪weaponDamageTracePassed
‪function weaponDamageTracePassed(from, to, startRadius, ignore)
Definition: weapons_shared.gsc:155