--- deliantra/server/include/map.h 2006/12/31 18:10:40 1.45 +++ deliantra/server/include/map.h 2007/01/15 00:40:49 1.52 @@ -1,6 +1,7 @@ /* CrossFire, A Multiplayer game for X-windows + Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team Copyright (C) 2002-2005 Mark Wedel & Crossfire Development Team Copyright (C) 1992 Frank Tore Johansen @@ -56,10 +57,12 @@ #define MAP_OVERLAY 0x10 /* Values for in_memory below. Should probably be an enumerations */ -#define MAP_IN_MEMORY 1 -#define MAP_SWAPPED 2 -#define MAP_LOADING 3 -#define MAP_SAVING 4 +enum { + MAP_IN_MEMORY, + MAP_SWAPPED, + MAP_LOADING, + MAP_SAVING, +}; /* GET_MAP_FLAGS really shouldn't be used very often - get_map_flags should * really be used, as it is multi tile aware. However, there are some cases @@ -287,6 +290,9 @@ MTH void set_darkness_map (); MTH int estimate_difficulty () const; + // set the given flag on all objects in the map + MTH void set_object_flag (int flag, int value = 1); + MTH void link_multipart_objects (); MTH void clear_unique_items (); @@ -294,20 +300,20 @@ MTH void clear_links_to (maptile *m); // loas the header pseudo-object - bool load_header (object_thawer &thawer); - MTH bool load_header (const char *path); + bool _load_header (object_thawer &thawer); + MTH bool _load_header (const char *path); // load objects into the map - bool load_objects (object_thawer &thawer); - MTH bool load_objects (const char *path, bool skip_header = true); + bool _load_objects (object_thawer &thawer); + MTH bool _load_objects (const char *path, bool skip_header = true); // save objects into the given file (uses IO_ flags) - bool save_objects (object_freezer &freezer, int flags); - MTH bool save_objects (const char *path, int flags); + bool _save_objects (object_freezer &freezer, int flags); + MTH bool _save_objects (const char *path, int flags); // save the header pseudo object _only_ - bool save_header (object_freezer &freezer); - MTH bool save_header (const char *path); + bool _save_header (object_freezer &freezer); + MTH bool _save_header (const char *path); maptile (); maptile (int w, int h); @@ -320,29 +326,31 @@ MTH object *insert (object *op, int x, int y, object *originator = 0, int flags = 0); -// static maptile *find_map (const char *path, maptile *origin);//PERL -// -// // load a map relative to this one -// maptile *find_map (const char *path) -// { -// return find_map (path, this); -// } -// -// // customise this map for the given player -// // might return this or a completely new map -// maptile *customise_for (object *op); -// -// void do_force_map_sync ();//PERL -// -// // make sure the map is loaded -// MTH void force_map_sync () -// { -// if (in_memory != MAP_IN_MEMORY) -// do_force_map_sync (); -// } + MTH void touch () { last_access = runtime; } - static maptile *load_map_sync (const char *path, maptile *original = 0);//PERL - static void emergency_save ();//PERL + // find the map that is at coordinate x|y relative to this map + // TODO: need a better way than passing by reference + // TODO: make perl interface + maptile *xy_find (sint16 &x, sint16 &y); + + // like xy_find, but also loads the map + maptile *xy_load (sint16 &x, sint16 &y); + + void do_load_sync ();//PERL + + // make sure the map is loaded + MTH void load_sync () + { + if (!spaces) + do_load_sync (); + } + + void make_map_floor (char **layout, char *floorstyle, random_map_params *RP); + bool generate_random_map (random_map_params *RP); + + static maptile *find_sync (const char *path, maptile *original = 0);//PERL + // async prefetch + static maptile *find_async (const char *path, maptile *original = 0);//PERL mapspace const &at (uint32 x, uint32 y) const { return spaces [x * height + y]; } mapspace &at (uint32 x, uint32 y) { return spaces [x * height + y]; } @@ -366,6 +374,26 @@ object *part; }; +//TODO: these should be refactored into things like xy_normalise +// and so on. +int get_map_flags(maptile *oldmap, maptile **newmap, sint16 x, sint16 y, sint16 *nx, sint16 *ny); +int ob_blocked(const object *ob, maptile *m, sint16 x, sint16 y); +int out_of_map(maptile *m, int x, int y); +maptile *get_map_from_coord(maptile *m, sint16 *x, sint16 *y); +void get_rangevector(object *op1, object *op2, rv_vector *retval, int flags); +void get_rangevector_from_mapcoord(const maptile *m, int x, int y, const object *op2, rv_vector *retval, int flags); +int on_same_map(const object *op1, const object *op2); + +// adjust map, x and y for tiled maps and return true if the position is valid at all +inline bool +xy_normalise (maptile *&map, sint16 &x, sint16 &y) +{ + // when in range, do a quick return, otherwise go the slow route + return + (IN_RANGE_EXC (x, 0, map->width) && IN_RANGE_EXC (y, 0, map->height)) + || !(get_map_flags (map, &map, x, y, &x, &y) & P_OUT_OF_MAP); +} + inline mapspace & object::ms () const {