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