Jawbone_gump.cc

Go to the documentation of this file.
00001 /*
00002 Copyright (C) 2001 The Exult Team
00003 
00004 This program is free software; you can redistribute it and/or
00005 modify it under the terms of the GNU General Public License
00006 as published by the Free Software Foundation; either version 2
00007 of the License, or (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 "game.h"
00024 #include "Jawbone_gump.h"
00025 #include "contain.h"
00026 #include "gamewin.h"
00027 #include "objiter.h"
00028 #include "misc_buttons.h"
00029 #include "jawbone.h"
00030 
00031 const int toothx[19] = { 34, 32, 31, 31, 28, 31, 27, 31, 40, 50,
00032              57, 63, 72, 70, 75, 82, 83, 87, 0 };
00033 
00034 const int toothy[19] = { 19, 30, 37, 44, 52, 57, 66, 77, 82, 84,
00035              80, 71, 69, 61, 50, 42, 36, 32, 0 };
00036 
00037 Jawbone_gump::Jawbone_gump
00038   (
00039   Jawbone_object *cont, // Jawbone it represents.
00040   int initx, int inity    // Coords. on screen.
00041   ) : Gump(cont, initx, inity, game->get_shape("gumps/jawbone")),
00042     jawbone(cont)
00043 {
00044   set_object_area(Rectangle(0, 0, 138, 116), 10, 109);
00045 }
00046 
00047 
00048 int Jawbone_gump::add(Game_object *obj, int mx, int my, int sx, int sy,
00049             bool dont_check, bool combine)
00050 {
00051   // Jawbone_object handles all the checks required
00052   return jawbone->add(obj, dont_check, combine);
00053 }
00054 
00055 void Jawbone_gump::paint()
00056 {
00057   // Paint gump itself
00058   paint_shape(x, y);
00059 
00060   // Paint red "checkmark".
00061   check_button->paint();
00062 
00063   jawbone->find_teeth();
00064 
00065   int i;  // Blame MSVC
00066   for (i=0; i<9; i++)
00067     if (jawbone->teeth[i])
00068       paint_tooth(i);
00069   for (i=17; i>8; i--)
00070     if (jawbone->teeth[i])
00071       paint_tooth(i);
00072 }
00073 
00074 void Jawbone_gump::paint_tooth(int index)
00075 {
00076   ShapeID shape(game->get_shape("gumps/tooth"), index, SF_GUMPS_VGA);
00077 
00078   int objx = toothx[index];
00079   int objy = toothy[index];
00080 
00081   shape.paint_shape(x + objx, y + objy);
00082 }
00083 
00084 Game_object *Jawbone_gump::find_object(int mx, int my)
00085 {
00086   jawbone->find_teeth();
00087 
00088   // get position relative to gump
00089   mx -= x;
00090   my -= y;
00091 
00092   int i;  // Blame MSVC
00093 
00094   // reverse of drawing order
00095   for (i=9; i<18; i++)
00096     if (jawbone->teeth[i] && on_tooth(mx, my, i)) {
00097       // set correct position (otherwise tooth won't be on mouse cursor)
00098       set_to_spot(jawbone->teeth[i], mx, my);
00099       return jawbone->teeth[i];
00100     }
00101   for (i=8; i>=0; i--)
00102     if (jawbone->teeth[i] && on_tooth(mx, my, i)) {
00103       // set correct position (otherwise tooth won't be on mouse cursor)
00104       set_to_spot(jawbone->teeth[i], mx, my);
00105       return jawbone->teeth[i];
00106     }
00107 
00108   return 0;
00109 }
00110 
00111 bool Jawbone_gump::on_tooth(int sx, int sy, int index)
00112 {
00113   ShapeID sid(game->get_shape("gumps/tooth"), index, SF_GUMPS_VGA);
00114   Shape_frame *shape = sid.get_shape();
00115 
00116   int objx = toothx[index];
00117   int objy = toothy[index];
00118   
00119   Rectangle r = gwin->get_shape_rect (shape, 0, 0);
00120   
00121   if (r.has_point (sx - objx, sy - objy) && 
00122       shape->has_point (sx - objx, sy - objy))
00123     return true;
00124 
00125   return false;
00126 }
00127 
00128 void Jawbone_gump::set_to_spot(Game_object *obj, int sx, int sy)
00129 {
00130   if (obj->get_shapenum() != 559)  // not a serpent tooth?
00131     return;
00132 
00133   int fr = obj->get_framenum();
00134   
00135   // Get shape.
00136   Shape_frame *shape = obj->get_shape();
00137   
00138   // Height and width
00139   int w = shape->get_width(), h = shape->get_height();
00140   
00141   // Set object's position.
00142   obj->set_chunk(sx + shape->get_xleft() - w/2,
00143     sy + shape->get_yabove() - h/2);
00144 }
00145 

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