home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #6 / amigaacscoverdisc1998-061998.iso / games / shareware / crystalppc / script.h < prev    next >
C/C++ Source or Header  |  1998-06-08  |  3KB  |  138 lines

  1. #ifndef SCRIPT_H
  2. #define SCRIPT_H
  3.  
  4. #ifndef MATH3D_H
  5. #include "math3d.h"
  6. #endif
  7.  
  8. class PolygonSet;
  9. class ScriptRun;
  10. class World;
  11. class CsObject;
  12.  
  13. #define CMD_QUIT 0        // Stop script
  14. #define CMD_MOVE 1        // Move relative with given vector
  15. #define CMD_TRANSFORM 2        // Transform with given matrix
  16. #define CMD_LOOP 3        // Do a loop
  17. #define CMD_FOREVER 4        // Loop forever
  18. #define CMD_WAIT 5        // Wait
  19. #define CMD_RETURN 6        // Return from current sequence (possibly stop script if toplevel)
  20. #define CMD_SCRIPT 7        // Start a script for a local object
  21.  
  22. #define CMD_INITLOOP 100    // Internal command to initialize the loop
  23.  
  24. typedef signed char ubyte;
  25.  
  26. class CmdSequence
  27. {
  28.   friend class Script;
  29.   friend class CmdSequenceRun;
  30.   friend class ScriptRun;
  31.  
  32. private:
  33.   ubyte* cmds;        // All commands
  34.  
  35.   long* long_args;    // Long arguments
  36.   Matrix3* mat_args;    // Matrix arguments
  37.   Vector3* vec_args;    // Vector arguments
  38.   CmdSequence* seq_args;// CmdSequences
  39.  
  40.   int num_cmds;
  41.   int num_long_args, num_mat_args, num_vec_args, num_seq_args;
  42.   int num_long_vars;
  43.  
  44.   void compile_pass1 (char** buf);
  45.   void compile_pass2 (char** buf);
  46.  
  47.   CmdSequence ();
  48.   ~CmdSequence ();
  49. };
  50.  
  51. class Script
  52. {
  53.   friend class ScriptRun;
  54.  
  55. private:
  56.   Script* next;        // Linked list of all scripts.
  57.   CmdSequence main;    // Main command sequence for this script.
  58.  
  59.   char name[30];
  60.  
  61. public:
  62.   Script (char* name);
  63.   ~Script ();
  64.  
  65.   char* get_name () { return name; }
  66.  
  67.   void set_next (Script* n) { next = n; }
  68.   Script* get_next () { return next; }
  69.  
  70.   void save (FILE* fp, int indent);
  71.   void load (char** buf);
  72. };
  73.  
  74. class CmdSequenceRun
  75. {
  76.   friend class ScriptRun;
  77.  
  78. private:
  79.   int cur_cmd;
  80.   int cur_long_arg, cur_mat_arg, cur_vec_arg, cur_seq_arg;
  81.   long* vars;            // Local variables
  82.  
  83.   CmdSequenceRun ();
  84.   ~CmdSequenceRun ();
  85.  
  86.   void start (CmdSequence* seq);
  87. };
  88.  
  89. class ScriptRun
  90. {
  91. private:
  92.   ScriptRun* nextR, * prevR;    // Double linked list of all running scripts.
  93.   CsObject* object;        // Object to perform the actions on.
  94.   int type;            // Type of object (PS_THING or PS_SECTOR).
  95.   Script* script;        // Pointer to script.
  96.  
  97.   CmdSequenceRun stackr[20];
  98.   CmdSequence* stack[20];
  99.   int stack_idx;
  100.   CmdSequenceRun* seqr;
  101.   CmdSequence* seq;
  102.  
  103. public:
  104.   ScriptRun (Script* script, CsObject* object);
  105.   ~ScriptRun ();
  106.  
  107.   void set_next (ScriptRun* n) { nextR = n; }
  108.   void set_prev (ScriptRun* p) { prevR = p; }
  109.   ScriptRun* get_next () { return nextR; }
  110.   ScriptRun* get_prev () { return prevR; }
  111.  
  112.   void start ();    // Start script (is done at construction).
  113.   int step ();        // Do one step, return TRUE if finished.
  114. };
  115.  
  116. class TriggerList
  117. {
  118. private:
  119.   class Trigger
  120.   {
  121.   public:
  122.     Trigger* next;
  123.     CsObject* object;
  124.     Script* script;
  125.   };
  126.  
  127.   Trigger* first_trigger;
  128.  
  129. public:
  130.   TriggerList ();
  131.   ~TriggerList ();
  132.  
  133.   void add_trigger (Script* s, CsObject* ob = NULL);
  134.   void perform (World* w, CsObject* object);
  135. };
  136.  
  137. #endif /*SCRIPT_H*/
  138.