--- deliantra/server/common/map.C 2010/04/13 02:39:52 1.186 +++ deliantra/server/common/map.C 2011/05/07 10:50:35 1.208 @@ -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 * @@ -79,7 +79,7 @@ */ if (OUT_OF_REAL_MAP (m, sx, sy)) { - LOG (llevError, "blocked_link: Passed map, x, y coordinates outside of map\n"); + LOG (llevError | logBacktrace, "blocked_link: Passed map, x, y coordinates outside of map\n"); return 1; } @@ -92,7 +92,7 @@ * go further. Not true for players - all sorts of special * things we need to do for players. */ - if (ob->type != PLAYER && !(mflags & P_IS_ALIVE) && (blocked == 0)) + if (ob->type != PLAYER && !(mflags & P_IS_ALIVE) && blocked == 0) return 0; /* if there isn't anything alive on this space, and this space isn't @@ -112,7 +112,7 @@ * true. If we get through the entire stack, that must mean * ob is blocking it, so return 0. */ - for (object *tmp = ms.bot; tmp; tmp = tmp->above) + for (object *tmp = ms.top; tmp; tmp = tmp->below) { if (OB_MOVE_BLOCK (ob, tmp)) { @@ -146,12 +146,11 @@ } else { // space does not block the ob, directly, but // anything alive that is not a door still - // blocks anything but wizards. + // blocks anything if (tmp->flag [FLAG_ALIVE] - && tmp->head_ () != ob - && tmp != ob - && tmp->type != DOOR) + && tmp->type != DOOR + && tmp->head_ () != ob) //TODO: maybe move these check up? return 1; } } @@ -160,7 +159,7 @@ } /* - * Returns qthe blocking object if the given object can't fit in the given + * Returns the blocking object if the given object can't fit in the given * spot. This is meant for multi space objects - for single space objecs, * just calling get_map_blocked and checking that against movement type * of object. This function goes through all the parts of the multipart @@ -314,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)) { @@ -361,19 +363,29 @@ 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; + + activate_physics (); } 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 @@ -424,30 +436,35 @@ return freezer.save (path); } -maptile::maptile () +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. */ - width = 16; - height = 16; - timeout = 300; - max_items = MAX_ITEM_PER_ACTION; - max_volume = 2000000; // 2m³ + width = 16; + height = 16; + timeout = 300; + max_items = MAX_ITEM_PER_ACTION; + max_volume = 2000000; // 2m³ + reset_timeout = 0; + enter_x = 0; + enter_y = 0; +} + +maptile::maptile () +{ + init (); } maptile::maptile (int w, int h) { - in_memory = MAP_SWAPPED; + init (); - width = w; - height = h; - reset_timeout = 0; - timeout = 300; - enter_x = 0; - enter_y = 0; + width = w; + height = h; alloc (); } @@ -557,20 +574,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 ("*"); } @@ -603,7 +626,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; @@ -636,7 +659,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.get_str ()); break; + case KW_region: thawer.get (default_region); break; case KW_shopitems: shopitems = parse_shop_string (thawer.get_str ()); break; // old names new names @@ -654,6 +677,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); @@ -664,7 +689,7 @@ return true; default: - if (!thawer.parse_error ("map", 0)) + if (!thawer.parse_error ("map")) return false; break; } @@ -746,6 +771,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)); @@ -812,7 +839,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; } @@ -829,7 +856,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; } @@ -1182,9 +1209,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]; } @@ -1306,7 +1335,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; @@ -1318,65 +1347,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; @@ -1427,11 +1456,11 @@ if (!adjacent_map (op1->map, op2->map, &retval->distance_x, &retval->distance_y)) { /* be conservative and fill in _some_ data */ - retval->distance = 10000; + retval->distance = 10000; retval->distance_x = 10000; retval->distance_y = 10000; - retval->direction = 0; - retval->part = 0; + retval->direction = 0; + retval->part = 0; } else { @@ -1443,7 +1472,7 @@ /* If this is multipart, find the closest part now */ if (!(flags & 1) && op1->more) { - int best_distance = retval->distance_x * retval->distance_x + retval->distance_y * retval->distance_y, tmpi; + int best_distance = idistance (retval->distance_x, retval->distance_y); /* we just take the offset of the piece to head to figure * distance instead of doing all that work above again @@ -1453,12 +1482,12 @@ */ for (object *tmp = op1->more; tmp; tmp = tmp->more) { - tmpi = (op1->x - tmp->x + retval->distance_x) * (op1->x - tmp->x + retval->distance_x) + - (op1->y - tmp->y + retval->distance_y) * (op1->y - tmp->y + retval->distance_y); + int tmpi = idistance (op1->x - tmp->x + retval->distance_x, op1->y - tmp->y + retval->distance_y); + if (tmpi < best_distance) { best_distance = tmpi; - best = tmp; + best = tmp; } } @@ -1469,9 +1498,9 @@ } } - retval->part = best; - retval->distance = upos_max (abs (retval->distance_x), abs (retval->distance_y)); - retval->direction = find_dir_2 (-retval->distance_x, -retval->distance_y); + retval->part = best; + retval->distance = upos_max (abs (retval->distance_x), abs (retval->distance_y)); + retval->direction = find_dir_2 (retval->distance_x, retval->distance_y); } } @@ -1486,25 +1515,25 @@ * 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)) { /* be conservative and fill in _some_ data */ - retval->distance = 100000; + retval->distance = 100000; retval->distance_x = 32767; retval->distance_y = 32767; - retval->direction = 0; - retval->part = 0; + retval->direction = 0; + retval->part = 0; } else { retval->distance_x += op2->x - x; retval->distance_y += op2->y - y; - retval->part = 0; - retval->distance = upos_max (abs (retval->distance_x), abs (retval->distance_y)); - retval->direction = find_dir_2 (-retval->distance_x, -retval->distance_y); + retval->part = 0; + retval->distance = upos_max (abs (retval->distance_x), abs (retval->distance_y)); + retval->direction = find_dir_2 (retval->distance_x, retval->distance_y); } } @@ -1618,7 +1647,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 @@ -1630,7 +1659,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 @@ -1642,7 +1671,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 @@ -1654,7 +1683,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