ucsched.h

Go to the documentation of this file.
00001 /*
00002  *  Copyright (C) 2000-2001  The Exult Team
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  */
00018 
00019 #ifndef _UCSCHED_H
00020 #define _UCSCHED_H
00021 
00022 class Game_object;
00023 class Usecode_value;
00024 class Usecode_internal;
00025 
00026 #include "tqueue.h"
00027 
00028 /*
00029  *  A class for executing usecode at a scheduled time:
00030  */
00031 class Usecode_script : public Time_sensitive
00032   {
00033   static int count;   // Total # of these around.
00034   static Usecode_script *first;// ->chain of all of them.
00035   Usecode_script *next, *prev;  // Next/prev. in global chain.
00036   Game_object *obj;   // From objval.
00037   Usecode_value *code;    // Array of code to execute.
00038   int cnt;      // Length of arrval.
00039   int i;        // Current index.
00040   int frame_index;    // For taking steps.
00041   bool no_halt;     // 1 to ignore halt().
00042   bool must_finish;   // 1 to finish before deleting.
00043   int delay;      // Used for restoring.
00044           // For restore:
00045   Usecode_script(Game_object *item, Usecode_value *cd, int findex,
00046             int nhalt, int del);
00047 public:
00048   Usecode_script(Game_object *o, Usecode_value *cd = 0);
00049   ~Usecode_script();
00050   void start(long delay = 1); // Start after 'delay' msecs.
00051   long get_delay() const
00052     { return delay; }
00053   void halt();      // Stop executing.
00054   bool is_no_halt() const   // Is the 'no_halt' flag set?
00055     { return no_halt; }
00056   int is_activated()    // Started already?
00057     { return i > 0; }
00058   void add(int v1);   // Append new instructions:
00059   void add(int v1, int v2);
00060   void add(int v1, const char *str);
00061   void add(int *vals, int cnt);
00062   Usecode_script& operator<<(int v)
00063     { add(v); return *this; }
00064   inline void activate_egg(Usecode_internal *usecode,  Game_object *e);
00065 
00066   static int get_count()
00067     { return count; }
00068           // Find for given item.
00069   static Usecode_script *find(Game_object *srch, 
00070           Usecode_script *last_found = 0);
00071   static void terminate(Game_object *obj);
00072   static void clear();    // Delete all.
00073           // Remove all whose objs. are too far.
00074   static void purge(Tile_coord pos, int dist);
00075   virtual void handle_event(unsigned long curtime, long udata);
00076   int exec(Usecode_internal *usecode, bool finish);
00077           // Move object in given direction.
00078   void step(Usecode_internal *usecode, int dir);
00079           // Save/restore.
00080   int save(unsigned char *buf, int buflen);
00081   static Usecode_script *restore(Game_object *item,
00082           unsigned char *buf, int buflen);
00083   void print(std::ostream& out);  // Print values.
00084   };
00085 
00086 
00087 #endif

Generated on Mon Jul 9 14:42:52 2007 for ExultEngine by  doxygen 1.5.1