--- deliantra/server/common/map.C 2010/04/25 10:45:38 1.196 +++ deliantra/server/common/map.C 2011/05/05 18:59:43 1.207 @@ -1,7 +1,7 @@ /* * This file is part of Deliantra, the Roguelike Realtime MMORPG. * - * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team + * Copyright (©) 2005,2006,2007,2008,2009,2010,2011 Marc Alexander Lehmann / Robin Redeker / the Deliantra team * Copyright (©) 2001-2003 Mark Wedel & Crossfire Development Team * Copyright (©) 1992 Frank Tore Johansen * @@ -313,7 +313,10 @@ { // TODO: why? if (op->inv) - op->update_weight (); + { + op->carrying = 0; + op->update_weight (); + } if (IN_RANGE_EXC (op->x, 0, width) && IN_RANGE_EXC (op->y, 0, height)) { @@ -360,19 +363,27 @@ void maptile::activate () { - if (spaces) - for (mapspace *ms = spaces + size (); ms-- > spaces; ) - for (object *op = ms->bot; op; op = op->above) - op->activate_recursive (); + if (state != MAP_INACTIVE) + return; + + for (mapspace *ms = spaces + size (); ms-- > spaces; ) + for (object *op = ms->bot; op; op = op->above) + op->activate_recursive (); + + state = MAP_ACTIVE; } void maptile::deactivate () { - if (spaces) - for (mapspace *ms = spaces + size (); ms-- > spaces; ) - for (object *op = ms->bot; op; op = op->above) - op->deactivate_recursive (); + if (state != MAP_ACTIVE) + return; + + for (mapspace *ms = spaces + size (); ms-- > spaces; ) + for (object *op = ms->bot; op; op = op->above) + op->deactivate_recursive (); + + state = MAP_INACTIVE; } bool @@ -426,7 +437,7 @@ void maptile::init () { - in_memory = MAP_SWAPPED; + state = MAP_SWAPPED; /* The maps used to pick up default x and y values from the * map archetype. Mimic that behaviour. @@ -561,20 +572,26 @@ print_shop_string (maptile *m) { static dynbuf_text buf; buf.clear (); + bool first = true; for (int i = 0; i < m->shopitems[0].index; i++) { + if (!first) + buf << ';'; + + first = false; + if (m->shopitems[i].typenum) { if (m->shopitems[i].strength) - buf.printf ("%s:%d;", m->shopitems[i].name, m->shopitems[i].strength); + buf.printf ("%s:%d", m->shopitems[i].name, m->shopitems[i].strength); else - buf.printf ("%s;", m->shopitems[i].name); + buf.printf ("%s", m->shopitems[i].name); } else { if (m->shopitems[i].strength) - buf.printf ("*:%d;", m->shopitems[i].strength); + buf.printf ("*:%d", m->shopitems[i].strength); else buf.printf ("*"); } @@ -607,7 +624,7 @@ thawer.get_ml (KW_endmsg, msg); break; - case KW_lore: // CF+ extension + case KW_lore: // deliantra extension thawer.get_ml (KW_endlore, maplore); break; @@ -640,7 +657,7 @@ case KW_no_reset: thawer.get (no_reset); break; case KW_no_drop: thawer.get (no_drop); break; - case KW_region: default_region = region::find (thawer); break; + case KW_region: thawer.get (default_region); break; case KW_shopitems: shopitems = parse_shop_string (thawer.get_str ()); break; // old names new names @@ -658,6 +675,8 @@ case KW_tile_path_2: thawer.get (tile_path [1]); break; case KW_tile_path_3: thawer.get (tile_path [2]); break; case KW_tile_path_4: thawer.get (tile_path [3]); break; + case KW_tile_path_5: thawer.get (tile_path [4]); break; + case KW_tile_path_6: thawer.get (tile_path [5]); break; case KW_ERROR: set_key_text (thawer.kw_str, thawer.value); @@ -750,6 +769,8 @@ if (tile_path [1]) MAP_OUT2 (tile_path_2, tile_path [1]); if (tile_path [2]) MAP_OUT2 (tile_path_3, tile_path [2]); if (tile_path [3]) MAP_OUT2 (tile_path_4, tile_path [3]); + if (tile_path [4]) MAP_OUT2 (tile_path_5, tile_path [4]); + if (tile_path [5]) MAP_OUT2 (tile_path_6, tile_path [5]); freezer.put (this); freezer.put (KW(end)); @@ -816,7 +837,7 @@ shoprace = 0; delete [] shopitems, shopitems = 0; - for (int i = 0; i < 4; i++) + for (int i = 0; i < array_length (tile_path); i++) tile_path [i] = 0; } @@ -833,7 +854,7 @@ * tiling can be asymetric, we just can not look to see which * maps this map tiles with and clears those. */ - for (int i = 0; i < 4; i++) + for (int i = 0; i < array_length (tile_path); i++) if (tile_map[i] == m) tile_map[i] = 0; } @@ -1186,9 +1207,11 @@ { if (tile_path[dir]) { - if (tile_map[dir] && (!load || tile_map[dir]->in_memory == MAP_ACTIVE)) + // map is there and we don't need to load it OR it's loaded => return what we have + if (tile_map[dir] && (!load || tile_map[dir]->linkable ())) return tile_map[dir]; + // well, try to locate it then, if possible - maybe it's there already if ((tile_map[dir] = find_async (tile_path[dir], this, load))) return tile_map[dir]; } @@ -1310,7 +1333,7 @@ * map1 to map2 in dx/dy. */ int -adjacent_map (const maptile *map1, const maptile *map2, int *dx, int *dy) +adjacent_map (maptile *map1, maptile *map2, int *dx, int *dy) { if (!map1 || !map2) return 0; @@ -1322,65 +1345,65 @@ *dx = 0; *dy = 0; } - else if (map1->tile_map[0] == map2) - { /* up */ + else if (map1->tile_available (TILE_NORTH, false) == map2) + { *dx = 0; *dy = -map2->height; } - else if (map1->tile_map[1] == map2) - { /* right */ + else if (map1->tile_available (TILE_EAST , false) == map2) + { *dx = map1->width; *dy = 0; } - else if (map1->tile_map[2] == map2) - { /* down */ + else if (map1->tile_available (TILE_SOUTH, false) == map2) + { *dx = 0; *dy = map1->height; } - else if (map1->tile_map[3] == map2) - { /* left */ + else if (map1->tile_available (TILE_WEST , false) == map2) + { *dx = -map2->width; *dy = 0; } - else if (map1->tile_map[0] && map1->tile_map[0]->tile_map[1] == map2) + else if (map1->tile_map[TILE_NORTH] && map1->tile_map[TILE_NORTH]->tile_available (TILE_EAST , false) == map2) { /* up right */ - *dx = map1->tile_map[0]->width; - *dy = -map1->tile_map[0]->height; + *dx = +map1->tile_map[TILE_NORTH]->width; + *dy = -map1->tile_map[TILE_NORTH]->height; } - else if (map1->tile_map[0] && map1->tile_map[0]->tile_map[3] == map2) + else if (map1->tile_map[TILE_NORTH] && map1->tile_map[TILE_NORTH]->tile_available (TILE_WEST , false) == map2) { /* up left */ *dx = -map2->width; - *dy = -map1->tile_map[0]->height; + *dy = -map1->tile_map[TILE_NORTH]->height; } - else if (map1->tile_map[1] && map1->tile_map[1]->tile_map[0] == map2) + else if (map1->tile_map[TILE_EAST ] && map1->tile_map[TILE_EAST ]->tile_available (TILE_NORTH, false) == map2) { /* right up */ - *dx = map1->width; + *dx = +map1->width; *dy = -map2->height; } - else if (map1->tile_map[1] && map1->tile_map[1]->tile_map[2] == map2) + else if (map1->tile_map[TILE_EAST ] && map1->tile_map[TILE_EAST ]->tile_available (TILE_SOUTH, false) == map2) { /* right down */ - *dx = map1->width; - *dy = map1->tile_map[1]->height; + *dx = +map1->width; + *dy = +map1->tile_map[TILE_EAST]->height; } - else if (map1->tile_map[2] && map1->tile_map[2]->tile_map[1] == map2) + else if (map1->tile_map[TILE_SOUTH] && map1->tile_map[TILE_SOUTH]->tile_available (TILE_EAST , false) == map2) { /* down right */ - *dx = map1->tile_map[2]->width; - *dy = map1->height; + *dx = +map1->tile_map[TILE_SOUTH]->width; + *dy = +map1->height; } - else if (map1->tile_map[2] && map1->tile_map[2]->tile_map[3] == map2) + else if (map1->tile_map[TILE_SOUTH] && map1->tile_map[TILE_SOUTH]->tile_available (TILE_WEST , false) == map2) { /* down left */ *dx = -map2->width; - *dy = map1->height; + *dy = +map1->height; } - else if (map1->tile_map[3] && map1->tile_map[3]->tile_map[0] == map2) + else if (map1->tile_map[TILE_WEST ] && map1->tile_map[TILE_WEST ]->tile_available (TILE_NORTH, false) == map2) { /* left up */ - *dx = -map1->tile_map[3]->width; + *dx = -map1->tile_map[TILE_WEST]->width; *dy = -map2->height; } - else if (map1->tile_map[3] && map1->tile_map[3]->tile_map[2] == map2) + else if (map1->tile_map[TILE_WEST ] && map1->tile_map[TILE_WEST ]->tile_available (TILE_SOUTH, false) == map2) { /* left down */ - *dx = -map1->tile_map[3]->width; - *dy = map1->tile_map[3]->height; + *dx = -map1->tile_map[TILE_WEST]->width; + *dy = +map1->tile_map[TILE_WEST]->height; } else return 0; @@ -1490,7 +1513,7 @@ * field of the rv_vector is set to NULL. */ void -get_rangevector_from_mapcoord (const maptile *m, int x, int y, const object *op2, rv_vector *retval, int flags) +get_rangevector_from_mapcoord (maptile *m, int x, int y, const object *op2, rv_vector *retval, int flags) { if (!adjacent_map (m, op2->map, &retval->distance_x, &retval->distance_y)) { @@ -1622,7 +1645,7 @@ // clip to map to the left if (x0 < 0) { - if (maptile *tile = m->tile_available (TILE_LEFT, 1)) + if (maptile *tile = m->tile_available (TILE_WEST, 1)) split_to_tiles (buf, tile, x0 + tile->width, y0, min (x1 + tile->width, tile->width), y1, dx - tile->width, dy); if (x1 < 0) // entirely to the left @@ -1634,7 +1657,7 @@ // clip to map to the right if (x1 > m->width) { - if (maptile *tile = m->tile_available (TILE_RIGHT, 1)) + if (maptile *tile = m->tile_available (TILE_EAST, 1)) split_to_tiles (buf, tile, max (x0 - m->width, 0), y0, x1 - m->width, y1, dx + m->width, dy); if (x0 > m->width) // entirely to the right @@ -1646,7 +1669,7 @@ // clip to map above if (y0 < 0) { - if (maptile *tile = m->tile_available (TILE_UP, 1)) + if (maptile *tile = m->tile_available (TILE_NORTH, 1)) split_to_tiles (buf, tile, x0, y0 + tile->height, x1, min (y1 + tile->height, tile->height), dx, dy - tile->height); if (y1 < 0) // entirely above @@ -1658,7 +1681,7 @@ // clip to map below if (y1 > m->height) { - if (maptile *tile = m->tile_available (TILE_DOWN, 1)) + if (maptile *tile = m->tile_available (TILE_SOUTH, 1)) split_to_tiles (buf, tile, x0, max (y0 - m->height, 0), x1, y1 - m->height, dx, dy + m->height); if (y0 > m->height) // entirely below