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