--- deliantra/server/common/map.C 2010/04/18 05:54:18 1.189 +++ deliantra/server/common/map.C 2011/05/07 11:49:08 1.209 @@ -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 @@ -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,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 @@ -426,7 +439,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 +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 ("*"); } @@ -607,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; @@ -640,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 @@ -658,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); @@ -750,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)); @@ -816,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; } @@ -833,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; } @@ -1174,6 +1197,32 @@ if (top == middle) middle = 0; + // dire hack to handle "transparent" floors - currently only open_space + if (floor && floor->arch->archname == shstr_quad_open_space + && !middle) + { + floor->set_anim_frame (0); + + if (maptile *m = floor->map->tile_map [TILE_DOWN]) + { + // mirror the floor - very unreliable because usually outdated, + // but somewhta works because floors do not change often :/ + middle = floor; + + mapspace &ms = m->at (floor->x, floor->y); + + ms.update (); + + if (object *floor2 = ms.faces_obj [2]) + if (floor2->arch->archname != shstr_quad_open_space) + { + floor->set_anim_frame (1); + middle = floor; + floor = floor2; + } + } + } + #if 0 faces_obj [0] = top; faces_obj [1] = middle; @@ -1186,9 +1235,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 +1361,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 +1373,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; @@ -1431,11 +1482,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 { @@ -1447,7 +1498,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 @@ -1457,12 +1508,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; } } @@ -1473,9 +1524,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); } } @@ -1490,25 +1541,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); } } @@ -1622,7 +1673,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 +1685,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 +1697,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 +1709,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