--- deliantra/server/common/map.C 2010/02/07 04:22:33 1.182 +++ deliantra/server/common/map.C 2010/04/25 10:45:38 1.196 @@ -2,8 +2,8 @@ * 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 (©) 2001-2003,2007 Mark Wedel & Crossfire Development Team - * Copyright (©) 1992,2007 Frank Tore Johansen + * Copyright (©) 2001-2003 Mark Wedel & Crossfire Development Team + * Copyright (©) 1992 Frank Tore Johansen * * Deliantra is free software: you can redistribute it and/or modify it under * the terms of the Affero GNU General Public License as published by the @@ -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 @@ -424,30 +423,35 @@ return freezer.save (path); } -maptile::maptile () +void +maptile::init () { in_memory = 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 (); } @@ -636,7 +640,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: default_region = region::find (thawer); break; case KW_shopitems: shopitems = parse_shop_string (thawer.get_str ()); break; // old names new names @@ -664,7 +668,7 @@ return true; default: - if (!thawer.parse_error ("map", 0)) + if (!thawer.parse_error ("map")) return false; break; } @@ -692,10 +696,10 @@ { object *above = op->above; - if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE)) + if (op->flag [FLAG_IS_FLOOR] && op->flag [FLAG_UNIQUE]) unique = 1; - if (op->head_ () == op && (QUERY_FLAG (op, FLAG_UNIQUE) || unique)) + if (op->head_ () == op && (op->flag [FLAG_UNIQUE] || unique)) op->destroy (); op = above; @@ -856,16 +860,16 @@ above = op->above; // do not decay anything above unique floor tiles (yet :) - if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE)) + if (op->flag [FLAG_IS_FLOOR] && op->flag [FLAG_UNIQUE]) break; bool destroy = 0; - if (QUERY_FLAG (op, FLAG_IS_FLOOR) - || QUERY_FLAG (op, FLAG_OBJ_ORIGINAL) - || QUERY_FLAG (op, FLAG_UNIQUE) - || QUERY_FLAG (op, FLAG_OVERLAY_FLOOR) - || QUERY_FLAG (op, FLAG_UNPAID) + if (op->flag [FLAG_IS_FLOOR] + || op->flag [FLAG_OBJ_ORIGINAL] + || op->flag [FLAG_UNIQUE] + || op->flag [FLAG_OVERLAY_FLOOR] + || op->flag [FLAG_UNPAID] || op->is_alive ()) ; // do not decay else if (op->is_weapon ()) @@ -931,13 +935,13 @@ for (mapspace *ms = spaces + size (); ms-- > spaces; ) for (object *op = ms->bot; op; op = op->above) { - if (QUERY_FLAG (op, FLAG_MONSTER)) + if (op->flag [FLAG_MONSTER]) { total_exp += op->stats.exp; monster_cnt++; } - if (QUERY_FLAG (op, FLAG_GENERATOR)) + if (op->flag [FLAG_GENERATOR]) { total_exp += op->stats.exp; @@ -1129,7 +1133,7 @@ for (object *tmp = last; tmp; tmp = tmp->below) { /* Once we get to a floor, stop, since we already have a floor object */ - if (QUERY_FLAG (tmp, FLAG_IS_FLOOR)) + if (tmp->flag [FLAG_IS_FLOOR]) break; /* If two top faces are already set, quit processing */ @@ -1422,29 +1426,28 @@ * closest body part of 'op1' */ void -get_rangevector (object *op1, object *op2, rv_vector * retval, int flags) +get_rangevector (object *op1, object *op2, rv_vector *retval, int flags) { 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 { - object *best; - retval->distance_x += op2->x - op1->x; retval->distance_y += op2->y - op1->y; - best = op1; + object *best = op1; + /* If this is multipart, find the closest part now */ - if (!(flags & 0x1) && op1->more) + 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 @@ -1454,12 +1457,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; } } @@ -1470,9 +1473,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); } } @@ -1492,20 +1495,20 @@ 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); } } @@ -1565,9 +1568,9 @@ { object *pick = at (gen (width), gen (height)).bot; - // do not prefer big monsters just because they are big. + // must be head: do not prefer big monsters just because they are big. if (pick && pick->is_head ()) - return pick->head_ (); + return pick; } // instead of crashing in the unlikely(?) case, try to return *something*