DI-Guy SDK Documentation  13.8
diguyImpact.h
Go to the documentation of this file.
1 /****************************************************************************
2  * Copyright (c) 2024 MAK Technologies, Inc.
3  * All rights reserved.
4  ****************************************************************************/
5 
6 /*********************************************************************
7  **
8  *t diguyImpact
9  **
10  *b Link against: libdiguy
11  */
12 
13 #pragma once
14 
15 #ifdef SWIG
16 %module diguyImpact
17 #else
18 #define CPLUSPLUS_ONLY
19 #endif
20 
21 #ifdef CPLUSPLUS_ONLY
22 #include <stdio.h> // for NULL
23 class diguyCharacter;
24 class diguyScenario;
25 class diguySceneObject;
26 #endif
27 
28 #include <declspec_diguy.h>
29 #include <diguy_constants.h>
30 #include <diguy_vector_classes.h>
31 
39 /****************************************************************************/
40 class BDI_DECLSPEC_diguy diguyImpact
41 {
42 
43 public:
44 
45 /****************************************************************************/
55  /*l
56  *b Description:
57  **
58  ** Returns the type of impact; this is based on how the collision was
59  ** generated. Possible values are:
60  **
61  *- - DIGUY_IMPACT_DIRECT_HIT
62  *- - DIGUY_IMPACT_NEARBY_DETONATION
63  *- - DIGUY_IMPACT_VEHICLE_COLLISION
64  *- - DIGUY_IMPACT_NO_IMPACT
65  *- - DIGUY_IMPACT_USER_GENERATED
66  **
67  ** Note: NO_IMPACT is generated when a character fires but fails the
68  ** hit ratio test. The location of the impact is then set to the
69  ** attacker's position, or if that is unavailable to:
70  ** (DIGUY_DEFAULT_FLOAT, DIGUY_DEFAULT_FLOAT, DIGUY_DEFAULT_FLOAT).
71  **
72  *b Returns:
73  **
74  ** the type of impact
75  */
76  diguyImpactType get_impact_type();
77 
78  /*l
79  *b Returns:
80  **
81  ** the string version of the type of impact. This is based
82  ** on how the collision was generated. Possible values are:
83  **
84  *- - "direct_hit"
85  *- - "nearby_detonation"
86  *- - "vehicle_collision"
87  *- - "no_impact"
88  *- - "user_generated"
89  */
90  const char* get_impact_type_string();
91 
92  /*l
93  *b Returns:
94  **
95  ** the number of hits made by this impact. This includes hits
96  ** against characters and scene objects.
97  */
98  int get_num_hits();
99 
100  /*l
101  *b Returns:
102  **
103  ** the name of the attacker. This pointer may be NULL if
104  ** there is no attacker character.
105  */
106  const char* get_attacker_name();
107 
108  /*l
109  *b Returns:
110  **
111  ** Returns a pointer to the attacker. This pointer may be NULL.
112  */
113  diguyCharacter* get_attacker();
114 
115  /*l
116  *b Returns:
117  **
118  ** the name of the target. This pointer may be NULL if there
119  ** is no impact target character (e.g., impact is against a scene
120  ** object).
121  */
122  const char* get_target_name();
123 
124  /*l
125  *b Returns:
126  **
127  ** the diguyCharacter impact target. This pointer may be NULL if there is no
128  ** impact target character (e.g., impact is against a scene object).
129  */
130  diguyCharacter* get_target();
131 
132  /*l
133  *b Returns:
134  **
135  ** name of the target character link that was hit; may be NULL if
136  ** there is no hit target character
137  */
138  const char* get_hit_link_name();
139 
140  /*l
141  *b Returns:
142  **
143  ** index of the target character link that was hit
144  */
145  int get_hit_link_index();
146 
147  /*l
148  *b Returns:
149  **
150  ** name of the target character shape that was hit; may be NULL if
151  ** there is no hit target character
152  */
153  const char* get_hit_shape_name();
154 
155  /*l
156  *b Returns:
157  **
158  ** index of the target character shape that was hit
159  */
160  int get_hit_shape_index();
161 
162  /*l
163  *b Returns:
164  **
165  ** the number of impacts the target character has taken
166  */
167  int get_impact_number();
168 
169  /*l
170  *b Description:
171  **
172  ** Sets the impact number.
173  */
174  void set_impact_number(int val);
175 
176  /*l
177  *b Description:
178  **
179  ** Sets that the impact has been processed.
180  */
181  void set_impact_been_processed();
182 
183  /*l
184  *b Returns:
185  **
186  ** 1 if the impact has been processed, 0 if not
187  */
188  int get_impact_been_processed();
189 
190  /*l
191  *b Returns:
192  **
193  ** the approximate world x coordinate of the impact
194  */
195  float get_x();
196 
197  /*l
198  *b Returns:
199  **
200  ** the approximate world y coordinate of the impact
201  */
202  float get_y();
203 
204  /*l
205  *b Returns:
206  **
207  ** the approximate world z coordinate of the impact
208  */
209  float get_z();
210 
211  /*l
212  *b Description:
213  **
214  ** Alternative method for getting the location of the impact.
215  */
216  void get_location(float* x, float* y, float* z);
217 
218  /*l
219  *b Returns:
220  **
221  ** the radius of the impact
222  */
223  float get_impact_radius();
224 
225  /*l
226  *b Returns:
227  **
228  ** the speed of the impact
229  */
230  float get_impact_speed();
231 
232  /*l
233  *b Description:
234  **
235  ** This function returns the location of the impact in link-relative
236  ** coordinates. The function may fail and return -1 if a link was not
237  ** hit by the impact.
238  **
239  *b Arguments:
240  **
241  *a link_x, link_y, link_z - link-relative coordinates are
242  ** returned in these variables
243  **
244  *b Returns:
245  **
246  ** 0 on success, -1 on failure
247  */
248  int get_location_in_link_coordinates(float* link_x,
249  float* link_y,
250  float* link_z);
251 
252  /*l
253  *b Description:
254  **
255  ** This function resets all of the impact data to default values.
256  */
257  void reset();
258 
259  /*l
260  *b Description:
261  **
262  ** This function returns the name of the munition that was fired. This
263  ** is useful for creating impact callbacks that respond differently to
264  ** different weapons.
265  **
266  *b Returns:
267  **
268  ** the munition type of the impact; may be NULL
269  */
270  const char* get_munition_type();
271 
272  /*l
273  *b Description:
274  **
275  ** Returns the hit diguySceneObject.
276  **
277  ** This pointer may be NULL if there is no impact scene object (e.g.,
278  ** impact is against a character).
279  **
280  ** If the octtree was used to generate the impact, this pointer will
281  ** be NULL.
282  **
283  *b Returns:
284  **
285  ** pointer of type diguySceneObject
286  */
287  diguySceneObject* get_hit_scene_object();
288 
289  /*l
290  *b Returns:
291  **
292  ** approximate normal x coordinate of the impact; may not be valid
293  */
294  float get_normal_x();
295 
296  /*l
297  *b Returns:
298  **
299  ** approximate normal y coordinate of the impact; may not be valid
300  */
301  float get_normal_y();
302 
303  /*l
304  *b Returns:
305  **
306  ** approximate normal z coordinate of the impact; may not be valid
307  */
308  float get_normal_z();
309 
310  /*l
311  *b Description:
312  **
313  ** Alternative method for getting the normal of the impact.
314  */
315  void get_impact_normal(float* x, float* y, float* z);
316 
317 
318 /*****************************************************************************/
326  /*l
327  *b Description:
328  **
329  ** Velocity of projectile at impact. May be 0 if no velocity
330  ** information is available.
331  */
332  void get_impact_velocity(float* x, float* y, float* z);
333 
334  /*l
335  *b Returns:
336  **
337  ** 1 if impact was generated as a result of a network detonation (e.g.
338  ** a DIS detonation PDU), else 0
339  */
340  int get_is_from_net_detonation();
341 
342  /*l
343  *b Description:
344  **
345  ** This function returns the specified part of the DIS septet of the
346  ** detonation's munition septet.
347  **
348  *b Arguments:
349  **
350  *a septet_index - which part of the septet to return; must be between
351  *a 0 (for 'kind') and 6 (for 'extra')
352  **
353  ** Returns -1 if septet isn't specified, or on error.
354  */
355  int get_DIS_munition_septet_value(int septet_index);
356 
357  /*l
358  *b Returns:
359  **
360  ** the site id part of the detonation PDU event id; -1 if not set
361  */
362  int get_DIS_site();
363 
364  /*l
365  *b Returns:
366  **
367  ** the host id part of the detonation PDU event id; -1 if not set
368  */
369  int get_DIS_host();
370 
371  /*l
372  *b Returns:
373  **
374  ** the event number part of the detonation PDU event id; -1 if not set
375  */
376  int get_DIS_event_number();
377 
378  /*l
379  *b Returns:
380  **
381  ** the event number part of the detonation PDU *munition* event id;
382  ** -1 if not set
383  */
384  int get_DIS_munition_number();
385 
386  /*l
387  *b Returns:
388  **
389  ** the detonation result of the detonation PDU; -1 if not set
390  */
391  int get_DIS_detonation_result();
392 
393  /*l
394  *b Returns:
395  **
396  ** the warhead type enumeration of the detonation PDU's burst
397  ** descriptor; -1 if not set
398  */
399  int get_DIS_burst_warhead_type();
400 
401  /*l
402  *b Returns:
403  **
404  ** the fuze enumeration of the detonation PDU's burst descriptor; -1
405  ** if not set
406  */
407  int get_DIS_burst_fuze();
408 
409  /*l
410  *b Returns:
411  **
412  ** the burst quantity of the detonation PDU's burst descriptor; -1 if
413  ** not set
414  */
415  int get_DIS_burst_quantity();
416 
417  /*l
418  *b Returns:
419  **
420  ** the burst rate of the detonation PDU's burst descriptor; -1 if not
421  ** set
422  */
423  int get_DIS_burst_rate();
424 
425 
426 #ifdef CPLUSPLUS_ONLY
427 
428 /*****************************************************************************/
493  /*l
494  *b Description:
495  **
496  ** This function sets the impact to be valid. It must be called if
497  ** the impact hits a character.
498  */
499  void set_valid_impact();
500 
501  /*l
502  *b Description:
503  **
504  ** This function allows for explicitly setting the target character of
505  ** this impact object.
506  **
507  *b Arguments:
508  **
509  *a x, y, z - override target of impact
510  **
511  *b Callable From:
512  **
513  *- - C++
514  */
515  void set_target(diguyCharacter* target);
516 
517  /*l
518  *b Description:
519  **
520  ** This function allows for explicitly setting the position of this
521  ** impact object.
522  **
523  *b Arguments:
524  **
525  *a x, y, z - override position of impact
526  **
527  *b Callable From:
528  **
529  *- - C++
530  */
531  void set_location(float x, float y, float z);
532 
533  /*l
534  *b Description:
535  **
536  ** This function allows for explicitly setting the normal of this
537  ** impact object.
538  **
539  *b Arguments:
540  **
541  *a nx, ny, nz - override normal of impact
542  **
543  *b Callable From:
544  **
545  *- - C++
546  */
547  void set_normal(float nx, float ny, float nz);
548 
549  /*l
550  *b Description:
551  **
552  ** Returns the hit scene object.
553  **
554  ** This function allows for explicitly setting the scene_object that
555  ** the impact object hit.
556  **
557  ** If the octtree was used to generate the impact, this pointer will
558  ** be NULL.
559  **
560  *b Arguments:
561  **
562  *a scene_object - pointer to scene object hit
563  **
564  *b Callable From:
565  **
566  *- - C++
567  */
568  void set_hit_scene_object(diguySceneObject* scene_object);
569 
570  /*l
571  *b Description:
572  **
573  ** This function allows for explicitly setting the link index of this
574  ** impact object.
575  **
576  *b Callable From:
577  **
578  *- - C++
579  */
580  void set_hit_link_index(int index);
582  /*l
583  *b Description:
584  **
585  ** This function allows for explicitly setting the shape index of this
586  ** impact object.
587  **
588  *b Callable From:
589  **
590  *- - C++
591  */
592  void set_hit_shape_index(int index);
595 /****************************************************************************/
596 /****************************************************************************/
597 
602 private:
604  friend class bdiScenarioEditorDIGS;
605  friend class bdiPublishedCharacter;
606  friend class bdiScenario;
607  friend class bdiScenarioCharacter;
608  friend class bdiScenarioCrowdWorkManager;
609  friend class diguyCharacter;
610  friend class bdiQGLWidgetDIGS;
612  void set_munition_type(const char* munition_type);
613 
614  /*l
615  ** Private constructors.
616  */
617  diguyImpact();
618 
619  diguyImpact(diguyScenario* scenario,
621  int num_hits = 0,
622  diguyCharacter* attacker = NULL,
623  diguyCharacter* target = NULL,
624  diguySceneObject* hit_scene_object = NULL,
625  int link_index = -1,
626  int shape_index = -1,
627  float* location = NULL,
628  float* normal = NULL,
629  float impact_speed = 0.0f,
630  float radius = 0.0f,
631  const char* munition_type = NULL);
633  /*
634  * Private data members.
635  */
636  diguyScenario* m_scenario;
637  diguyImpactType m_impact_type;
638  int m_num_hits;
639  diguyCharacter* m_attacker;
640  diguyCharacter* m_target;
641  diguySceneObject* m_hit_scene_object;
642  int m_link_index;
643  int m_shape_index;
644  int m_impact_number;
645  int m_impact_processed;
646  float m_location[3];
647  float m_normal[3];
648  float m_impact_speed;
649  float m_impact_radius;
650  char m_munition_type[128];
651 
652 public:
653  /*
654  * FOR INTERNAL DI-GUY USE ONLY
655  */
656  int m_is_from_net_detonation;
657  int m_DIS_munition_septet[7];
658  int m_DIS_site;
659  int m_DIS_host;
660  int m_DIS_event_number;
661  int m_DIS_munition_number;
662  int m_DIS_detonation_result;
663  int m_DIS_burst_warhead_type;
664  int m_DIS_burst_fuze;
665  int m_DIS_burst_quantity;
666  int m_DIS_burst_rate;
667  float m_impact_velocity[3];
668 private:
669 
670 #endif
671 
672 };
673 
674 
675 /****************************************************************************/
677 class BDI_DECLSPEC_diguy diguyIntersectionResult
678 {
679 public:
680 
682  : m_impact_character( NULL )
683  , m_impact_scene_object( NULL )
684  , m_valid_impact( 0 )
685  {
686  }
687 
689  {
690  }
691 
692  diguyCharacter* get_impact_character();
693  diguySceneObject* get_impact_scene_object();
694 
695  int get_impact_point( float* ret_x, float* ret_y, float* ret_z );
696  int get_valid_impact();
697 
698 public:
699 
700  diguyCharacter* m_impact_character;
701  diguySceneObject* m_impact_scene_object;
702  diguyVec3f m_impact_point;
703  diguyVec3f m_impact_normal;
704  int m_valid_impact;
705 
706 };
Experimental class for diguyIntersectionResult exp_intersect_geometry.
Definition: diguyImpact.h:621
A class that represents a bullet impact in the world, often used by AIs to make reaction decisions...
Definition: diguyImpact.h:39
diguyImpactType
This is an enumeration of the different impact types that are found in diguyImpact.
Definition: diguy_constants.h:247
Represents the scenario currently being portrayed.
Definition: diguyScenario.h:99
The class that represents a DI-Guy Entity in the world.
Definition: diguyCharacter.h:81
Definition: diguy_constants.h:249
Definition: diguy_vector_classes.h:74
A scene object is a static (that is, non-moving) object in the scenario. Scene objects are the basic ...
Definition: diguySceneObject.h:43