--- deliantra/server/common/map.C 2009/11/07 18:30:05 1.169 +++ deliantra/server/common/map.C 2009/11/11 23:27:56 1.177 @@ -219,33 +219,6 @@ return 0; } -/* When the map is loaded, load_object does not actually insert objects - * into inventory, but just links them. What this does is go through - * and insert them properly. - * The object 'container' is the object that contains the inventory. - * This is needed so that we can update the containers weight. - */ -static void -fix_container (object *container) -{ - object *tmp = container->inv, *next; - - container->inv = 0; - while (tmp) - { - next = tmp->below; - if (tmp->inv) - fix_container (tmp); - - insert_ob_in_ob (tmp, container); - tmp = next; - } - - // go through and calculate what all the containers are carrying. - //TODO: remove - container->update_weight (); -} - //-GPL void @@ -272,6 +245,19 @@ INVOKE_OBJECT (RESET, tmp); } +void +maptile::post_load () +{ +#if 0 + if (!spaces) + return; + + for (mapspace *ms = spaces + size (); ms-- > spaces; ) + for (object *tmp = ms->bot; tmp; tmp = tmp->above) + ; // nop +#endif +} + //+GPL /* link_multipart_objects go through all the objects on the map looking @@ -450,7 +436,7 @@ width = 16; height = 16; timeout = 300; - max_nrof = 1000; // 1000 items of anything + max_items = MAX_ITEM_PER_ACTION; max_volume = 2000000; // 2m³ } @@ -730,10 +716,10 @@ bool maptile::_save_header (object_freezer &freezer) { -#define MAP_OUT(k) freezer.put (KW_ ## k, k) -#define MAP_OUT2(k,v) freezer.put (KW_ ## k, v) +#define MAP_OUT(k) freezer.put (KW(k), k) +#define MAP_OUT2(k,v) freezer.put (KW(k), v) - MAP_OUT2 (arch, "map"); + MAP_OUT2 (arch, CS(map)); if (name) MAP_OUT (name); MAP_OUT (swap_time); @@ -757,8 +743,8 @@ MAP_OUT (enter_x); MAP_OUT (enter_y); - if (msg) freezer.put (KW_msg , KW_endmsg , msg); - if (maplore) freezer.put (KW_maplore, KW_endmaplore, maplore); + if (msg) freezer.put (KW(msg) , KW(endmsg) , msg); + if (maplore) freezer.put (KW(maplore), KW(endmaplore), maplore); MAP_OUT (outdoor); MAP_OUT (temp); @@ -777,7 +763,7 @@ if (tile_path [3]) MAP_OUT2 (tile_path_4, tile_path [3]); freezer.put (this); - freezer.put (KW_end); + freezer.put (KW(end)); return true; } @@ -1029,9 +1015,13 @@ mapspace::update_ () { object *last = 0; - uint8 flags = P_UPTODATE, anywhere = 0; + uint8 flags = P_UPTODATE; sint8 light = 0; MoveType move_block = 0, move_slow = 0, move_on = 0, move_off = 0, move_allow = 0; + uint64_t volume = 0; + uint32_t items = 0; + object *anywhere = 0; + uint8_t middle_visibility = 0; //object *middle = 0; //object *top = 0; @@ -1041,6 +1031,8 @@ object *&middle = faces_obj[1] = 0; object *&floor = faces_obj[2] = 0; + object::flags_t allflags; // all flags of all objects or'ed together + for (object *tmp = bot; tmp; last = tmp, tmp = tmp->above) { // Lights are additive, up to MAX_LIGHT_RADIUS, see los.C) @@ -1054,11 +1046,11 @@ * * Always put the player down for drawing. */ - if (!tmp->invisible) + if (expect_true (!tmp->invisible)) { - if ((tmp->type == PLAYER || QUERY_FLAG (tmp, FLAG_MONSTER))) + if (expect_false (tmp->type == PLAYER || tmp->flag [FLAG_MONSTER])) top = tmp; - else if (QUERY_FLAG (tmp, FLAG_IS_FLOOR)) + else if (expect_false (tmp->flag [FLAG_IS_FLOOR])) { /* If we got a floor, that means middle and top were below it, * so should not be visible, so we clear them. @@ -1066,26 +1058,31 @@ middle = 0; top = 0; floor = tmp; + volume = 0; + items = 0; } - /* Flag anywhere have high priority */ - else if (QUERY_FLAG (tmp, FLAG_SEE_ANYWHERE)) + else { - middle = tmp; - anywhere = 1; - } - - /* Find the highest visible face around. If equal - * visibilities, we still want the one nearer to the - * top - */ - else if (!middle || (::faces [tmp->face].visibility > ::faces [middle->face].visibility && !anywhere)) - middle = tmp; - } + if (expect_true (!tmp->flag [FLAG_NO_PICK])) + { + ++items; + volume += tmp->volume (); + } - if (tmp == tmp->above) - { - LOG (llevError, "Error in structure of map\n"); - exit (-1); + /* Flag anywhere have high priority */ + if (expect_false (tmp->flag [FLAG_SEE_ANYWHERE])) + anywhere = tmp; + + /* Find the highest visible face around. If equal + * visibilities, we still want the one nearer to the + * top + */ + if (expect_false (::faces [tmp->face].visibility >= middle_visibility)) + { + middle_visibility = ::faces [tmp->face].visibility; + middle = tmp; + } + } } move_slow |= tmp->move_slow; @@ -1094,20 +1091,30 @@ move_off |= tmp->move_off; move_allow |= tmp->move_allow; - if (QUERY_FLAG (tmp, FLAG_BLOCKSVIEW)) flags |= P_BLOCKSVIEW; - if (QUERY_FLAG (tmp, FLAG_NO_MAGIC)) flags |= P_NO_MAGIC; - if (tmp->type == PLAYER) flags |= P_PLAYER; - if (tmp->type == SAFE_GROUND) flags |= P_SAFE; - if (QUERY_FLAG (tmp, FLAG_ALIVE)) flags |= P_IS_ALIVE; - if (QUERY_FLAG (tmp, FLAG_DAMNED)) flags |= P_NO_CLERIC; + allflags |= tmp->flag; + + if (tmp->type == PLAYER) flags |= P_PLAYER; + if (tmp->type == SAFE_GROUND) flags |= P_SAFE; } + // FLAG_SEE_ANYWHERE takes precedence + if (anywhere) + middle = anywhere; + + // ORing all flags together and checking them here is much faster + if (allflags [FLAG_BLOCKSVIEW]) flags |= P_BLOCKSVIEW; + if (allflags [FLAG_NO_MAGIC] ) flags |= P_NO_MAGIC; + if (allflags [FLAG_ALIVE] ) flags |= P_IS_ALIVE; + if (allflags [FLAG_DAMNED] ) flags |= P_NO_CLERIC; + this->light = min (light, MAX_LIGHT_RADIUS); this->flags_ = flags; this->move_block = move_block & ~move_allow; this->move_on = move_on; this->move_off = move_off; this->move_slow = move_slow; + this->volume_ = (volume + 1023) / 1024; + this->items_ = upos_min (items, 65535); // assume nrof <= 2**31 /* At this point, we have a floor face (if there is a floor), * and the floor is set - we are not going to touch it at @@ -1183,17 +1190,6 @@ #endif } -uint64 -mapspace::volume () const -{ - uint64 vol = 0; - - for (object *op = top; op && !op->flag [FLAG_NO_PICK]; op = op->below) - vol += op->volume (); - - return vol; -} - maptile * maptile::tile_available (int dir, bool load) {