00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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,
00036 Tile_coord pos,
00037 int shapenum,
00038
00039
00040 int delta,
00041 int mask,
00042 int qual,
00043 int framenum
00044 )
00045 {
00046 if (delta < 0)
00047 delta = 24;
00048 if (shapenum > 0 && mask == 4)
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
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
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
00065 for (int cy = start_cy; cy <= end_cy; cy++)
00066 for (int cx = start_cx; cx <= end_cx; cx++)
00067 {
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 {
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
00094 return (vec.size() - vecsize);
00095 }
00096
00097 #undef FN_VECTOR
00098 #undef FN_OBJECT
00099 #undef FN_CAST