--- deliantra/server/common/region.C 2007/02/02 00:42:03 1.24 +++ deliantra/server/common/region.C 2009/10/12 14:00:57 1.43 @@ -1,32 +1,30 @@ /* - * CrossFire, A Multiplayer game for X-windows + * This file is part of Deliantra, the Roguelike Realtime MMORPG. * - * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team - * Copyright (C) 2001-2003 Mark Wedel & Crossfire Development Team - * Copyright (C) 1992 Frank Tore Johansen + * 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 * - * This program 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. + * 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 + * 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, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * The authors can be reached via e-mail at + * 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 */ #include #include -#include "loader.h" - regionvec regions; region * @@ -48,75 +46,25 @@ * used by the map parsing code. */ region * -region::find (const char *name) +region::find (shstr_cmp name) { for_all_regions (rgn) - if (!strcmp (rgn->name, name)) + if (rgn->name == name) return rgn; - LOG (llevError, "region called %s requested, but not found, using fallback.\n", name); + LOG (llevError, "region called %s requested, but not found, using fallback.\n", &name); return default_region (); } -/* - * Tries to find a region that 'name' corresponds to. - * It looks, in order, for: - * an exact match to region name (case insensitive) - * an exact match to longname (case insensitive) - * a substring that matches to the longname (eg Kingdom) - * a substring that matches to the region name (eg nav) - * if it can find none of these it returns the first parentless region - * (there should be only one of these - the top level one) - * If we got a NULL, then just return the top level region - * - */ -region * -region::find_fuzzy (const char *name) +void +region::do_destroy () { - if (!name) - return default_region (); + regions.erase (this); - char *p = strchr (name, '\n'); - if (p) - *p = '\0'; + attachable::do_destroy (); - for_all_regions (rgn) - if (!strcasecmp (rgn->name, name)) - return rgn; - - for_all_regions (rgn) - if (rgn->longname) - if (!strcasecmp (rgn->longname, name)) - return rgn; - - for_all_regions (rgn) - if (rgn->longname) - { - if (strstr (rgn->longname, name)) - return rgn; - } - - for_all_regions (rgn) - if (rgn->longname) - { - /* - * This is not a bug, we want the region that is most identifiably a discrete - * area in the game, eg if we have 'scor', we want to return 'scorn' and not - * 'scornarena', regardless of their order on the list so we only look at those - * regions with a longname set. - */ - if (strstr (rgn->name, name)) - return rgn; - } - - for_all_regions (rgn) - { - if (strstr (rgn->name, name)) - return rgn; - } - - return default_region (); + refcnt_dec (); } /* @@ -124,24 +72,22 @@ * 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 @@ -152,21 +98,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); @@ -183,75 +126,70 @@ return 0; } -region *loader_region::get_region (const char *name) -{ - region *rgn = new region; - rgn->name = name; - return rgn; -} - -void loader_region::put_region (region *rgn) +region * +region::read (object_thawer &f) { - for_all_regions (old) - if (old->name == rgn->name) - { - // replace, copy new values (ugly) - rgn->index = old->index; - *old = *rgn; - delete rgn; + assert (f.kw == KW_region); - return; - } + region *rgn = new region; + rgn->refcnt_inc (); - // just append - regions.push_back (rgn); -} + f.get (rgn->name); + f.next (); -bool -loader_base::parse_region (object_thawer &thawer, region *rgn) -{ for (;;) { - keyword kw = thawer.get_kv (); - - switch (kw) + switch (f.kw) { case KW_parent: - rgn->parent = region::find (thawer.get_str ()); + rgn->parent = region::find (f.get_str ()); break; - case KW_longname: - thawer.get (rgn->longname); - break; - - case KW_jail_map: - thawer.get (rgn->jailmap); - break; - - case KW_jail_x: - thawer.get (rgn->jailx); - break; - - case KW_jail_y: - thawer.get (rgn->jaily); - break; + case KW_msg: f.get_ml (KW_endmsg, rgn->msg); break; + case KW_longname: f.get (rgn->longname); 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; + case KW_portal_map: f.get (rgn->portalmap);break; + case KW_portal_x: f.get (rgn->portalx); break; + case KW_portal_y: f.get (rgn->portaly); break; + case KW_fallback: f.get (rgn->fallback); break; + case KW_chance: f.get (rgn->treasure_density); break; - case KW_msg: - thawer.get_ml (KW_endmsg, rgn->msg); - break; - - case KW_fallback: - thawer.get (rgn->fallback); + case KW_randomitems: + rgn->treasure = treasurelist::get (f.get_str ()); break; case KW_end: - return true; + f.next (); + + // cannot use find as that will request the default region + for_all_regions (old) + if (old->name == rgn->name) + { + 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 (!thawer.parse_error (kw, "region", rgn->name)) - return false; + if (!f.parse_error ("region", rgn->name)) + { + rgn->destroy (); + return 0; + } break; } + + f.next (); } } @@ -259,7 +197,6 @@ * First initialises the archtype hash-table (init_archetable()). * Reads and parses the archetype file (with the first and second-pass * functions). - * Then initialises treasures by calling load_treasures(). */ void init_regions (void)