effects.h

Go to the documentation of this file.
00001 /*
00002  *  effects.h - Special effects.
00003  *
00004  *  Copyright (C) 2000-2001  The Exult Team
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00019  */
00020 
00021 #ifndef EFFECTS_H
00022 #define EFFECTS_H 1
00023 
00024 #include <string>
00025 
00026 #include "tqueue.h"
00027 #include "tiles.h"
00028 #include "singles.h"
00029 
00030 class Xform_palette;
00031 class PathFinder;
00032 class Game_object;
00033 class Game_window;
00034 class Image_window8;
00035 class Shape_frame;
00036 class Actor;
00037 class Special_effect;
00038 class Text_effect;
00039 
00040 /*
00041  *  Manage special effects.
00042  */
00043 class Effects_manager
00044   {
00045   Game_window *gwin;    // Handy pointer.
00046   Special_effect *effects;  // Sprite effects, projectiles, etc.
00047   Text_effect *texts;   // Text snippets.
00048 public:
00049   Effects_manager(Game_window *g) : gwin(g), effects(0), texts(0)
00050     {  }
00051   ~Effects_manager();
00052           // Add text item.
00053   void add_text(const char *msg, Game_object *item);
00054   void add_text(const char *msg, int x, int y);
00055   void center_text(const char *msg);
00056   void add_effect(Special_effect *effect);
00057   void add_text_effect(Text_effect *txt);
00058   void remove_text_effect(Game_object *item);
00059           // Remove text item & delete it.
00060   void remove_effect(Special_effect *effect);
00061   void remove_text_effect(Text_effect *txt);
00062   void remove_all_effects(bool repaint=false);
00063   void remove_text_effects();
00064           // Remove just the weather.
00065   void remove_weather_effects(int dist = 0);
00066   int get_weather();    // Get # of last weather added.
00067   void paint();     // Draw all sprites/proj./weather.
00068   void paint_text();    // Draw text.
00069   };
00070 
00071 /*
00072  *  Base class for special-effects:
00073  */
00074 class Special_effect : public Time_sensitive, public Game_singletons
00075   {
00076   Special_effect *next, *prev;  // All of them are chained together.
00077 public:
00078   friend class Effects_manager;
00079   Special_effect() : next(0), prev(0)
00080     {  }
00081   virtual ~Special_effect()
00082     {  }
00083           // Render.
00084   virtual void paint();
00085   virtual int is_weather()  // Need to distinguish weather.
00086     { return 0; }
00087   };
00088 
00089 /*
00090  *  An animation from 'sprites.vga':
00091  */
00092 class Sprites_effect : public Special_effect
00093   {
00094 protected:
00095   ShapeID sprite;
00096   //int sprite_num;   // Which one.
00097   //int frame_num;    // Current frame.
00098   int frames;     // # frames.
00099   Game_object *item;    // Follows this around if not null.
00100   Tile_coord pos;     // Position within world.
00101   int xoff, yoff;     // Offset from position in pixels.
00102   int deltax, deltay;   // Add to xoff, yoff on each frame.
00103   void add_dirty(int frnum);
00104 public:
00105   Sprites_effect(int num, Tile_coord p, int dx = 0, int dy = 0, 
00106               int delay = 0);
00107   Sprites_effect(int num, Game_object *it, 
00108           int xf, int yf, int dx, int dy);
00109           // For Time_sensitive:
00110   virtual void handle_event(unsigned long time, long udata);
00111           // Render.
00112   virtual void paint();
00113   };
00114 
00115 /*
00116  *  An explosion.
00117  */
00118 class Explosion_effect : public Sprites_effect
00119   {
00120   Game_object *explode;   // What's exploding, or 0.
00121   int weapon;     // Weapon to use for attack values.
00122 public:
00123   Explosion_effect(Tile_coord p, Game_object *exp, int delay = 0,
00124             int weap = -1);
00125   virtual void handle_event(unsigned long time, long udata);
00126   };
00127 
00128 /*
00129  *  A moving animation, followed by an 'attack' at the end, to
00130  *  implement Usecode intrinsic 0x41:
00131  */
00132 class Projectile_effect : public Special_effect
00133   {
00134   Actor *attacker;    // Source of attack/spell.
00135   Game_object *target;    // Target of path.
00136   int projectile_shape;   // Shape # of projectile/spell.
00137   ShapeID sprite;     // Sprite shape to display.
00138   int weapon;     // Shape # of firing weapon, or 0.
00139   int frames;     // # frames.
00140   PathFinder *path;   // Determines path.
00141   Tile_coord pos;     // Current position.
00142   bool return_path;   // Returning a boomerang.
00143   bool no_blocking;   // Don't get blocked by things.
00144           // Add dirty rectangle.
00145   void add_dirty();
00146   void init(Tile_coord s, Tile_coord t);
00147 public:
00148   Projectile_effect(Actor *att, Game_object *to, int shnum,
00149                 int weap = 0);
00150           // For missile traps:
00151   Projectile_effect(Tile_coord s, Tile_coord d, int shnum, int weap);
00152   Projectile_effect(Tile_coord s, Game_object *to, int shnum, int weap,
00153               bool retpath = false);
00154   ~Projectile_effect();
00155           // For Time_sensitive:
00156   virtual void handle_event(unsigned long time, long udata);
00157           // Render.
00158   virtual void paint();
00159   };
00160 
00161 /*
00162  *  'Death Vortex', from the spell.  (Maybe this could be a
00163  *  Sprites_effect.)
00164  */
00165 class Death_vortex : public Special_effect
00166   {
00167   ShapeID vortex;
00168   Actor *target;      // We'll follow this around if not 0.
00169   Tile_coord pos;     // Current position.
00170   int frames;     // # frames.
00171   uint32 stop_time;   // Time in 1/1000 secs. to stop.
00172   uint32 next_damage_time;  // When to check for NPC's beneath us.
00173   int add_dirty();
00174 public:
00175   Death_vortex(Game_object *trg, Tile_coord tp);
00176           // For Time_sensitive:
00177   virtual void handle_event(unsigned long time, long udata);
00178           // Render.
00179   virtual void paint();
00180   };
00181 
00182 /*
00183  *  A text object is a message that stays on the screen for just a couple
00184  *  of seconds.  These are all kept in a single list, and managed by
00185  *  Game_window.
00186  */
00187 class Text_effect : public Time_sensitive, public Game_singletons
00188   {
00189   Text_effect *next, *prev; // All of them are chained together.
00190   std::string msg;    // What to print.
00191   Game_object *item;    // Item text is on.  May be null.
00192   Tile_coord pos;     // Position to display it at.
00193   short width, height;    // Dimensions of rectangle.
00194   int num_ticks;      // # ticks passed.
00195   void add_dirty();
00196   void init();
00197 public:
00198   friend class Effects_manager;
00199   Text_effect(const std::string &m, Game_object *it);
00200   Text_effect(const std::string &m, int t_x, int t_y);
00201           // At timeout, remove from screen.
00202   virtual void handle_event(unsigned long curtime, long udata);
00203           // Render.
00204   virtual void paint();
00205           // Check for matching item.
00206   int is_text(Game_object *it)
00207     { return it == item; }
00208   };
00209 
00210 /*
00211  *  Weather.
00212  */
00213 class Weather_effect : public Special_effect
00214   {
00215 protected:
00216   uint32 stop_time;   // Time in 1/1000 secs. to stop.
00217   int num;      // Weather ID (0-6), or -1.
00218   Tile_coord eggloc;    // Location of egg that started this.
00219 public:
00220   Weather_effect(int duration, int delay, int n, Game_object *egg = 0);
00221   virtual ~Weather_effect()
00222     {  }
00223           // Avatar out of range?
00224   int out_of_range(Tile_coord& avpos, int dist);
00225   virtual int is_weather()
00226     { return 1; }
00227   int get_num() { return num; }
00228   };
00229 
00230 /*
00231  *  A raindrop:
00232  */
00233 class Raindrop
00234   {
00235   unsigned char oldpix;   // Pixel originally on screen.
00236   unsigned char yperx;    // Move this many y-pixels for each x.
00237   long ax, ay;      // Coords. where drawn in abs. pixels.
00238 public:
00239   Raindrop() : oldpix(0xff), yperx(1), ax(-1), ay(-1)
00240     {  }
00241   void paint(Image_window8 *iwin, int scrolltx, int scrollty,
00242             Xform_palette& xform);
00243           // Move to next position.
00244   void next(Image_window8 *iwin, int scrolltx, int scrollty,
00245           Xform_palette& xform, int w, int h);
00246   void next_random(Image_window8 *iwin, int scrolltx, int scrollty,
00247           Xform_palette& xform, int w, int h);
00248   };  
00249 
00250 /*
00251  *  Raining.
00252  */
00253 class Rain_effect : public Weather_effect
00254   {
00255 protected:
00256 #define MAXDROPS 200
00257   Raindrop drops[MAXDROPS]; // Drops moving down the screen.
00258   int num_drops;      // # to actually use.
00259 public:
00260   Rain_effect(int duration, int delay = 0, 
00261     int ndrops = MAXDROPS, int n = -1, Game_object *egg = 0)
00262     : Weather_effect(duration, delay, n, egg),
00263       num_drops(ndrops)
00264     {  }
00265           // Execute when due.
00266   virtual void handle_event(unsigned long curtime, long udata);
00267           // Render.
00268   virtual void paint();
00269   };
00270 
00271 /*
00272  *  Lightning.
00273  */
00274 class Lightning_effect : public Weather_effect
00275   {
00276   static int active;    // Just want one at a time.
00277   bool flashing;      // Lightning palette is set.
00278   friend class Storm_effect;
00279 public:
00280   Lightning_effect(int duration, int delay = 0) 
00281     : Weather_effect(duration, delay, -1), flashing(false)
00282     { }
00283   ~Lightning_effect();
00284           // Execute when due.
00285   virtual void handle_event(unsigned long curtime, long udata);
00286   };
00287 
00288 /*
00289  *  Storm.
00290  */
00291 class Storm_effect : public Weather_effect
00292   {
00293   int start;      // 1 to start storm.
00294 public:
00295   Storm_effect(int duration, int delay = 0, Game_object *egg = 0);
00296           // Execute when due.
00297   virtual void handle_event(unsigned long curtime, long udata);
00298   virtual ~Storm_effect();
00299   };
00300 
00301 /*
00302  *  Ambrosia's 'twinkling rain'.
00303  */
00304 class Sparkle_effect : public Rain_effect
00305   {
00306 public:
00307   Sparkle_effect(int duration, int delay = 0, Game_object *egg = 0) 
00308           // Weather #3.
00309     : Rain_effect(duration, delay, 50, 3, egg)
00310     {  }
00311           // Execute when due.
00312   virtual void handle_event(unsigned long curtime, long udata);
00313   };
00314 
00315 /*
00316  *  A single cloud (sprite shape 2):
00317  */
00318 class Cloud
00319   {
00320   ShapeID cloud;
00321   long wx, wy;      // Position within world.
00322   short deltax, deltay;   // How to move.
00323   int count;      // Counts down to 0.
00324   int max_count;
00325   uint32 start_time;  // When to start.
00326   static int randcnt;   // For generating random times.
00327   void set_start_pos(Shape_frame *shape, int w, int h, int& x, int& y);
00328 public:
00329   Cloud(short dx, short dy);
00330           // Move to next position & paint.
00331   void next(Game_window *gwin, unsigned long curtime, int w, int h);
00332   void paint();
00333   };
00334 
00335 /*
00336  *  Clouds.
00337  */
00338 class Clouds_effect : public Weather_effect
00339   {
00340   int num_clouds;
00341   Cloud **clouds;     // ->clouds.
00342 public:
00343   Clouds_effect(int duration, int delay = 0, Game_object *egg = 0);
00344           // Execute when due.
00345   virtual void handle_event(unsigned long curtime, long udata);
00346           // Render.
00347   virtual void paint();
00348   virtual ~Clouds_effect()
00349     { delete [] clouds; }
00350   };
00351 
00352 /*
00353  *  Earthquakes.  +++++Might make this a Weather_effect.
00354  */
00355 class Earthquake : public Time_sensitive
00356   {
00357   int len;      // From Usecode intrinsic.
00358   int i;        // Current index.
00359 public:
00360   Earthquake(int l) : len(l), i(0)
00361     {
00362     }
00363           // Execute when due.
00364   virtual void handle_event(unsigned long curtime, long udata);
00365   };
00366 
00367 /*
00368  *  A fire field that dies out after a few seconds.
00369  */
00370 class Fire_field_effect : public Special_effect
00371   {
00372   Game_object *field;   // What we create.
00373 public:
00374   Fire_field_effect(Tile_coord t);
00375   virtual void handle_event(unsigned long curtime, long udata);
00376   };
00377 
00378 #endif
00379 

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