DI-Guy SDK Documentation  13.9
diguyVariable.h
Go to the documentation of this file.
1 /****************************************************************************
2  * Copyright (c) 2026 MAK Technologies, Inc.
3  * All rights reserved.
4  ****************************************************************************/
5 
6 /*********************************************************************
7  **
8  *t diguyVariable
9  **
10  *b Link against: libdiguy
11  */
12 
13 #pragma once
14 
15 #ifdef SWIG
16 %module diguyVariable
17 #else
18 #define CPLUSPLUS_ONLY
19 #endif
20 
21 #ifdef CPLUSPLUS_ONLY
22 
23 class bdiScenarioVariable;
24 class diguyCharacter;
25 class diguyScenario;
26 class diguyVariable;
27 
28 #include <stdio.h> // for NULL
29 #include <diguy_constants.h>
30 #include <diguy_typedefs.h>
31 
32 #endif /* CPLUSPLUS_ONLY */
33 
34 #include <declspec_diguy.h>
35 
45 /****************************************************************************/
46 class BDI_DECLSPEC_diguy diguyVariable
47 {
48 
49 public:
50 /*****************************************************************************/
60  /*l
61  *b Description:
62  **
63  ** Returns the name of the variable. This pointer will
64  ** never be NULL.
65  **
66  *b Returns:
67  **
68  ** name of the variable
69  */
70  const char* get_name();
71 
72  /*l
73  *b Description:
74  **
75  ** This function sets the name of this object.
76  **
77  *b Returns:
78  **
79  ** 0 on success, -1 on failure
80  */
81  int set_name(const char* name);
82 
83  /*l
84  *b Description:
85  **
86  ** Returns the type name of the object. This pointer will
87  ** never be NULL.
88  **
89  *b Returns:
90  **
91  ** type name of the object
92  */
93  const char* get_type_name();
94 
95  /*l
96  *b Description:
97  **
98  ** Returns the scenario that this variable belongs to. This
99  ** pointer will never be NULL. Note that if this variable
100  ** belongs to a character, a pointer to the scenario that the
101  ** character belongs to will be returned.
102  */
103  diguyScenario* get_scenario();
104 
105  /*l
106  *b Description:
107  **
108  ** Returns the character that this variable belongs to, if any.
109  ** This pointer might be NULL is this variable is not a
110  ** character variable.
111  */
112  diguyCharacter* get_character();
113 
114  /*l
115  *b Description:
116  **
117  ** Copies the contents of the passed variable.
118  **
119  *b Returns:
120  **
121  ** 0 on success, -1 on failure
122  */
123  int copy(diguyVariable* rhs);
124 
126  int get_value_as_int();
127 
129  float get_value_as_float();
130 
132  const char* get_value_as_string();
133 
134  /*l
135  *b Description:
136  **
137  ** Returns the initial value of the variable as an integer.
138  **
139  *b Returns:
140  **
141  ** initial value of the variable
142  **
143  *b Callable From:
144  **
145  *- - C++
146  *- - Script
147  */
148  int get_initial_value_as_int();
149 
150  /*l
151  *b Description:
152  **
153  ** Returns the initial value of the variable as a floating point
154  ** number.
155  **
156  *b Returns:
157  **
158  ** initial value of the variable
159  */
160  float get_initial_value_as_float();
161 
162  /*l
163  *b Description:
164  **
165  ** Returns the initial value of the variable as a string. This
166  ** pointer will never be NULL.
167  **
168  *b Returns:
169  **
170  ** initial value of the variable
171  */
172  const char* get_initial_value_as_string();
173 
174  /*l
175  *b Description:
176  **
177  ** This function sets the initial value as an integer.
178  ** The current value will be set to the initial value when the
179  ** scenario containing this variable is reset.
180  **
181  *b Arguments:
182  **
183  *a initial value - new initial value of variable
184  **
185  *b Returns:
186  **
187  ** 0 on success, -1 on failure
188  */
189  int set_initial_value_as_int(int initial_value);
190 
191  /*l
192  *b Description:
193  **
194  ** This function sets the initial value as a floating point number.
195  ** The current value will be set to the initial value when the
196  ** scenario containing this variable is reset.
197  **
198  *b Arguments:
199  **
200  *a initial value - new initial value of variable
201  **
202  *b Returns:
203  **
204  ** 0 on success, -1 on failure
205  */
206  int set_initial_value_as_float(float initial_value);
207 
208  /*l
209  *b Description:
210  **
211  ** This function sets the initial value as a string.
212  ** The current value will be set to the initial value when the
213  ** scenario containing this variable is reset.
214  **
215  *b Arguments:
216  **
217  *a initial value - new initial value of variable
218  **
219  *b Returns:
220  **
221  ** 0 on success, -1 on failure
222  */
223  int set_initial_value_as_string(const char* initial_value);
224 
225 
226 /*****************************************************************************/
237  /*l
238  *b Description:
239  **
240  ** This function sets the value as a bool.
241  **
242  *b Arguments:
243  **
244  *a value - new value of variable
245  **
246  *b Returns:
247  **
248  ** 0 on success, -1 on failure
249  */
250  int set_value_as_bool( bool value );
251 
253  bool get_value_as_bool() const;
254 
255  /*l
256  *b Description:
257  **
258  ** This function sets the value as an integer.
259  **
260  *b Arguments:
261  **
262  *a value - new value of variable
263  **
264  *b Returns:
265  **
266  ** 0 on success, -1 on failure
267  */
268  int set_value_as_int(int value);
269 
270  /*l
271  *b Description:
272  **
273  ** This function sets the value as a floating point number.
274  **
275  *b Arguments:
276  **
277  *a value - new value of variable
278  **
279  *b Returns:
280  **
281  ** 0 on success, -1 on failure
282  */
283  int set_value_as_float(float value);
284 
285  /*l
286  *b Description:
287  **
288  ** This function sets the value as a string.
289  **
290  *b Arguments:
291  **
292  *a value - new value of variable
293  **
294  *b Returns:
295  **
296  ** 0 on success, -1 on failure
297  */
298  int set_value_as_string(const char* value);
299 
300  /*l
301  *b Description:
302  **
303  ** This function increments the value as an int.
304  **
305  *b Arguments:
306  **
307  *a increment_amount - the value by which to increment
308  **
309  *b Returns:
310  **
311  ** 0 on success, -1 on failure
312  */
313  int increment_value_as_int(int increment_amount = 1);
314 
315  /*l
316  *b Description:
317  **
318  ** This function decrements the value as an int.
319  **
320  *b Arguments:
321  **
322  *a decrement_amount - the value by which to decrement
323  **
324  *b Returns:
325  **
326  ** 0 on success, -1 on failure
327  */
328  int decrement_value_as_int(int decrement_amount = 1);
329 
330  /*l
331  *b Returns:
332  **
333  ** 1 if the variable as an int is equal to the passed value;
334  ** 0 if not
335  **
336  *b Arguments:
337  **
338  *a value - the value to compare against
339  **
340  *b Returns:
341  **
342  ** 0 on success, -1 on failure
343  */
344  int equal_to_int(int value);
345 
346  /*l
347  *b Returns:
348  **
349  ** 1 if the variable as an int is greater than the passed value;
350  ** 0 if not
351  **
352  *b Arguments:
353  **
354  *a value - the value to compare against
355  */
356  int greater_than_int(int value);
357 
358  /*l
359  *b Returns:
360  **
361  ** 1 if the variable as an int is less than the passed value;
362  ** 0 if not
363  **
364  *b Arguments:
365  **
366  *a value - the value to compare against
367  */
368  int less_than_int(int value);
369 
370  /*l
371  *b Returns:
372  **
373  ** 1 if the variable as a float is equal to the passed value;
374  ** 0 if not
375  **
376  *b Arguments:
377  **
378  *a value - the value to compare against
379  */
380  int equal_to_float(float value);
381 
382  /*l
383  *b Returns:
384  **
385  ** 1 if the variable as a float is greater than the passed value;
386  ** 0 if not
387  **
388  *b Arguments:
389  **
390  *a value - the value to compare against
391  */
392  int greater_than_float(float value);
393 
394  /*l
395  *b Returns:
396  **
397  ** 1 if the variable as a float is less than the passed value;
398  ** 0 if not
399  **
400  *b Arguments:
401  **
402  *a value - the value to compare against
403  */
404  int less_than_float(float value);
405 
406  /*l
407  *b Returns:
408  **
409  ** 1 if the variable as a string is equal to the passed value;
410  ** 0 if not
411  **
412  *b Arguments:
413  **
414  *a value - the value to compare against
415  */
416  int equal_to_string(const char* value);
417 
418  /*l
419  *b Returns:
420  **
421  ** 1 if the variable as a string is alphabetically greater than
422  ** the passed value;
423  ** 0 if not
424  **
425  *b Arguments:
426  **
427  *a value - the value to compare against
428  */
429  int greater_than_string(const char* value);
430 
431  /*l
432  *b Returns:
433  **
434  ** 1 if the variable as a string is alphabetically less than
435  ** the passed value;
436  ** 0 if not
437  **
438  *b Arguments:
439  **
440  *a value - the value to compare against
441  */
442  int less_than_string(const char* value);
443 
444 
445 /*****************************************************************************/
450  /*l
451  *b Description:
452  **
453  ** This is an enumeration of the different callbacks
454  ** that can be registered with add_callback() and
455  ** add_callback_script().
456  **
457  *b Usable From:
458  **
459  *- - C++
460  *- - Script
461  */
462  enum {
463  CALLBACK_ID_VALUE_CHANGED = 1
464  };
465 
466 #ifdef CPLUSPLUS_ONLY
467 
468  /*l
469  *b Description:
470  **
471  ** This function adds a user callback.
472  **
473  *b Arguments:
474  **
475  *a callback - pointer to function with prototype
476  *a diguyVariableCallback (typedefed above)
477  *a callback_id - integer id of when this callback is to be called
478  *a callback_params - not currently used; pass NULL
479  *a callback_user_data - pointer for user's own use; DI-Guy will
480  *a do nothing to the contents of this pointer
481  *a beyond passing it back when the callback is
482  *a invoked
483  **
484  ** callback_id should be one of the following values:
485  **
486  *i CALLBACK_ID_VALUE_CHANGED
487  **
488  ** This callback will be called whenever the value of the
489  ** variable changes.
490  **
491  ** There are no parameters for this callback.
492  **
493  *i Callback Return Values:
494  **
495  ** Callbacks return a value of type diguyCallbackReturn,
496  ** which will be DIGUY_CALLBACK_STOP or DIGUY_CALLBACK_CONTINUE.
497  ** If the callback returns DIGUY_CALLBACK_STOP, the default handler
498  ** of the function will not be called; the callback is asserting
499  ** that it has done everything necessary for the function call.
500  ** If the callback returns DIGUY_CALLBACK_CONTINUE, the default
501  ** handler for the function will be called after the callback.
502  **
503  *b Returns:
504  **
505  ** 0 on success, -1 on failure
506  **
507  *b Callable From:
508  **
509  *- - C++
510  */
511  int add_callback(int callback_id,
512  diguyVariableCallback* callback,
513  void* callback_params = 0,
514  void* callback_user_data = 0);
515 
516  /*l
517  *b Description:
518  **
519  ** This function removes a user callback. All callbacks matching
520  ** the specified callback_id and callback function will be removed.
521  **
522  *b Arguments:
523  **
524  *a callback_id - integer id of when this callback is to be called
525  *a callback - pointer to function with prototype
526  *a diguyVariableCallback (typedefed above)
527  **
528  *b Returns:
529  **
530  ** 0 on success, -1 on failure
531  **
532  *b Callable From:
533  **
534  *- - C++
535  */
536  int remove_callback(int callback_id,
537  diguyVariableCallback* callback);
538 
539  /*l
540  *b Description:
541  **
542  ** This function removes a user callback. All callbacks matching
543  ** the specified callback_id and callback_user_data pointer will
544  ** be removed.
545  **
546  *b Arguments:
547  **
548  *a callback_id - integer id of when this callback is to be called
549  *a callback_user_data - pointer for user's own use
550  **
551  *b Returns:
552  **
553  ** 0 on success, -1 on failure
554  **
555  *b Callable From:
556  **
557  *- - C++
558  */
559  int remove_callback_with_user_data(int callback_id,
560  void* callback_user_data);
561 
562 #endif /* CPLUSPLUS_ONLY */
563 
564  /*l
565  *b Description:
566  **
567  ** This function adds a user callback script. Callback scripts can
568  ** be removed with remove_callback_script().
569  **
570  ** See diguyCharacter::add_callback_script() for an example
571  ** of use.
572  **
573  *b Arguments:
574  **
575  *a callback_id - integer id of the callback
576  *a callback_script - script text of callback to be added
577  *a callback_script_type - the type of script contained in
578  *a callback_script
579  **
580  ** If NULL is passed for callback_script_type, a default script type
581  ** will be derived based on the default script interpreter of the
582  ** scenario.
583  **
584  *i Lua specific:
585  **
586  ** When the script is called, the object for which it is being called
587  ** will be in the callback_object global.
588  **
589  ** To pass NULL when calling from a lua script, use nil.
590  **
591  *b Returns:
592  **
593  ** 0 on success, -1 on failure
594  **
595  *b Callable From:
596  **
597  *- - C++
598  *- - Script
599  */
600  int add_callback_script(int callback_id,
601  const char* callback_script,
602  const char* callback_script_type = NULL);
603 
604  /*l
605  *b Description:
606  **
607  ** This function removes a user callback script previously added with
608  ** add_callback_script().
609  **
610  ** See diguyCharacter::remove_callback_script() for an example
611  ** of use.
612  **
613  *b Arguments:
614  **
615  *a callback_id - integer id of the callback
616  *a callback_script - script text of callback previously added
617  *a callback_script_type - the type of script contained in
618  *a callback_script
619  **
620  ** If NULL is passed for callback_script, all callback
621  ** scripts whose ids match callback_id and whose types match
622  ** callback_script_type will be removed.
623  **
624  ** If NULL is passed for callback_script_type, a default script type
625  ** will be derived based on the default script interpreter of the
626  ** scenario.
627  **
628  *i Lua specific:
629  **
630  ** To pass NULL when calling from a lua script, use nil.
631  **
632  *b Returns:
633  **
634  ** 0 on success, -1 on failure
635  **
636  *b Callable From:
637  **
638  *- - C++
639  *- - Script
640  */
641  int remove_callback_script(int callback_id,
642  const char* callback_script,
643  const char* callback_script_type = NULL);
644 
645 
646 /*****************************************************************************/
656  /*l
657  *b Description:
658  **
659  ** This function maps the event handler with the given name
660  ** to a callback id. This mapping will be saved in the .dss
661  ** file and restored when the .dss file is loaded.
662  **
663  ** Mappings can also be made via the DI-Guy Scenario UI.
664  **
665  ** The event handler is one of the following:
666  **
667  *- - a variable callback function registered by
668  *- diguyScenario::register_variable_event_handler() or
669  *- diguyScenario::register_variable_event_handler_from_library()
670  *- - a script registered by
671  *- diguyScenario::register_variable_event_handler_script()
672  *- - a Script, Decision, or Library Function in the scenario
673  *- whose "Event Type" is "Variable"
674  **
675  *b Arguments:
676  **
677  *a callback_id - integer id of callback
678  *a handler_name - name of the event handler to map
679  **
680  *b Returns:
681  **
682  ** 0 on success, -1 on failure
683  */
684  int map_event_handler_to_callback_id(int callback_id,
685  const char* handler_name);
686 
687  /*l
688  *b Description:
689  **
690  ** This function unmaps the event handler with the given name
691  ** from a callback id.
692  **
693  *b Arguments:
694  **
695  *a callback_id - integer id of callback
696  *a handler_name - name of the event handler to map
697  *a unmap_all_matches - pass 0 to unmap only the first match,
698  *a pass 1 to unmap all matches
699  **
700  *b Returns:
701  **
702  ** 0 on success, -1 on failure
703  */
704  int unmap_event_handler_from_callback_id(int callback_id,
705  const char* handler_name,
706  int unmap_all_matches = 0);
707 
708 
713 #ifdef CPLUSPLUS_ONLY
714 
715  bdiScenarioVariable* get_scripted_object() {return m_scripted_object;}
716 
717 private:
718 
719  /*l
720  ** A private constructor.
721  */
722  diguyVariable(bdiScenarioVariable* variable);
723 
724  /*l
725  ** A pointer to internal data.
726  */
727  bdiScenarioVariable* m_scripted_object;
728 
729  friend class bdiScenarioVariable;
730 
731 #endif /* CPLUSPLUS_ONLY */
732 
733 };
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
The diguyVariable class allows you to add per character named parameters. This can be handy for track...
Definition: diguyVariable.h:44
diguyCallbackReturn diguyVariableCallback(diguyVariable *variable, int callback_id, void *callback_params, void *callback_user_data)
Definition: diguy_typedefs.h:199