shapeid.cc

Go to the documentation of this file.
00001 /*
00002  *  Copyright (C) 2000-2004  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 #ifdef HAVE_CONFIG_H
00020 #  include <config.h>
00021 #endif
00022 
00023 #include "gamewin.h"
00024 #include "shapeid.h"
00025 #include "vgafile.h"
00026 #include "fontvga.h"
00027 #include "fnames.h"
00028 #include "game.h"
00029 #include "Configuration.h"
00030 #include "utils.h"
00031 #include "segfile.h"
00032 #include "u7drag.h"
00033 #include "U7file.h"
00034 
00035 using std::cerr;
00036 using std::cout;
00037 using std::endl;
00038 using std::string;
00039 
00040 Shape_manager *Shape_manager::instance = 0;
00041 
00042 /*
00043  *  Singletons:
00044  */
00045 Game_window *Game_singletons::gwin = 0;
00046 Game_map *Game_singletons::gmap = 0;
00047 Effects_manager *Game_singletons::eman = 0;
00048 Shape_manager *Game_singletons::sman = 0;
00049 Usecode_machine *Game_singletons::ucmachine = 0;
00050 Game_clock *Game_singletons::gclock = 0;
00051 Palette *Game_singletons::pal = 0;
00052 Gump_manager *Game_singletons::gumpman = 0;
00053 Party_manager *Game_singletons::partyman = 0;
00054 void Game_singletons::init
00055   (
00056   Game_window *g
00057   )
00058   {
00059   gwin = g;
00060   gmap = g->get_map();
00061   eman = g->get_effects();
00062   sman = Shape_manager::get_instance();
00063   ucmachine = g->get_usecode();
00064   gclock = g->get_clock();
00065   pal = g->get_pal();
00066   gumpman = g->get_gump_man();
00067   partyman = g->get_party_man();
00068   }
00069 
00070 /*
00071  *  Create shape manager.
00072  */
00073 Shape_manager::Shape_manager
00074   (
00075   ) : bg_paperdolls_allowed(false), bg_multiracial_allowed(false),
00076       bg_paperdolls(false), fonts(0)
00077   {
00078   assert(instance == 0);
00079   instance = this;
00080   std::string str;
00081   config->value("config/gameplay/bg_paperdolls", str, "yes");
00082   if (str == "yes")
00083     bg_paperdolls = true;
00084   config->set("config/gameplay/bg_paperdolls", str, true);
00085   }
00086 
00087 /*
00088  *  Load files.
00089  */
00090 
00091 void Shape_manager::load
00092   (
00093   )
00094   {
00095   // Determine some colors based on the default palette
00096   Palette pal;
00097   pal.load(PALETTES_FLX, 0);  // could throw!
00098           // Get a bright green.
00099   special_pixels[POISON_PIXEL] = pal.find_color(4, 63, 4);
00100           // Get a light gray.
00101   special_pixels[PROTECT_PIXEL] = pal.find_color(62, 62, 55);
00102           // Yellow for cursed.
00103   special_pixels[CURSED_PIXEL] = pal.find_color(62, 62, 5);
00104           // Red for hit in battle.
00105   special_pixels[HIT_PIXEL] = pal.find_color(63, 4, 4);
00106   // What about charmed/cursed/paralyzed?
00107 
00108   shapes.init();
00109   shapes.read_info(GAME_BG);  // Read in shape dimensions.
00110   files[SF_GUMPS_VGA].load(GUMPS_VGA, PATCH_GUMPS);
00111 
00112   if (Game::get_game_type()==SERPENT_ISLE)
00113     {
00114     files[SF_PAPERDOL_VGA].load(PAPERDOL, PATCH_PAPERDOL);
00115     if (!files[SF_PAPERDOL_VGA].is_good())
00116       gwin->abort("Can't open 'paperdol.vga' file.");
00117     }
00118   else
00119     {
00120     try
00121       {
00122       files[SF_PAPERDOL_VGA].load(
00123           "<SERPENTISLE_STATIC>/paperdol.vga");
00124       files[SF_BG_SIGUMP_FLX].load(
00125           "<SERPENTISLE_STATIC>/gumps.vga");
00126       files[SF_BG_SISHAPES_VGA].load(
00127           "<SERPENTISLE_STATIC>/shapes.vga");
00128 
00129       if (files[SF_PAPERDOL_VGA].is_good() && 
00130           files[SF_BG_SIGUMP_FLX].is_good() && 
00131           files[SF_BG_SISHAPES_VGA].is_good())
00132         {
00133           std::cout << "Support for SI Paperdolls and Multiracial Avatars in BG is enabled." << std::endl;
00134         bg_paperdolls_allowed = true;
00135         bg_multiracial_allowed = true;
00136         }
00137       else
00138         std::cout << "Bad SI 'paperdol.vga', 'gumps.vga' or 'shapes.vga'." << std::endl
00139               << "Support for SI Paperdolls and Multiracial Avatars in BG is disabled." << std::endl;
00140       }
00141     catch (const exult_exception &e)  
00142       {
00143         std::cerr << "Couldn't open SI 'paperdol.vga', 'gumps.vga' or 'shapes.vga'." << std::endl
00144               << "Support for SI Paperdolls and Multiracial Avatars in BG is disabled." << std::endl;
00145       }
00146 
00147     }
00148   files[SF_SPRITES_VGA].load(SPRITES_VGA, PATCH_SPRITES);
00149   files[SF_FACES_VGA].load(FACES_VGA, PATCH_FACES);
00150   files[SF_EXULT_FLX].load("<DATA>/exult.flx");
00151   const char* gamedata = game->get_resource("files/gameflx").str;
00152   std::cout << "Loading " << gamedata << "..." << std::endl;
00153   files[SF_GAME_FLX].load(gamedata);
00154   if (!fonts)
00155     {
00156     fonts = new Fonts_vga_file();
00157     fonts->init();
00158     }
00159           // Get translucency tables.
00160   std::size_t len, nxforms = sizeof(xforms)/sizeof(xforms[0]);
00161           // RGBA blend colors:
00162   static unsigned char blends[4*11] = {
00163       144,40,192,128, 96,40,16,128, 100,108,116,192, 
00164       68,132,28,128, 255,208,48,64, 28,52,255,128,
00165       8,68,0,128, 255,8,8,118, 255,244,248,128, 
00166       56,40,32,128, 228,224,214,82};
00167   for (int i = 0; i < nxforms; i++)
00168     xforms[i].set_color(blends[4*i], blends[4*i+1],
00169           blends[4*i+2], blends[4*i+3]);
00170   if (U7exists(XFORMTBL))
00171     {     // Read in translucency tables.
00172     Segment_file xf(XFORMTBL);
00173     for (int i = 0; i < nxforms; i++)
00174       {
00175       uint8 *data = (uint8*)xf.retrieve(i, len);
00176       std::memcpy(xforms[nxforms - 1 - i].colors, data,
00177             sizeof(xforms[0].colors));
00178       delete[] data;
00179       }
00180     }
00181   else        // Create algorithmically.
00182     {
00183     gwin->get_pal()->load(PALETTES_FLX, 0);
00184     for (int i = 0; i < nxforms; i++)
00185       {
00186       gwin->get_pal()->create_trans_table(xforms[i].r/4,
00187         xforms[i].g/4, xforms[i].b/4,
00188         xforms[i].a, xforms[i].colors);
00189       }
00190     }
00191 
00192   invis_xform = &xforms[nxforms - 1 - 0];   // ->entry 0.
00193   }
00194 
00195 /*
00196  *  Reload one of the shape files (msg. from ExultStudio).
00197  */
00198 
00199 void Shape_manager::reload_shapes
00200   (
00201   int dragtype      // Type from u7drag.h.
00202   )
00203   {
00204   U7FileManager::get_ptr()->reset();  // Cache no longer valid.
00205   switch (dragtype)
00206     {
00207   case U7_SHAPE_SHAPES:
00208     shapes.init();    // Reread .vga file.
00209     shapes.read_info(GAME_BG);  //+++++Needs work.
00210           // ++++Reread text?
00211     break;
00212   case U7_SHAPE_GUMPS:
00213     files[SF_GUMPS_VGA].load(GUMPS_VGA, PATCH_GUMPS);
00214     break;
00215   case U7_SHAPE_FONTS:
00216     fonts->init();
00217     break;
00218   case U7_SHAPE_FACES:
00219     files[SF_FACES_VGA].load(FACES_VGA, PATCH_FACES);
00220     break;
00221   case U7_SHAPE_SPRITES:
00222     files[SF_SPRITES_VGA].load(SPRITES_VGA, PATCH_SPRITES);
00223     break;
00224   case U7_SHAPE_PAPERDOL:
00225     files[SF_PAPERDOL_VGA].load(PAPERDOL, PATCH_PAPERDOL);
00226     break;
00227   default:
00228     cerr << "Type not supported:  " << dragtype << endl;
00229     break;
00230     }
00231   }
00232 
00233 /*
00234  *  Clean up.
00235  */
00236 Shape_manager::~Shape_manager()
00237   {
00238   delete fonts;
00239   assert(this == instance);
00240   instance = 0;
00241   }
00242 
00243 /*
00244  *  Text-drawing methods:
00245  */
00246 int Shape_manager::paint_text_box(int fontnum, const char *text, 
00247     int x, int y, int w, int h, int vert_lead, int pbreak, 
00248                 int shading)
00249   {
00250   if(shading>=0)
00251     gwin->get_win()->fill_translucent8(
00252         0, w, h, x, y, xforms[shading]);
00253   return fonts->paint_text_box(gwin->get_win()->get_ib8(),
00254       fontnum, text, x, y, w, h, vert_lead, pbreak); 
00255   }
00256 int Shape_manager::paint_text(int fontnum, const char *text, 
00257               int xoff, int yoff)
00258   {
00259   return fonts->paint_text(gwin->get_win()->get_ib8(), fontnum, text,
00260               xoff, yoff); 
00261   }
00262 int Shape_manager::paint_text(int fontnum, const char *text, int textlen, 
00263               int xoff, int yoff)
00264   {
00265   return fonts->paint_text(gwin->get_win()->get_ib8(), fontnum, 
00266             text, textlen, xoff, yoff);
00267   }
00268 
00269 int Shape_manager::get_text_width(int fontnum, const char *text)
00270   { return fonts->get_text_width(fontnum, text); }
00271 int Shape_manager::get_text_width(int fontnum, const char *text, int textlen)
00272   { return fonts->get_text_width(fontnum, text, textlen); }
00273 int Shape_manager::get_text_height(int fontnum)
00274   { return fonts->get_text_height(fontnum); }
00275 int Shape_manager::get_text_baseline(int fontnum)
00276   { return fonts->get_text_baseline(fontnum); }
00277 
00278 Font *Shape_manager::get_font(int fontnum)
00279   { return fonts->get_font(fontnum); }
00280 
00281 
00282 /*
00283  *  Read in shape.
00284  */
00285 Shape_frame *ShapeID::cache_shape()
00286 {
00287   if (framenum == -1) return 0;
00288 
00289   if (has_trans != 2) has_trans = 0;
00290   if (!shapefile)
00291     {     // Special case.
00292     shape = sman->shapes.get_shape(shapenum, framenum);
00293     if (has_trans != 2) 
00294       has_trans = 
00295           sman->shapes.get_info(shapenum).has_translucency();
00296     }
00297   else if (shapefile < SF_OTHER)
00298     {
00299     shape = sman->files[(int) shapefile].get_shape(
00300               shapenum, framenum);
00301     if (shapefile == SF_SPRITES_VGA)
00302       has_trans = 1;
00303     }
00304   else
00305     {
00306     std::cerr << "Error! Wrong ShapeFile!" << std::endl;
00307     return 0;
00308     } 
00309   return shape;
00310 
00311 }
00312 
00313 int ShapeID::get_num_frames() const
00314 {
00315   if (!shapefile)
00316     return sman->shapes.get_num_frames(shapenum);
00317   else if (shapefile < SF_OTHER)
00318     {
00319     if (!sman->files[(int) shapefile].is_good())
00320       return 0;
00321     return sman->files[(int) shapefile].get_num_frames(shapenum);
00322     }
00323   std::cerr << "Error! Wrong ShapeFile!" << std::endl;
00324   return 0;
00325 }
00326 
00327 
00328 

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