--- deliantra/server/common/map.C 2008/12/26 10:36:42 1.155 +++ deliantra/server/common/map.C 2009/10/16 01:19:12 1.164 @@ -1,22 +1,23 @@ /* * This file is part of Deliantra, the Roguelike Realtime MMORPG. * - * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team + * Copyright (©) 2005,2006,2007,2008,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team * Copyright (©) 2001-2003,2007 Mark Wedel & Crossfire Development Team * Copyright (©) 1992,2007 Frank Tore Johansen * - * Deliantra is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * 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 + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the Affero GNU General Public License + * and the GNU General Public License along with this program. If not, see + * . * * The authors can be reached via e-mail to */ @@ -72,9 +73,6 @@ int blocked_link (object *ob, maptile *m, int sx, int sy) { - object *tmp; - int mflags, blocked; - /* Make sure the coordinates are valid - they should be, as caller should * have already checked this. */ @@ -87,9 +85,10 @@ /* Save some cycles - instead of calling get_map_flags(), just get the value * directly. */ - mflags = m->at (sx, sy).flags (); + mapspace &ms = m->at (sx, sy); - blocked = GET_MAP_MOVE_BLOCK (m, sx, sy); + int mflags = ms.flags (); + int blocked = ms.move_block; /* If space is currently not blocked by anything, no need to * go further. Not true for players - all sorts of special @@ -98,7 +97,7 @@ if (ob->type != PLAYER && !(mflags & P_IS_ALIVE) && (blocked == 0)) return 0; - /* if there isn't anytyhing alive on this space, and this space isn't + /* if there isn't anything alive on this space, and this space isn't * otherwise blocked, we can return now. Only if there is a living * creature do we need to investigate if it is part of this creature * or another. Likewise, only if something is blocking us do we @@ -115,54 +114,57 @@ * true. If we get through the entire stack, that must mean * ob is blocking it, so return 0. */ - for (tmp = GET_MAP_OB (m, sx, sy); tmp; tmp = tmp->above) + for (object *tmp = ms.bot; tmp; tmp = tmp->above) { + bool block = OB_MOVE_BLOCK (ob, tmp); /* This must be before the checks below. Code for inventory checkers. */ - if (tmp->type == CHECK_INV && OB_MOVE_BLOCK (ob, tmp)) + if (block && tmp->type == CHECK_INV) { + bool have = check_inv_recursive (ob, tmp); + /* If last_sp is set, the player/monster needs an object, * so we check for it. If they don't have it, they can't * pass through this space. */ if (tmp->last_sp) { - if (check_inv_recursive (ob, tmp) == NULL) + if (!have) return 1; - else - continue; } else { /* In this case, the player must not have the object - * if they do, they can't pass through. */ - if (check_inv_recursive (ob, tmp) != NULL) /* player has object */ + if (have) return 1; - else - continue; } - } /* if check_inv */ + } + else if (block && tmp->type == T_MATCH) + { + //TODO + } else { /* Broke apart a big nasty if into several here to make * this more readable. first check - if the space blocks * movement, can't move here. * second - if a monster, can't move there, unless it is a - * hidden dm + * dm. */ - if (OB_MOVE_BLOCK (ob, tmp)) + if (block) return 1; if (tmp->flag [FLAG_ALIVE] && tmp->head_ () != ob && tmp != ob && tmp->type != DOOR - && !(tmp->flag [FLAG_WIZ] && tmp->contr->hidden)) + && !tmp->flag [FLAG_WIZ]) return 1; } - } + return 0; } @@ -336,7 +338,7 @@ // we insert manually because // a) its way faster // b) we remove manually, too, and there are good reasons for that - // c) its correct + // c) it's correct mapspace &ms = at (op->x, op->y); op->flag [FLAG_REMOVED] = false; @@ -344,10 +346,7 @@ op->above = 0; op->below = ms.top; - if (ms.top) - ms.top->above = op; - else - ms.bot = op; + *(ms.top ? &ms.top->above : &ms.bot) = op; ms.top = op; ms.flags_ = 0; @@ -569,32 +568,30 @@ /* opposite of parse string, this puts the string that was originally fed in to * the map (or something equivilent) into output_string. */ -static void -print_shop_string (maptile *m, char *output_string) +static const char * +print_shop_string (maptile *m) { - int i; - char tmp[MAX_BUF]; + static dynbuf_text buf; buf.clear (); - strcpy (output_string, ""); - for (i = 0; i < m->shopitems[0].index; i++) + for (int i = 0; i < m->shopitems[0].index; i++) { if (m->shopitems[i].typenum) { if (m->shopitems[i].strength) - sprintf (tmp, "%s:%d;", m->shopitems[i].name, m->shopitems[i].strength); + buf.printf ("%s:%d;", m->shopitems[i].name, m->shopitems[i].strength); else - sprintf (tmp, "%s;", m->shopitems[i].name); + buf.printf ("%s;", m->shopitems[i].name); } else { if (m->shopitems[i].strength) - sprintf (tmp, "*:%d;", m->shopitems[i].strength); + buf.printf ("*:%d;", m->shopitems[i].strength); else - sprintf (tmp, "*"); + buf.printf ("*"); } - - strcat (output_string, tmp); } + + return buf; } /* This loads the header information of the map. The header @@ -739,20 +736,14 @@ MAP_OUT (no_reset); MAP_OUT (no_drop); MAP_OUT (difficulty); - if (default_region) MAP_OUT2 (region, default_region->name); - if (shopitems) - { - char shop[MAX_BUF]; - print_shop_string (this, shop); - MAP_OUT2 (shopitems, shop); - } - + if (shopitems) MAP_OUT2 (shopitems, print_shop_string (this)); MAP_OUT (shopgreed); MAP_OUT (shopmin); MAP_OUT (shopmax); if (shoprace) MAP_OUT (shoprace); + MAP_OUT (darkness); MAP_OUT (width); MAP_OUT (height); @@ -939,30 +930,6 @@ } /* - * Updates every button on the map (by calling update_button() for them). - */ -void -maptile::update_buttons () -{ - for (oblinkpt *obp = buttons; obp; obp = obp->next) - for (objectlink *ol = obp->link; ol; ol = ol->next) - { - if (!ol->ob) - { - LOG (llevError, "Internal error in update_button (%s (%dx%d), connected %ld).\n", - ol->ob ? (const char *) ol->ob->name : "null", ol->ob ? ol->ob->x : -1, ol->ob ? ol->ob->y : -1, obp->value); - continue; - } - - if (ol->ob->type == BUTTON || ol->ob->type == PEDESTAL) - { - update_button (ol->ob); - break; - } - } -} - -/* * This routine is supposed to find out the difficulty of the map. * difficulty does not have a lot to do with character level, * but does have a lot to do with treasure on the map. @@ -1544,8 +1511,8 @@ retval->distance_x += op2->x - x; retval->distance_y += op2->y - y; - retval->part = NULL; - retval->distance = idistance (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); } } @@ -1630,6 +1597,22 @@ } } +void +maptile::say_msg (const char *msg, int x, int y) const +{ + for_all_players (pl) + if (client *ns = pl->ns) + { + int dx = x - pl->ob->x; + int dy = y - pl->ob->y; + + int distance = idistance (dx, dy); + + if (distance <= MAX_SOUND_DISTANCE) + ns->send_msg (NDI_GREY | NDI_DEF, SAY_CHANNEL, msg); + } +} + static void split_to_tiles (dynbuf &buf, maptile *m, int x0, int y0, int x1, int y1, int dx, int dy) {