--- deliantra/server/include/map.h 2007/07/01 05:00:18 1.78 +++ deliantra/server/include/map.h 2007/09/30 20:22:18 1.89 @@ -31,6 +31,7 @@ #include +#include "region.h" #include "cfperl.h" /* We set this size - this is to make magic map work properly on @@ -104,11 +105,6 @@ #define P_NEW_MAP 0x20000 /* Coordinates passed result in a new tiled map */ -/* P_NO_PASS is used for ob_blocked() return value. It needs - * to be here to make sure the bits don't match with anything. - */ -#define P_NO_PASS 0x80000 - /* Instead of having numerous arrays that have information on a * particular space (was map, floor, floor2, map_ob), * have this structure take care of that information. @@ -155,6 +151,11 @@ // return the item volume on this mapspace in cm³ uint64 volume () const; + + bool blocks (MoveType mt) const + { + return move_block && (mt & move_block) == mt; + } }; struct shopitems : zero_initialised @@ -188,12 +189,12 @@ sint32 ACC (RW, width), ACC (RW, height); /* Width and height of map. */ struct mapspace *spaces; /* Array of spaces on this map */ uint8 *regions; /* region index per mapspace, if != 0 */ - struct region **regionmap; /* index to region */ + region_ptr *regionmap; /* index to region */ tstamp ACC (RW, last_access); /* last time this map was accessed somehow */ shstr ACC (RW, name); /* Name of map as given by its creator */ - struct region *ACC (RW, default_region); /* What jurisdiction in the game world this map is ruled by + region_ptr ACC (RW, default_region); /* What jurisdiction in the game world this map is ruled by * points to the struct containing all the properties of * the region */ double ACC (RW, reset_time); @@ -213,7 +214,6 @@ sint16 players; /* How many players are on this map right now */ uint16 ACC (RW, difficulty); /* What level the player should be to play here */ - bool ACC (RW, active); // wether this map is active or not bool ACC (RW, per_player); bool ACC (RW, per_party); bool ACC (RW, outdoor); /* True if an outdoor map */ @@ -259,6 +259,8 @@ MTH void set_darkness_map (); MTH int estimate_difficulty () const; + MTH void play_sound (faceidx sound, int x, int y) const; + // set the given flag on all objects in the map MTH void set_object_flag (int flag, int value = 1); @@ -270,13 +272,13 @@ MTH struct region *region (int x, int y) const; - // loas the header pseudo-object + // load the header pseudo-object bool _load_header (object_thawer &thawer); - MTH bool _load_header (const char *path); + MTH bool _load_header (object_thawer *thawer) { return _load_header (*thawer); } // load objects into the map bool _load_objects (object_thawer &thawer); - MTH bool _load_objects (const char *path, bool skip_header = true); + MTH bool _load_objects (object_thawer *thawer) { return _load_objects (*thawer); } // save objects into the given file (uses IO_ flags) bool _save_objects (object_freezer &freezer, int flags); @@ -299,6 +301,8 @@ MTH void touch () { last_access = runtime; } + MTH bool tile_available (int dir, bool load = true); + // 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 @@ -319,7 +323,7 @@ void make_map_floor (char **layout, char *floorstyle, random_map_params *RP); bool generate_random_map (random_map_params *RP); - static maptile *find_async (const char *path, maptile *original = 0);//PERL + static maptile *find_async (const char *path, maptile *original = 0, bool load = true);//PERL static maptile *find_sync (const char *path, maptile *original = 0);//PERL static maptile *find_style_sync (const char *dir, const char *file = 0);//PERL MTH object *pick_random_object () const; @@ -346,10 +350,10 @@ object *part; }; +// comaptibility cruft start //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); @@ -358,7 +362,7 @@ int adjacent_map (const maptile *map1, const maptile *map2, int *dx, int *dy); // adjust map, x and y for tiled maps and return true if the position is valid at all -inline bool +static inline bool xy_normalise (maptile *&map, sint16 &x, sint16 &y) { // when in range, do a quick return, otherwise go the slow route @@ -366,6 +370,7 @@ (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); } +// comaptibility cruft end inline mapspace & object::ms () const @@ -373,5 +378,64 @@ return map->at (x, y); } +struct mapxy { + maptile *m; + sint16 x, y; + + mapxy (maptile *m, sint16 x, sint16 y) + : m(m), x(x), y(y) + { } + + mapxy (object *op) + : m(op->map), x(op->x), y(op->y) + { } + + mapxy &move (int dx, int dy) + { + x += dx; + y += dy; + + return *this; + } + + mapxy &move (int dir) + { + return move (freearr_x [dir], freearr_y [dir]); + } + + operator void *() const { return (void *)m; } + mapxy &operator =(const object *op) + { + m = op->map; + x = op->x; + y = op->y; + + return *this; + } + + mapspace *operator ->() const { return &m->at (x, y); } + mapspace &operator * () const { return m->at (x, y); } + + bool normalise () + { + return xy_normalise (m, x, y); + } + + object *insert (object *op, object *originator = 0, int flags = 0) const + { + m->insert (op, x, y, originator, flags); + } +}; + +inline const mapxy & +object::operator =(const mapxy &pos) +{ + map = pos.m; + x = pos.x; + y = pos.y; + + return pos; +} + #endif