find_nearby.h

Go to the documentation of this file.
00001 /*
00002  *  find_nearby.h - Header for defining static Game_object::find_nearby()
00003  *
00004  *  Copyright (C) 2001-2002 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 FN_VECTOR
00022 #error(Can't Include find_nearby.h if FN_VECTOR is not #define'd)
00023 #endif
00024 
00025 #ifndef FN_OBJECT
00026 #error(Can't Include find_nearby.h if FN_OBJECT is not #define'd)
00027 #endif
00028 
00029 #ifndef FN_CAST
00030 #error(Can't Include find_nearby.h if FN_CAST is not #define'd)
00031 #endif
00032 
00033 int Game_object::find_nearby
00034   (
00035   FN_VECTOR& vec,     // Objects appended to this.
00036   Tile_coord pos,     // Look near this point.
00037   int shapenum,     // Shape to look for.  
00038           //   -1=any (but always use mask?),
00039           //   c_any_shapenum=any.
00040   int delta,      // # tiles to look in each direction.
00041   int mask,     // See Check_mask() above.
00042   int qual,     // Quality, or c_any_qual for any.
00043   int framenum      // Frame #, or c_any_framenum for any.
00044   )
00045   {
00046   if (delta < 0)      // +++++Until we check all old callers.
00047     delta = 24;
00048   if (shapenum > 0 && mask == 4)  // Ignore mask=4 if shape given!
00049     mask = 0;
00050   int vecsize = vec.size();
00051   Game_window *gwin = Game_window::get_instance();
00052   Game_map *gmap = gwin->get_map();
00053   Rectangle tiles(pos.tx - delta, pos.ty - delta, 1 + 2*delta, 1 + 
00054                 2*delta);
00055           // Stay within world.
00056   Rectangle world(0, 0, c_num_chunks*c_tiles_per_chunk, 
00057           c_num_chunks*c_tiles_per_chunk);
00058   tiles = tiles.intersect(world);
00059           // Figure range of chunks.
00060   int start_cx = tiles.x/c_tiles_per_chunk,
00061       end_cx = (tiles.x + tiles.w - 1)/c_tiles_per_chunk;
00062   int start_cy = tiles.y/c_tiles_per_chunk,
00063       end_cy = (tiles.y + tiles.h - 1)/c_tiles_per_chunk;
00064           // Go through all covered chunks.
00065   for (int cy = start_cy; cy <= end_cy; cy++)
00066     for (int cx = start_cx; cx <= end_cx; cx++)
00067       {   // Go through objects.
00068       Map_chunk *chunk = gmap->get_chunk(cx, cy);
00069       Object_iterator next(chunk->get_objects());
00070       Game_object *obj;
00071       while ((obj = next.get_next()) != 0)
00072         { // Check shape.
00073         if (shapenum >= 0)
00074           {
00075           if (obj->get_shapenum() != shapenum)
00076             continue;
00077           }
00078         if (qual != c_any_qual && obj->get_quality() 
00079                 != qual)
00080           continue;
00081         if (framenum !=  c_any_framenum &&
00082           obj->get_framenum() != framenum)
00083           continue;
00084         if (!Check_mask(gwin, obj, mask))
00085           continue;
00086         Tile_coord t = obj->get_tile();
00087         if (tiles.has_point(t.tx, t.ty)) {
00088           FN_OBJECT* castobj = obj FN_CAST;
00089           if (castobj) vec.push_back(castobj);
00090         }
00091         }
00092       }
00093           // Return # added.
00094   return (vec.size() - vecsize);
00095   }
00096 
00097 #undef FN_VECTOR
00098 #undef FN_OBJECT
00099 #undef FN_CAST

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