shapeid.h

Go to the documentation of this file.
00001 /*
00002  *  Copyright (C) 2000-2003  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 SHAPEID_H
00020 #define SHAPEID_H 1
00021 
00022 #include "exult_constants.h"
00023 #include "shapevga.h"
00024 #include "singles.h"
00025 
00026 class Shape_frame;
00027 class Shape_info;
00028 class Fonts_vga_file;
00029 class Font;
00030 class Image_buffer8;
00031 
00032 enum ShapeFile {
00033   SF_SHAPES_VGA = 0,  // <STATIC>/shapes.vga.  MUST be first.
00034   SF_GUMPS_VGA,   // <STATIC>/gumps.vga
00035   SF_PAPERDOL_VGA,  // <STATIC>/paperdol.vga
00036   SF_SPRITES_VGA,   // <STATIC>/sprites.vga
00037   SF_FACES_VGA,   // <STATIC>/faces.vga
00038   SF_EXULT_FLX,   // <DATA>/exult.flx
00039   SF_GAME_FLX,    // <DATA>/bg_data.flx or <DATA>/si_data.flx
00040   SF_BG_SIGUMP_FLX, // BG only for Paperdolls
00041   SF_BG_SISHAPES_VGA, // BG only for Multiracial
00042   // Not yet
00043   //SF_FONTS_VGA,   // <STATIC>/fonts.vga
00044 
00045   SF_OTHER,   // Other unknown FLX
00046   SF_COUNT    // # of preceding entries.
00047 };
00048 
00049           // Special pixels.
00050 enum Pixel_colors {POISON_PIXEL = 0, PROTECT_PIXEL, CURSED_PIXEL, HIT_PIXEL,
00051       NPIXCOLORS};
00052 
00053 /*
00054  *  Manage the set of shape files.
00055  */
00056 class Shape_manager : public Game_singletons
00057   {
00058   static Shape_manager *instance; // There shall be only one.
00059   Shapes_vga_file shapes;   // Main 'shapes.vga' file.
00060   Vga_file files[(int) SF_COUNT]; // The files we manage.
00061   Fonts_vga_file *fonts;    // "fonts.vga" file.
00062   Xform_palette xforms[11]; // Transforms translucent colors
00063           //   0xf4 through 0xfe.
00064   Xform_palette *invis_xform; // For showing invisible NPC's.
00065   unsigned char special_pixels[NPIXCOLORS]; // Special colors.
00066   bool bg_paperdolls_allowed; // Set true if the SI paperdoll file 
00067           //   is found when playing BG
00068   bool bg_paperdolls;   // True if paperdolls are wanted in BG
00069   bool bg_multiracial_allowed;  // Set true if the SI shapes file 
00070           //   is found when playing BG
00071 public:
00072   friend class ShapeID;
00073   Shape_manager();
00074   ~Shape_manager();
00075   static Shape_manager *get_instance()
00076     { return instance; }
00077   void load();      // Read in files.
00078   void reload_shapes(int dragtype); // Reload a shape file.
00079   Vga_file& get_file(enum ShapeFile f)
00080     { return files[(int) f]; };
00081   Shapes_vga_file& get_shapes()
00082     { return shapes; }
00083   inline Xform_palette& get_xform(int i)
00084     { return xforms[i]; }
00085   // BG Only
00086   inline bool can_use_paperdolls() const
00087   { return bg_paperdolls_allowed; }
00088 
00089   inline bool get_bg_paperdolls() const
00090   { return bg_paperdolls; }
00091 
00092   inline void set_bg_paperdolls(bool p)
00093   { bg_paperdolls = p; }
00094 
00095   inline bool can_use_multiracial() const
00096   { return bg_multiracial_allowed; }
00097 
00098           // Paint shape in window.
00099   void paint_shape(int xoff, int yoff, Shape_frame *shape,
00100             int translucent = 0)
00101     {
00102     if (!shape || !shape->data)
00103       CERR("NULL SHAPE!!!");
00104     else if (!shape->rle)
00105       shape->paint(xoff, yoff);
00106     else if (!translucent)
00107       shape->paint_rle(xoff, yoff);
00108     else
00109       shape->paint_rle_translucent(xoff, yoff, xforms, 
00110           sizeof(xforms)/sizeof(xforms[0]));
00111     }
00112 
00113   inline void paint_invisible(int xoff, int yoff, Shape_frame *shape)
00114     {
00115     if (shape) shape->paint_rle_transformed(
00116             xoff, yoff, *invis_xform);
00117     }
00118           // Paint outline around a shape.
00119   inline void paint_outline(int xoff, int yoff, Shape_frame *shape, 
00120               Pixel_colors pix)
00121     {
00122     if (shape) shape->paint_rle_outline(
00123           xoff, yoff, special_pixels[(int) pix]);
00124     }
00125   unsigned char get_special_pixel(Pixel_colors pix)
00126     { return special_pixels[(int) pix]; }
00127 
00128           // Paint text using "fonts.vga".
00129   int paint_text_box(int fontnum, const char *text, int x, int y, int w, 
00130     int h, int vert_lead = 0, int pbreak = 0, int shading = -1);
00131   int paint_text(int fontnum, const char *text, int xoff, int yoff);
00132   int paint_text(int fontnum, const char *text, int textlen, 
00133               int xoff, int yoff);
00134           // Get text width.
00135   int get_text_width(int fontnum, const char *text);
00136   int get_text_width(int fontnum, const char *text, int textlen);
00137           // Get text height, baseline.
00138   int get_text_height(int fontnum);
00139   int get_text_baseline(int fontnum);
00140   Font *get_font(int fontnum);
00141   };
00142 
00143 /*
00144  *  A shape ID contains a shape # and a frame # within the shape encoded
00145  *  as a 2-byte quantity.
00146  */
00147 class ShapeID : public Game_singletons
00148   {
00149   short shapenum;     // Shape #.
00150   signed char framenum;   // Frame # within shape.
00151   char has_trans;
00152   ShapeFile shapefile;
00153   Shape_frame *shape;
00154 
00155   Shape_frame* cache_shape();
00156 
00157 public:
00158           // Create from map data.
00159   ShapeID(unsigned char l, unsigned char h) 
00160     : shapenum(l + 256*(h&0x3)), framenum(h >> 2), has_trans(0),
00161       shapefile(SF_SHAPES_VGA), shape(0)
00162     {  }
00163           // Read from buffer & incr. ptr.
00164   ShapeID(unsigned char *& data)
00165     : has_trans(0), shapefile(SF_SHAPES_VGA), shape(0)
00166     {
00167     unsigned char l = *data++;
00168     unsigned char h = *data++;
00169     shapenum = l + 256*(h&0x3);
00170     framenum = h >> 2;
00171     }
00172           // Create "end-of-list"/invalid entry.
00173   ShapeID() : shapenum(-1), framenum(-1), has_trans(0), shapefile(SF_SHAPES_VGA), shape(0)
00174     {  }
00175 
00176     virtual ~ShapeID()
00177         {  }
00178           // End-of-list or invalid?
00179   int is_invalid() const
00180     { return shapenum == -1; }
00181   int is_eol() const
00182     { return is_invalid(); }
00183 
00184   inline int get_shapenum() const
00185     { return shapenum; }
00186   inline int get_framenum() const
00187     { return framenum; }
00188   inline ShapeFile get_shapefile() const
00189     { return shapefile; }
00190   inline Shape_frame *get_shape()
00191     { return (shape!=0)?shape:cache_shape(); }
00192   inline void set_translucent(int trans)
00193     { has_trans=trans; }
00194   inline bool is_translucent()
00195     { if (shape==0) cache_shape(); return has_trans!=0; }
00196           // Set to given shape.
00197   void set_shape(int shnum, int frnum)
00198     {
00199     shapenum = shnum;
00200     framenum = frnum;
00201     shape = 0;
00202     }
00203   ShapeID(int shnum, int frnum, ShapeFile shfile = SF_SHAPES_VGA) :
00204     shapenum(shnum), framenum(frnum), shapefile(shfile),
00205     shape(0), has_trans(0)
00206     {  }
00207 
00208   void set_shape(int shnum) // Set shape, but keep old frame #.
00209     { shapenum = shnum; shape = 0; }
00210   void set_frame(int frnum) // Set to new frame.
00211     { framenum = frnum; shape = 0; }
00212   void set_file(ShapeFile shfile) // Set to new flex
00213     { shapefile = shfile; shape = 0; }
00214 
00215   void paint_shape(int xoff, int yoff, bool force_trans = false)
00216     {
00217     sman->paint_shape(xoff, yoff, get_shape(), 
00218             has_trans || force_trans);
00219     }
00220   void paint_invisible(int xoff, int yoff)
00221     { sman->paint_invisible(xoff, yoff, get_shape()); }
00222           // Paint outline around a shape.
00223   inline void paint_outline(int xoff, int yoff, Pixel_colors pix)
00224     { sman->paint_outline(xoff, yoff, get_shape(), pix); }
00225   int get_num_frames() const;
00226   Shape_info& get_info() const  // Get info. about shape.
00227     { return Shape_manager::instance->shapes.get_info(shapenum); }
00228   static Shape_info& get_info(int shnum)  // Get info. about shape.
00229     { return Shape_manager::instance->shapes.get_info(shnum); }
00230   };
00231 
00232 /*
00233  *  An interface used in Get_click():
00234  */
00235 class Paintable
00236   {
00237 public:
00238   virtual void paint() = 0;
00239   };
00240 
00241 #endif

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