egg.h

Go to the documentation of this file.
00001 /*
00002  *  Copyright (C) 1998-1999  Jeffrey S. Freedman
00003  *  Copyright (C) 2000-2001  The Exult Team
00004  *
00005  *  This program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation; either version 2 of the License, or
00008  *  (at your option) any later version.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00018  */
00019 
00020 #ifndef INCL_EGG
00021 #define INCL_EGG  1
00022 
00023 class Egg_object;
00024 class Animated_egg_object;
00025 class Animator;
00026 class   Monster_actor;
00027 class   Missile_launcher;
00028 
00029 #include "iregobjs.h"
00030 
00031 /*
00032  *  Here's a class for eggs and paths; i.e., objects that generally aren't
00033  *  visible.
00034  */
00035 class Egglike_game_object : public Ireg_game_object
00036   {
00037 public:
00038   Egglike_game_object(int shapenum, int framenum,
00039         unsigned int tilex,
00040         unsigned int tiley, unsigned int lft = 0)
00041     : Ireg_game_object(shapenum, framenum, tilex, tiley, lft)
00042     {  }
00043           // Render.
00044   virtual void paint();
00045           // Can this be clicked on?
00046   virtual int is_findable();
00047   };
00048 
00049 /*
00050  *  An "egg" is a special object that activates under certain
00051  *  circumstances.
00052  */
00053 class Egg_object : public Egglike_game_object
00054   {
00055   static Egg_object *editing; // Egg being edited by ExultStudio.
00056 protected:
00057   unsigned char type;   // One of the below types.
00058   unsigned char probability;  // 1-100, chance of egg activating.
00059   unsigned char criteria:3; // How it's activated.  See below.
00060   unsigned distance:6;    // Distance for activation (0-31).
00061   unsigned flags:4;   // Formed from below flags.
00062   unsigned short data1, data2;  // More data, depending on type.
00063   Rectangle area;     // Active area.
00064   unsigned char solid_area; // 1 if area is solid, 0 if outline.
00065   Missile_launcher *launcher; // For missile eggs.
00066   void init_field(unsigned char ty);
00067   void activate_teleport(Game_object *obj); // Handle teleport egg.
00068 public:
00069   enum Egg_types {    // Types of eggs:
00070     monster = 1,
00071     jukebox = 2,
00072     soundsfx = 3,
00073     voice = 4,
00074     usecode = 5,
00075     missile = 6,
00076     teleport = 7,
00077     weather = 8,
00078     path = 9,
00079     button = 10,
00080           // Our own:
00081     fire_field = 128,
00082     sleep_field = 129,
00083     poison_field = 130,
00084     caltrops_field = 131,
00085     mirror_object = 132
00086     };
00087   enum Egg_flag_shifts {
00088     nocturnal = 0,
00089     once = 1,
00090     hatched = 2,
00091     auto_reset = 3
00092     };
00093   enum Egg_criteria {
00094     cached_in = 0,    // Activated when chunk read in?
00095     party_near = 1,
00096     avatar_near = 2,  // Avatar steps into area.
00097     avatar_far = 3,   // Avatar steps outside area.
00098     avatar_footpad = 4, // Avatar must step on it.
00099     party_footpad = 5,
00100     something_on = 6, // Something placed on/near it.
00101     external_criteria = 7 // Appears on Isle of Avatar.  Guessing
00102           //   these set off all nearby.
00103     };
00104           // Create normal eggs.
00105   Egg_object(int shapenum, int framenum, unsigned int tilex,
00106     unsigned int tiley, unsigned int lft, 
00107     unsigned short itype,
00108     unsigned char prob, short d1, short d2);
00109           // Ctor. for fields:
00110   Egg_object(int shapenum, int framenum, unsigned int tilex, 
00111         unsigned int tiley, unsigned int lft,
00112         unsigned char ty);
00113   virtual ~Egg_object();
00114   virtual void set_area();    // Set up active area.
00115   int get_distance() const
00116     { return distance; }
00117   int get_criteria() const
00118     { return criteria; }
00119   int get_type() const
00120     { return type; }
00121           // Can it be activated?
00122   virtual int is_active(Game_object *obj,
00123       int tx, int ty, int tz, int from_tx, int from_ty);
00124 
00125   Rectangle get_area() const  // Get active area.
00126     { return area; }
00127   int is_solid_area() const
00128     { return solid_area; }
00129           // Render.
00130   virtual void paint();
00131           // Run usecode function.
00132   virtual void activate(int event = 1);
00133   virtual bool edit();    // Edit in ExultStudio.
00134           // Saved from ExultStudio.
00135   static void update_from_studio(unsigned char *data, int datalen);
00136   virtual void activate(Game_object *obj, bool must = false);
00137   void print_debug();
00138   static void set_weather(int weather, int len = 15,
00139             Game_object *egg = 0);
00140           // Move to new abs. location.
00141   virtual void move(int newtx, int newty, int newlift);
00142           // Remove/delete this object.
00143   virtual void remove_this(int nodel = 0);
00144   virtual int is_egg() const  // An egg?
00145     { return 1; }
00146           // Write out to IREG file.
00147   virtual void write_ireg(DataSource* out);
00148         // Get size of IREG. Returns -1 if can't write to buffer
00149   virtual int get_ireg_size();
00150 
00151   virtual void reset() 
00152     { flags &= ~(1 << hatched); }
00153 
00154   virtual Egg_object *as_egg() { return this; }
00155 
00156   };
00157 
00158 /*
00159  *  An object that cycles through its frames, or wiggles if just one
00160  *  frame.
00161  */
00162 class Animated_egg_object : public Egg_object
00163   {
00164 protected:
00165   Animator *animator;   // Controls animation.
00166 public:
00167   Animated_egg_object(int shapenum, int framenum,
00168     unsigned int tilex,
00169     unsigned int tiley, unsigned int lft, 
00170     unsigned short itype,
00171     unsigned char prob, short d1, short d2);
00172   Animated_egg_object(int shapenum, int framenum, unsigned int tilex, 
00173         unsigned int tiley, unsigned int lft,
00174         unsigned char ty);
00175   virtual ~Animated_egg_object();
00176           // Render.
00177   virtual void paint();
00178           // Can this be clicked on?
00179   virtual int is_findable()
00180     { return Ireg_game_object::is_findable(); }
00181           // Run usecode function.
00182   virtual void activate(int event = 1);
00183   void stop_animation();
00184   };
00185 
00186 /*
00187  *  Fields are activated like eggs.
00188  */
00189 
00190 class Field_object : public Animated_egg_object
00191   {
00192   bool field_effect(Actor *actor);// Apply field.
00193 public:
00194   Field_object(int shapenum, int framenum, unsigned int tilex, 
00195     unsigned int tiley, unsigned int lft, unsigned char ty)
00196     : Animated_egg_object(shapenum, framenum, tilex, tiley,
00197               lft, ty)
00198     {  }
00199           // Run usecode function.
00200   virtual void activate(int event = 1);
00201   virtual void activate(Game_object *obj, bool must = false);
00202           // Write out to IREG file.
00203   virtual void write_ireg(DataSource* out);
00204         // Get size of IREG. Returns -1 if can't write to buffer
00205   virtual int get_ireg_size();
00206   };
00207 
00208 /*
00209  *  Mirrors are handled like eggs.
00210  */
00211 
00212 class Mirror_object : public Egg_object
00213 {
00214 public:
00215   Mirror_object(int shapenum, int framenum, unsigned int tilex, 
00216     unsigned int tiley, unsigned int lft);
00217 
00218           // Run usecode function.
00219   virtual void activate(int event = 1);
00220   virtual void activate(Game_object *obj, bool must = false);
00221 
00222           // Can it be activated?
00223   virtual int is_active(Game_object *obj,
00224       int tx, int ty, int tz, int from_tx, int from_ty);
00225 
00226   virtual void set_area();    // Set up active area.
00227 
00228           // Render.
00229   virtual void paint();
00230           // Can this be clicked on?
00231   virtual int is_findable()
00232     { return Ireg_game_object::is_findable(); }
00233 
00234   virtual void write_ireg(DataSource* out);
00235         // Get size of IREG. Returns -1 if can't write to buffer
00236   virtual int get_ireg_size();
00237 };
00238 #endif

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