--- deliantra/server/common/region.C 2006/09/16 22:24:12 1.7 +++ deliantra/server/common/region.C 2007/01/27 23:59:29 1.18 @@ -1,32 +1,39 @@ /* - CrossFire, A Multiplayer game for X-windows - - Copyright (C) 2001-2003 Mark Wedel & Crossfire Development Team - Copyright (C) 1992 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. - - 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, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - - The authors can be reached via e-mail at -*/ - + * CrossFire, A Multiplayer game for X-windows + * + * 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 + * + * 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. + * + * 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, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * The authors can be reached via e-mail at + */ #include +#include + +region * +region::default_region () +{ + for (region *reg = first_region; reg; reg = reg->next) + if (reg->fallback) + return reg; -#ifndef WIN32 /* ---win32 exclude header */ -# include -#endif /* win32 */ + return first_region; +} /* * Pass a char array, returns a pointer to the region of the same name. @@ -37,34 +44,22 @@ * used by the map parsing code. */ region * -get_region_by_name (const char *region_name) +region::find (const char *name) { - region *reg; - char *p = strchr (region_name, '\n'); - - if (p) - *p = '\0'; - for (reg = first_region; reg != NULL; reg = reg->next) - if (!strcmp (reg->name, region_name)) + for (region *reg = first_region; reg; reg = reg->next) + if (!strcmp (reg->name, name)) return reg; - for (reg = first_region; reg != NULL; reg = reg->next) - { - if (reg->fallback) - { - LOG (llevDebug, "region called %s requested, but not found, fallback used.\n", region_name); - return reg; - } - } - LOG (llevInfo, "Got no region or fallback for region %s.\n", region_name); - return NULL; + LOG (llevError, "region called %s requested, but not found, using fallback.\n", name); + + return default_region (); } /* This might need optimising at some point. */ region * get_region_by_map (maptile *m) { - return get_region_by_name (get_name_of_region_for_map (m)); + return region::find (get_name_of_region_for_map (m)); } /* @@ -78,14 +73,16 @@ { region *reg; - if (m->region != NULL) - return m->region->name; - for (reg = first_region; reg != NULL; reg = reg->next) + if (m->default_region) + return m->default_region->name; + + for (reg = first_region; reg; reg = reg->next) { if (reg->fallback) return reg->name; } - LOG (llevInfo, "map %s had no region and I couldn't find a fallback to use.\n", m->name); + + LOG (llevInfo, "map %s had no region and I couldn't find a fallback to use.\n", &m->name); return "unknown"; } @@ -239,7 +236,7 @@ { if (reg->jailmap) { - exit = get_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); @@ -293,16 +290,7 @@ region * get_region_struct (void) { - - region *reg; - - reg = (region *) CALLOC (1, sizeof (region)); - if (reg == NULL) - fatal (OUT_OF_MEMORY); - - memset (reg, '\0', sizeof (region)); - - return reg; + return new region; } /* @@ -359,7 +347,7 @@ { *end = 0; newreg = get_region_struct (); - newreg->name = strdup_local (value); + newreg->name = strdup (value); } else if (!strcmp (key, "parent")) { @@ -369,12 +357,12 @@ * parsed. */ *end = 0; - newreg->parent_name = strdup_local (value); + newreg->parent_name = strdup (value); } else if (!strcmp (key, "longname")) { *end = 0; - newreg->longname = strdup_local (value); + newreg->longname = strdup (value); } else if (!strcmp (key, "jail")) { @@ -387,7 +375,7 @@ LOG (llevError, "region.c: malformated regions entry: jail %s\n", value); continue; } - newreg->jailmap = strdup_local (path); + newreg->jailmap = strdup (path); newreg->jailx = x; newreg->jaily = y; } @@ -409,7 +397,7 @@ * so better do it here too... */ if (msgpos != 0) - newreg->msg = strdup_local (msgbuf); + newreg->msg = strdup (msgbuf); /* we have to reset msgpos, or the next region will store both msg blocks. */ msgpos = 0; @@ -456,10 +444,12 @@ { if (reg->parent_name != NULL) { - reg->parent = get_region_by_name (reg->parent_name); + reg->parent = region::find (reg->parent_name); parent_count++; } + region_count++; } - LOG (llevDebug, "Assigned %u regions with %u parents.", region_count, parent_count); + + LOG (llevDebug, "Assigned %u regions with %u parents.\n", region_count, parent_count); }