‪Black Ops 3 Source Code Explorer  0.1
‪An script explorer for Black Ops 3 by ZeRoY
destructible_cover_shared.gsc
Go to the documentation of this file.
1 #using scripts\codescripts\struct;
2 
3 #using scripts\shared\system_shared;
4 #using scripts\shared\array_shared;
5 #using scripts\shared\util_shared;
6 
7 #insert scripts\shared\shared.gsh;
8 
9 #precache( "fx", "destruct/fx_dest_k_rail" );
10 #precache( "fx", "destruct/fx_dest_k_rail_crumble01" );
11 #precache( "fx", "destruct/fx_dest_k_rail_crumble02" );
12 #precache( "fx", "destruct/fx_dest_k_rail_crumble03" );
13 
14 // ============================================================================
15 // Utility
16 // ============================================================================
17 
18 ‪REGISTER_SYSTEM( "destructible_cover", &‪__init__, undefined )
19 
20 function ‪__init__()
21 {
22  level thread ‪precache_destructible_fx();
23 
24  cover_array = GetEntArray("dest_cover","targetname");
25  level thread array::spread_all(cover_array, &‪destructible_cover_think);
26 
27  // testing purposes only to proof out cover options before making a model.
28  cover_array_geo = GetEntArray("dest_cover_geo","targetname");
29  level thread array::spread_all( cover_array_geo, &‪destructible_cover_geo_think );
30 }
31 
32 // ============================================================================
33 //krail_upper_01_jnt
34 //krail_mid_01_jnt
35 //krail_btm_01_jnt
36 
38 {
39  //--- Default: Can be overwritted below -----------------
40  self.break_fx = level._effect[ "k_rail_destruct" ];
41  self.chunk_fx = level._effect[ "k_rail_destruct" ];
42  self.break_sound = "dst_cover_concrete";
43  self.chunk_sound = "dst_cover_concrete";
44 
45  //disconnect paths around krails.
46  self DisconnectPaths();
47 
48  if(isDefined(self.script_noteworthy) && self.script_noteworthy == "dest_krail")
49  {
50 
51  //"krail_base_jnt" main body
52 
53  self.PartTags_upper = ‪array("krail_upper_01_jnt", "krail_upper_02_jnt", "krail_upper_03_jnt", "krail_upper_04_jnt", "krail_upper_05_jnt", "krail_upper_06_jnt");
54  self.PartTags_mid = ‪array("krail_mid_01_jnt", "krail_mid_02_jnt", "krail_mid_03_jnt", "krail_mid_04_jnt", "krail_mid_05_jnt", "krail_mid_06_jnt");
55  self.PartTags_btm = ‪array("krail_btm_01_jnt", "krail_btm_02_jnt", "krail_btm_03_jnt", "krail_btm_04_jnt", "krail_btm_05_jnt", "krail_btm_06_jnt");
56 
57  self.PartTags = ‪array("krail_upper_01_jnt", "krail_upper_02_jnt", "krail_upper_03_jnt", "krail_upper_04_jnt", "krail_upper_05_jnt", "krail_upper_06_jnt",
58  "krail_mid_01_jnt", "krail_mid_02_jnt", "krail_mid_03_jnt", "krail_mid_04_jnt", "krail_mid_05_jnt", "krail_mid_06_jnt",
59  "krail_btm_01_jnt", "krail_btm_02_jnt", "krail_btm_03_jnt", "krail_btm_04_jnt", "krail_btm_05_jnt", "krail_btm_06_jnt");
60 
61  self.PartTags_dmg = ‪array("krail_upper_01_jnt", "krail_upper_02_jnt", "krail_upper_03_jnt");
62 
63  self.PartTags_chips = [];
64 
65  self.health_data = [];
66  foreach( tag in self.PartTags)
67  {
68  self.health_data[tag] = 100;
69  self.health_full[tag] = 100;
70  }
71  foreach( tag in self.PartTags_chips)
72  {
73  self.health_data[tag] = 35;
74  self.health_full[tag] = 35;
75  }
76 
77  //--------------------------------------------------
78  self.break_fx = level._effect[ "k_rail_destruct" ];
79  self.chunk_fx = level._effect[ "k_rail_destruct" ];
80  self.break_sound = "dst_cover_concrete";
81  self.chunk_sound = "dst_cover_concrete";
82 
83  if(!IsDefined(self.angles))
84  self.angles = (0, 0, 0);
85 
86  self.coll_model = ‪spawn("script_model", self.origin);
87  self.coll_model.angles = (self.angles);
88  self.coll_model setmodel("fxdest_bc_krail_whole");
89 
90  self thread ‪hide_cracked_parts(self.PartTags_dmg);
91  //self thread hide_cracked_parts(self.PartTags);
92 
93  /*
94  | 1 | 2 | 3 | 4 | 5 | 6 | upper
95  | 1 | 2 | 3 | 4 | 5 | 6 | mid
96  | 1 | 2 | 3 | 4 | 5 | 6 | btm
97  */
98  foreach( tag in self.PartTags)
99  {
100  if( IsSubStr(tag, "krail_upper_"))
101  self.part_links[tag] = [];
102 
103  if(tag == "krail_mid_01_jnt")
104  self.part_links[tag] = ‪array("krail_upper_01_jnt");
105 
106  if(tag == "krail_mid_02_jnt")
107  self.part_links[tag] = ‪array("krail_upper_01_jnt", "krail_upper_02_jnt", "krail_mid_01_jnt");
108 
109  if(tag == "krail_mid_03_jnt")
110  self.part_links[tag] = ‪array("krail_upper_02_jnt", "krail_upper_03_jnt", "krail_upper_04_jnt");
111 
112  if(tag == "krail_mid_04_jnt")
113  self.part_links[tag] = ‪array("krail_upper_03_jnt", "krail_upper_04_jnt", "krail_upper_05_jnt");
114 
115  if(tag == "krail_mid_05_jnt")
116  self.part_links[tag] = ‪array("krail_upper_05_jnt", "krail_upper_06_jnt", "krail_mid_06_jnt");
117 
118  if(tag == "krail_mid_06_jnt")
119  self.part_links[tag] = ‪array("krail_upper_06_jnt");
120 
121 
122  if(tag == "krail_btm_01_jnt")
123  self.part_links[tag] = ‪array("krail_upper_01_jnt", "krail_mid_01_jnt");
124 
125  if(tag == "krail_btm_02_jnt")
126  self.part_links[tag] = ‪array("krail_upper_02_jnt", "krail_mid_02_jnt");
127 
128  if(tag == "krail_btm_03_jnt")
129  self.part_links[tag] = ‪array("krail_upper_03_jnt", "krail_mid_03_jnt");
130 
131  if(tag == "krail_btm_04_jnt")
132  self.part_links[tag] = ‪array("krail_upper_04_jnt", "krail_mid_04_jnt");
133 
134  if(tag == "krail_btm_05_jnt")
135  self.part_links[tag] = ‪array("krail_upper_05_jnt", "krail_mid_05_jnt");
136 
137  if(tag == "krail_btm_06_jnt")
138  self.part_links[tag] = ‪array("krail_upper_06_jnt", "krail_mid_06_jnt");
139  }
140 
141  }
142 
143  self thread ‪dest_model_think();
144 
145 }
146 
147 // ============================================================================
148 function ‪hide_cracked_parts(tag_array)
149 {
150  for ( i = 0; i < tag_array.size; i++ )
151  {
152  self HidePart(tag_array[i] + "_cracks");
153  }
154 }
155 
156 // ============================================================================
157 //script_int: actual piece 1-18 3 rows of 6
159 {
160  self setcandamage(true);
161  destroyed_pieces = [];
162 
163  while( 1 )
164  {
165  self.damaged = undefined;
166 
167  self waittill( "damage", amount, who, direction_vec, point, type, modelName, tagName, partName );
168 
169  self.damaged = true;
170 
171  if(!IsDefined(self.health_data[partName]))
172  continue;
173 
174  // Did we hit a chunk piece directly?
175  if(isSubStr(partName, ( "_chunk" )))
176  {
177  //chunk hit directly, damage only part.
178  dmg = self.health_data[partName] - amount;
179  if(dmg <= 0)
180  {
181  self thread ‪destroy_chunks( partName );
182  }
183  part_hlth = self.health_full[partName];
184  break;
185  }
186  else //hit a larger part.
187  {
188  foreach( str in self.PartTags_chips)
189  {
190  if(isSubStr(str, (partName + "_chunk") && self.health_data[str] > 0))
191  {
192  self.health_data[str] = self.health_data[str] - amount;
193  if(self.health_data[str] <= 0)
194  {
195  self thread ‪destroy_chunks( str );
196  }
197  continue;
198  }
199  }
200 
201  self.health_data[partName] = self.health_data[partName] - amount;
202  part_hlth = self.health_data[partName];
203 
204  }
205 
206 
207  if (part_hlth > 0)
208  {
209  if(part_hlth < (self.health_full[partName] * 0.5) && part_hlth > 0 )
210  {
211  foreach( str in self.PartTags_dmg)
212  {
213  if(str == partName) //cracked overlay exists
214  {
215  self ShowPart( str + "_cracks" );
216  break;
217  }
218  }
219 
220  }
221  continue;
222  }
223 
224  // Check for linked parts to destroy first.
225  if(IsDefined(self.part_links[partName]) && self.part_links[partName].size > 0 )
226  {
227  str = self.part_links[partName];
228  for(i = 0; i < str.size; i ++)
229  {
230  if(self.health_data[str[i]] <= 0)
231  {
232  array::exclude(self.part_links[partName], str[i] );
233  }
234  else
235  {
236  hlth_dmg = self.health_full[str[i]] * (randomfloatrange(0.1, 0.4));
237  //self.health_data[str[i]] = self.health_data[str[i]] - hlth_dmg;
238 
239  self thread ‪pass_on_damage(hlth_dmg, direction_vec, who, str[i], type);
240  }
241  }
242  self.health_data[partName] = self.health_full[partName];
243  }
244  else
245  {
246  self thread ‪destroy_piece(partName);
247  }
248  }
249 }
250 
251 function ‪pass_on_damage(‪damage, direction_vec, who, tag, type)
252 {
253  while(IsDefined(self.damaged))
254  {
255  wait(0.1);
256  }
257 
258  pos = self GetTagOrigin( tag );
259  self ‪util::damage_notify_wrapper( ‪damage, who, direction_vec, pos, type, "", "", tag );
260 }
261 // ============================================================================
262 function ‪destroy_chunks( chunk )
263 {
264  PlayFxOnTag(self.chunk_fx, self, chunk);
265 
266  self playsound( self.chunk_sound );
267 
268  self HidePart( chunk );
269 }
270 
271 // ============================================================================
273 {
274  level._effect[ "k_rail_destruct" ] = "destruct/fx_dest_k_rail";
275  level._effect[ "k_rail_crumble01" ] = "destruct/fx_dest_k_rail_crumble01";
276  level._effect[ "k_rail_crumble02" ] = "destruct/fx_dest_k_rail_crumble02";
277  level._effect[ "k_rail_crumble03" ] = "destruct/fx_dest_k_rail_crumble03";
278 }
279 
280 // ============================================================================
281 function ‪destroy_piece(tag)
282 {
283 
284  PlayFxOnTag(self.break_fx, self, tag);
285 
286  self playsound(self.break_sound);
287 
288  foreach( str in self.PartTags_dmg)
289  {
290  if(str == tag) //cracked overlay exists
291  {
292  self HidePart( str + "_cracks" );
293  break;
294  }
295  }
296  self HidePart(tag);
297  self ‪dest_collision_watcher(tag);
298 }
299 
300 // ============================================================================
302 {
303 
304  if(IsSubStr(tag, "_upper_"))
305  {
306  array::exclude(self.PartTags_upper, tag );
307  }
308  else if(IsSubStr(tag, "_mid_"))
309  {
310  array::exclude(self.PartTags_mid, tag );
311  }
312  else if(IsSubStr(tag, "_btm_"))
313  {
314  array::exclude(self.PartTags_btm, tag );
315  }
316 
317  if(self.PartTags_upper.size <= 0 && self.PartTags_mid.size > 0 )
318  {
319  self.coll_model setmodel("fxdest_bc_krail_med");
320  }
321  else if(self.PartTags_upper.size <= 0 && self.PartTags_mid.size <= 0 )
322  {
323  self.coll_model setmodel("fxdest_bc_krail_low");
324  }
325 }
326 
327 // ============================================================================
328 // Obsolete geo functions: only for testing.
329 // ============================================================================
331 {
332  //--- Default: Can be overwritted below -----------------
333  self.break_fx = level._effect[ "k_rail_destruct" ];
334  self.chunk_fx = level._effect[ "k_rail_destruct" ];
335  self.break_sound = "dst_cover_concrete";
336  self.chunk_sound = "dst_cover_concrete";
337 
338  pieces = GetEntArray(self.target, "targetname");
339 
340  If(!IsDefined( self.script_int ))
341  {
342  self.script_int = 6;
343  }
344 
345  foreach( part in pieces)
346  {
347  if(IsDefined(part.script_float))
348  {
349  part.hlth = part.script_float;
350  }
351  else
352  {
353  part.hlth = 100;
354  }
355 
356 
357  /*
358  | 0 | 1 | 2 | 3 | 4 | 5 |
359  | 6 | 7 | 8 | 9 | 10| 11|
360  | 12| 13| 14| 15| 16| 17|
361  */
362  if( self.script_int == 6 )
363  {
364  if(part.script_int == 0 || part.script_int == 1 || part.script_int == 2 || part.script_int == 3 || part.script_int == 4 || part.script_int == 5)
365  part.links = [];
366 
367  if(part.script_int == 6)
368  part.links = ‪array(pieces thread ‪ents_from_script_int(0));
369 
370  if(part.script_int == 7)
371  part.links = ‪array(pieces thread ‪ents_from_script_int(0), pieces thread ‪ents_from_script_int(1),pieces thread ‪ents_from_script_int(6));
372 
373  if(part.script_int == 8)
374  part.links = ‪array(pieces thread ‪ents_from_script_int(1), pieces thread ‪ents_from_script_int(2),pieces thread ‪ents_from_script_int(3));
375 
376  if(part.script_int == 9)
377  part.links = ‪array(pieces thread ‪ents_from_script_int(2), pieces thread ‪ents_from_script_int(3),pieces thread ‪ents_from_script_int(4));
378 
379  if(part.script_int == 10)
380  part.links = ‪array(pieces thread ‪ents_from_script_int(3), pieces thread ‪ents_from_script_int(4),pieces thread ‪ents_from_script_int(5));
381 
382  if(part.script_int == 11)
383  part.links = ‪array(pieces thread ‪ents_from_script_int(4), pieces thread ‪ents_from_script_int(5));
384 
385  if(part.script_int == 12)
386  part.links = ‪array(pieces thread ‪ents_from_script_int(6), pieces thread ‪ents_from_script_int(0));
387 
388  if(part.script_int == 13)
389  part.links = ‪array(pieces thread ‪ents_from_script_int(7), pieces thread ‪ents_from_script_int(1));
390 
391  if(part.script_int == 14)
392  part.links = ‪array(pieces thread ‪ents_from_script_int(8), pieces thread ‪ents_from_script_int(2));
393 
394  if(part.script_int == 15)
395  part.links = ‪array(pieces thread ‪ents_from_script_int(9), pieces thread ‪ents_from_script_int(3));
396 
397  if(part.script_int == 16)
398  part.links = ‪array(pieces thread ‪ents_from_script_int(4), pieces thread ‪ents_from_script_int(10));
399 
400  if(part.script_int == 17)
401  part.links = ‪array(pieces thread ‪ents_from_script_int(5), pieces thread ‪ents_from_script_int(11));
402  }
403 
404  /*
405  | 0 | 1 | 2 | 3 |
406  | 4 | 5 | 6 | 7 |
407  | 8 | 9 | 10| 11|
408  | 12| 13| 14| 15|
409  | 16| 17| 18| 19|
410  */
411  else if( self.script_int == 4 )
412  {
413  if(part.script_int == 0 || part.script_int == 1 || part.script_int == 2 || part.script_int == 3)
414  part.links = [];
415 
416  if(part.script_int == 4)
417  part.links = ‪array(pieces thread ‪ents_from_script_int(0));
418 
419  if(part.script_int == 5)
420  part.links = ‪array(pieces thread ‪ents_from_script_int(0), pieces thread ‪ents_from_script_int(1),pieces thread ‪ents_from_script_int(4));
421 
422  if(part.script_int == 6)
423  part.links = ‪array(pieces thread ‪ents_from_script_int(2), pieces thread ‪ents_from_script_int(3),pieces thread ‪ents_from_script_int(7));
424 
425  if(part.script_int == 7)
426  part.links = ‪array(pieces thread ‪ents_from_script_int(3));
427 
428  if(part.script_int == 8)
429  part.links = ‪array(pieces thread ‪ents_from_script_int(0), pieces thread ‪ents_from_script_int(4));
430 
431  if(part.script_int == 9)
432  part.links = ‪array(pieces thread ‪ents_from_script_int(1), pieces thread ‪ents_from_script_int(5));
433 
434  if(part.script_int == 10)
435  part.links = ‪array(pieces thread ‪ents_from_script_int(2), pieces thread ‪ents_from_script_int(6));
436 
437  if(part.script_int == 11)
438  part.links = ‪array(pieces thread ‪ents_from_script_int(3), pieces thread ‪ents_from_script_int(7));
439 
440  if(part.script_int == 12)
441  part.links = ‪array( pieces thread ‪ents_from_script_int(0), pieces thread ‪ents_from_script_int(4),pieces thread ‪ents_from_script_int(8));
442 
443  if(part.script_int == 13)
444  part.links = ‪array(pieces thread ‪ents_from_script_int(1), pieces thread ‪ents_from_script_int(5), pieces thread ‪ents_from_script_int(9));
445 
446  if(part.script_int == 14)
447  part.links = ‪array(pieces thread ‪ents_from_script_int(2), pieces thread ‪ents_from_script_int(6), pieces thread ‪ents_from_script_int(10));
448 
449  if(part.script_int == 15)
450  part.links = ‪array(pieces thread ‪ents_from_script_int(3), pieces thread ‪ents_from_script_int(7), pieces thread ‪ents_from_script_int(11));
451 
452  if(part.script_int == 16)
453  part.links = ‪array(pieces thread ‪ents_from_script_int(0), pieces thread ‪ents_from_script_int(4), pieces thread ‪ents_from_script_int(8), pieces thread ‪ents_from_script_int(12));
454 
455  if(part.script_int == 17)
456  part.links = ‪array(pieces thread ‪ents_from_script_int(1), pieces thread ‪ents_from_script_int(5), pieces thread ‪ents_from_script_int(9), pieces thread ‪ents_from_script_int(13));
457 
458  if(part.script_int == 18)
459  part.links = ‪array(pieces thread ‪ents_from_script_int(2), pieces thread ‪ents_from_script_int(6), pieces thread ‪ents_from_script_int(10), pieces thread ‪ents_from_script_int(14));
460 
461  if(part.script_int == 19)
462  part.links = ‪array(pieces thread ‪ents_from_script_int(3), pieces thread ‪ents_from_script_int(7), pieces thread ‪ents_from_script_int(11), pieces thread ‪ents_from_script_int(15));
463  }
464 
465  else if( self.script_int == 2 )
466  {
467  part.links = [];
468  }
469 
470  part thread ‪pieces_think(self);
471  }
472 }
473 
474 // ============================================================================
476 {
477  foreach( ent in self)
478  {
479  if(ent.script_int == int)
480  return ent;
481  }
482 }
483 
484 // ============================================================================
485 //script_float: health values for piece
486 function ‪pieces_think(main_part)
487 {
488  self setcandamage(true);
489 
490  while( 1 )
491  {
492  self waittill("damage",amount, who);
493 
494  self.hlth = self.hlth - amount;
495  if (self.hlth > 0)
496  {
497  if(self.hlth < (self.script_float * 0.5) && IsDefined(self.script_noteworthy))
498  {
499  foreach( str in main_part.PartTags_dmg)
500  {
501  if(str == self.script_noteworthy) //cracked overlay exists
502  {
503  main_part ShowPart( str + "_cracks" );
504  continue;
505  }
506  }
507 
508  }
509  continue;
510  }
511 
512  if(IsDefined(self.links) && self.links.size > 0 )
513  {
514  // hack to get through inability to remove ents from array.
515  destroyed = 0;
516  foreach(ent in self.links)
517  {
518  if(‪IS_TRUE(ent.destroyed))
519  {
520  destroyed++;
521  }
522  else
523  {
524  ent DoDamage(self.script_float * (randomfloatrange(0.1, 0.4)) , ent.origin + (0, 0, 10));
525  }
526  }
527 
528  if(destroyed >= self.links.size)
529  {
530  self thread ‪destroy_geo_piece(main_part);
531  self.links = [];
532  return;
533  }
534  else
535  {
536  self.hlth = self.script_float;
537  }
538  }
539  else
540  {
541  self thread ‪destroy_geo_piece(main_part);
542  return;
543  }
544  }
545 }
546 
547 // ============================================================================
548 function ‪destroy_geo_piece(main_part)
549 {
550  self Hide();
551 
552  self.destroyed = true;
553 
554  ‪PlayFx(main_part.break_fx, self.origin);
555 
556  self playsound(main_part.break_sound);
557 
558  Self NotSolid();
559 }
‪destroy_piece
‪function destroy_piece(tag)
Definition: destructible_cover_shared.gsc:281
‪pass_on_damage
‪function pass_on_damage(damage, direction_vec, who, tag, type)
Definition: destructible_cover_shared.gsc:251
‪pieces_think
‪function pieces_think(main_part)
Definition: destructible_cover_shared.gsc:486
‪hide_cracked_parts
‪function hide_cracked_parts(tag_array)
Definition: destructible_cover_shared.gsc:148
‪destructible_cover_think
‪function destructible_cover_think()
Definition: destructible_cover_shared.gsc:37
‪dest_model_think
‪function dest_model_think()
Definition: destructible_cover_shared.gsc:158
‪spawn
‪function spawn(v_origin=(0, 0, 0), v_angles=(0, 0, 0))
Definition: struct.csc:23
‪IS_TRUE
‪#define IS_TRUE(__a)
Definition: shared.gsh:251
‪damage_notify_wrapper
‪function damage_notify_wrapper(damage, attacker, direction_vec, point, type, modelName, tagName, partName, iDFlags)
Definition: util_shared.gsc:1076
‪destroy_chunks
‪function destroy_chunks(chunk)
Definition: destructible_cover_shared.gsc:262
‪damage
‪function damage(trap)
Definition: _zm_trap_electric.gsc:116
‪ents_from_script_int
‪function ents_from_script_int(int)
Definition: destructible_cover_shared.gsc:475
‪precache_destructible_fx
‪function precache_destructible_fx()
Definition: destructible_cover_shared.gsc:272
‪REGISTER_SYSTEM
‪#define REGISTER_SYSTEM(__sys, __func_init_preload, __reqs)
Definition: shared.gsh:204
‪array
‪function filter array
Definition: array_shared.csc:16
‪destructible_cover_geo_think
‪function destructible_cover_geo_think()
Definition: destructible_cover_shared.gsc:330
‪__init__
‪function __init__()
Definition: destructible_cover_shared.gsc:20
‪destroy_geo_piece
‪function destroy_geo_piece(main_part)
Definition: destructible_cover_shared.gsc:548
‪dest_collision_watcher
‪function dest_collision_watcher(tag)
Definition: destructible_cover_shared.gsc:301
‪PlayFx
‪function PlayFx(name)
Definition: _counteruav.gsc:390