--- deliantra/server/common/region.C 2006/12/14 22:45:40 1.11 +++ deliantra/server/common/region.C 2007/01/27 23:59:29 1.18 @@ -1,30 +1,40 @@ /* - 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; + + return first_region; +} + /* * Pass a char array, returns a pointer to the region of the same name. * if it can't find a region of the same name it returns the first region @@ -34,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)); } /* @@ -75,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"; } @@ -444,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); }