--- deliantra/server/common/region.C 2007/05/28 21:21:40 1.32 +++ deliantra/server/common/region.C 2008/12/31 17:35:37 1.40 @@ -1,25 +1,24 @@ /* - * This file is part of Crossfire TRT, the Multiplayer Online Role Playing Game. + * This file is part of Deliantra, the Roguelike Realtime MMORPG. * - * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team + * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team * Copyright (©) 2001-2003,2007 Mark Wedel & Crossfire Development Team * Copyright (©) 1992,2007 Frank Tore Johansen * - * Crossfire TRT 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 2 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 Crossfire TRT; if not, write to the Free Software Foundation, Inc. 51 - * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * 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. + * + * 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. * - * The authors can be reached via e-mail to + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * The authors can be reached via e-mail to */ #include @@ -117,29 +116,37 @@ return default_region (); } +void +region::do_destroy () +{ + regions.erase (this); + + attachable::do_destroy (); + + refcnt_dec (); +} + /* * returns 1 if the player is in the region reg, or a child region thereof * otherwise returns 0 * if passed a NULL region returns -1 */ - static int region_is_child_of_region (const region * child, const region * r) { - - if (r == NULL) + if (!r) return -1; - if (child == NULL) + if (!child) return 0; - if (!strcmp (child->name, r->name)) + if (child->name == r->name) return 1; - else if (child->parent != NULL) + if (child->parent) return region_is_child_of_region (child->parent, r); - else - return 0; + + return 0; } /** Returns an object which is an exit through which the player represented by op should be @@ -150,21 +157,18 @@ object * get_jail_exit (object *op) { - region *reg; - object *exit; - if (op->type != PLAYER) { LOG (llevError, "region.c: get_jail_exit called against non-player object.\n"); return NULL; } - reg = op->region (); + region *reg = op->region (); while (reg) { if (reg->jailmap) { - exit = object::create (); + object *exit = object::create (); EXIT_PATH (exit) = reg->jailmap; /* damned exits reset savebed and remove teleports, so the prisoner can't escape */ SET_FLAG (exit, FLAG_DAMNED); @@ -187,6 +191,8 @@ assert (f.kw == KW_region); region *rgn = new region; + rgn->refcnt_inc (); + f.get (rgn->name); f.next (); @@ -200,7 +206,6 @@ case KW_msg: f.get_ml (KW_endmsg, rgn->msg); break; case KW_longname: f.get (rgn->longname); break; - case KW_match: f.get (rgn->match); break; case KW_jail_map: f.get (rgn->jailmap); break; case KW_jail_x: f.get (rgn->jailx); break; case KW_jail_y: f.get (rgn->jaily); break; @@ -217,25 +222,27 @@ case KW_end: f.next (); + // cannot use find as that will request the default region for_all_regions (old) if (old->name == rgn->name) { - // replace, copy new values (ugly) - rgn->index = old->index; - *old = *rgn; - delete rgn; - - return old; + old->destroy (); + break; } // just append regions.push_back (rgn); return rgn; + case KW_ERROR: + rgn->set_key_text (f.kw_str, f.value); + //fprintf (stderr, "region addkv(%s,%s)\n", f.kw_str, f.value);//D + break; + default: if (!f.parse_error ("region", rgn->name)) { - delete rgn; + rgn->destroy (); return 0; } break;