--- deliantra/server/include/map.h 2006/12/20 09:14:22 1.29 +++ deliantra/server/include/map.h 2006/12/21 01:33:49 1.31 @@ -44,7 +44,7 @@ #define MAGIC_MAP_SIZE 50 #define MAGIC_MAP_HALF MAGIC_MAP_SIZE/2 -#define MAP_LAYERS 4 +#define MAP_LAYERS 3 /* This is when the map will reset */ #define MAP_WHEN_RESET(m) ((m)->reset_time) @@ -101,26 +101,16 @@ * consistent (eg, op->map, op->x, op->y) */ // all those macros are herewith declared legacy -#define GET_MAP_FLAGS(M,X,Y) (M)->at((X),(Y)).flags -#define SET_MAP_FLAGS(M,X,Y,C) (M)->at((X),(Y)).flags = (C) +#define GET_MAP_FLAGS(M,X,Y) (M)->at((X),(Y)).flags () #define GET_MAP_LIGHT(M,X,Y) (M)->at((X),(Y)).light -#define SET_MAP_LIGHT(M,X,Y,L) (M)->at((X),(Y)).light = (L) #define GET_MAP_OB(M,X,Y) (M)->at((X),(Y)).bottom #define GET_MAP_TOP(M,X,Y) (M)->at((X),(Y)).top -#define SET_MAP_OB(M,X,Y,tmp) (M)->at((X),(Y)).bottom = (tmp) -#define SET_MAP_TOP(M,X,Y,tmp) (M)->at((X),(Y)).top = (tmp) -#define SET_MAP_FACE(M,X,Y,C,L) (M)->at((X),(Y)).faces[L] = (C) #define GET_MAP_FACE(M,X,Y,L) (M)->at((X),(Y)).faces[L] -#define SET_MAP_FACE_OBJ(M,X,Y,C,L) (M)->at((X),(Y)).faces_obj[L] = (C) #define GET_MAP_FACE_OBJ(M,X,Y,L) (M)->at((X),(Y)).faces_obj[L] #define GET_MAP_MOVE_BLOCK(M,X,Y) (M)->at((X),(Y)).move_block -#define SET_MAP_MOVE_BLOCK(M,X,Y,C) (M)->at((X),(Y)).move_block = (C) #define GET_MAP_MOVE_SLOW(M,X,Y) (M)->at((X),(Y)).move_slow -#define SET_MAP_MOVE_SLOW(M,X,Y,C) (M)->at((X),(Y)).move_slow = (C) #define GET_MAP_MOVE_ON(M,X,Y) (M)->at((X),(Y)).move_on -#define SET_MAP_MOVE_ON(M,X,Y,C) (M)->at((X),(Y)).move_on = (C) #define GET_MAP_MOVE_OFF(M,X,Y) (M)->at((X),(Y)).move_off -#define SET_MAP_MOVE_OFF(M,X,Y,C) (M)->at((X),(Y)).move_off = (C) /* You should really know what you are doing before using this - you * should almost always be using out_of_map instead, which takes into account @@ -141,10 +131,8 @@ * but is useful in other situations */ #define P_IS_ALIVE 0x10 /* something alive is on this space */ #define P_NO_CLERIC 0x20 /* no clerical spells cast here */ -#define P_NEED_UPDATE 0x40 /* this space is out of date */ -#define P_NO_ERROR 0x80 /* Purely temporary - if set, update_position - * does not complain if the flags are different. - */ + +#define P_NEED_UPDATE 0x80 /* this space is out of date */ /* The following two values are not stored in the MapLook flags, but instead * used in the get_map_flags value - that function is used to return @@ -172,13 +160,40 @@ object *bottom; /* lowest object on this space */ object *top; /* Highest object on this space */ New_Face *faces[MAP_LAYERS]; /* faces for the 3 layers */ - object *faces_obj[MAP_LAYERS]; /* face objects for the 3 layers */ - uint8 flags; /* flags about this space (see the P_ values above) */ + object *faces_obj[MAP_LAYERS];/* face objects for the 3 layers */ + uint8 flags_; /* flags about this space (see the P_ values above) */ sint8 light; /* How much light this space provides */ - uint8 move_block; /* What movement types this space blocks */ - uint8 move_slow; /* What movement types this space slows */ - uint8 move_on; /* What movement types are activated */ - uint8 move_off; /* What movement types are activated */ + MoveType move_block; /* What movement types this space blocks */ + MoveType move_slow; /* What movement types this space slows */ + MoveType move_on; /* What movement types are activated */ + MoveType move_off; /* What movement types are activated */ + + void update_ (); + void update () + { + if (flags_ & P_NEED_UPDATE) + update_ (); + } + + uint8 flags () + { + update (); + return flags_; + } + + // maybe only inline quick flags_ checking? + object *player () + { + // search from the top, because players are usually on top + // make usually == always and this non-amortized O(1) + // could gte rid of P_PLAYER, too, then + if (flags () & P_PLAYER) + for (object *op = top; op; op = op->below) + if (op->type == PLAYER) + return op; + + return 0; + } }; /* @@ -332,5 +347,11 @@ object *part; }; +inline mapspace & +object::ms () const +{ + return map->at (x, y); +} + #endif