--- deliantra/server/common/region.C 2006/08/13 17:16:00 1.1 +++ deliantra/server/common/region.C 2006/09/03 00:18:40 1.3 @@ -1,6 +1,6 @@ /* * static char *rcsid_map_c = - * "$Id: region.C,v 1.1 2006/08/13 17:16:00 elmex Exp $"; + * "$Id: region.C,v 1.3 2006/09/03 00:18:40 root Exp $"; */ /* @@ -45,13 +45,13 @@ 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)) return reg; + if (!strcmp(reg->name, region_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; - } + 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; @@ -59,7 +59,7 @@ /* This might need optimising at some point. */ region *get_region_by_map(mapstruct *m) { - return get_region_by_name(get_name_of_region_for_map(m)); + return get_region_by_name(get_name_of_region_for_map(m)); } /* @@ -69,13 +69,13 @@ */ const char *get_name_of_region_for_map(const mapstruct *m) { - region *reg; - if (m->region!=NULL) return m->region->name; - for (reg=first_region;reg!=NULL;reg=reg->next) { - if (reg->fallback) return reg->name; - } + region *reg; + if (m->region!=NULL) return m->region->name; + for (reg=first_region;reg!=NULL;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); - return "unknown"; + return "unknown"; } /* @@ -102,33 +102,33 @@ p = strchr(name, '\n'); if (p) *p = '\0'; for (reg=first_region;reg!=NULL;reg=reg->next) - if (!strcasecmp(reg->name, name)) return reg; + if (!strcasecmp(reg->name, name)) return reg; for (reg=first_region;reg!=NULL;reg=reg->next) if (reg->longname != NULL) { - if (!strcasecmp(reg->longname, name)) return reg; - } + if (!strcasecmp(reg->longname, name)) return reg; + } substr=NULL; for (reg=first_region;reg!=NULL;reg=reg->next) if (reg->longname != NULL) { substr=strstr(reg->longname, name); - if (substr != NULL) return reg; - } + if (substr != NULL) return reg; + } for (reg=first_region;reg!=NULL;reg=reg->next) if (reg->longname != NULL) { - /* - * 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. - */ + /* + * 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. + */ substr=strstr(reg->name, name); - if (substr != NULL) return reg; - } + if (substr != NULL) return reg; + } for (reg=first_region;reg!=NULL;reg=reg->next) { substr=strstr(reg->name, name); - if (substr != NULL) return reg; + if (substr != NULL) return reg; } /* if we are still here, we are going to have to give up, and give the top level region */ for (reg=first_region;reg->parent!=NULL;reg=reg->parent); @@ -146,9 +146,9 @@ if (r==NULL) return -1; if (child == NULL) - return 0; + return 0; if (!strcmp(child->name, r->name)) - return 1; + return 1; else if(child->parent!=NULL) return region_is_child_of_region(child->parent,r); else return 0; @@ -194,21 +194,21 @@ region *reg; object *exit; if (op->type != PLAYER) { - LOG(llevError, "region.c: get_jail_exit called against non-player object.\n"); - return NULL; + LOG(llevError, "region.c: get_jail_exit called against non-player object.\n"); + return NULL; } reg=get_region_by_map(op->map); while (reg!=NULL) { - if (reg->jailmap) { - exit=get_object(); - EXIT_PATH(exit)=add_string(reg->jailmap); - /* damned exits reset savebed and remove teleports, so the prisoner can't escape */ - SET_FLAG(exit, FLAG_DAMNED); - EXIT_X(exit) = reg->jailx; - EXIT_Y(exit) = reg->jaily; - return exit; - } - else reg=reg->parent; + if (reg->jailmap) { + exit=get_object(); + EXIT_PATH(exit)=reg->jailmap; + /* damned exits reset savebed and remove teleports, so the prisoner can't escape */ + SET_FLAG(exit, FLAG_DAMNED); + EXIT_X(exit) = reg->jailx; + EXIT_Y(exit) = reg->jaily; + return exit; + } + else reg=reg->parent; } LOG(llevDebug,"No suitable jailmap for region %s was found.\n", reg->name); return NULL; @@ -231,12 +231,12 @@ sprintf(filename,"%s/%s/%s",settings.datadir,settings.mapdir,settings.regions); LOG(llevDebug,"Reading regions from %s...\n",filename); if((fp=open_and_uncompress(filename,0,&comp))==NULL) { - LOG(llevError," Can't open regions file %s in init_regions.\n", filename); - return; + LOG(llevError," Can't open regions file %s in init_regions.\n", filename); + return; } parse_regions(fp); assign_region_parents(); - LOG(llevDebug," done\n"); + LOG(llevDebug," done\n"); close_and_delete(fp, comp); } @@ -273,106 +273,106 @@ newreg = NULL; while (fgets(buf, HUGE_BUF-1, fp)!=NULL) { - buf[HUGE_BUF-1] = 0; - key = buf; - while (isspace(*key)) key++; - if (*key == 0) continue; /* empty line */ - value = strchr(key, ' '); - if (!value) { - end = strchr(key, '\n'); - *end=0; - } else { - *value = 0; - value++; - while (isspace(*value)) value++; - end = strchr(value, '\n'); - } - - /* - * This is a bizzare mutated form of the map and archetype parser - * rolled into one. Key is the field name, value is what it should - * be set to. - * We've already done the work to null terminate key, - * and strip off any leading spaces for both of these. - * We have not touched the newline at the end of the line - - * these might be needed for some values. the end pointer - * points to the first of the newlines. - * value could be NULL! It would be easy enough to just point - * this to "" to prevent cores, but that would let more errors slide - * through. - */ - if (!strcmp(key,"region")) { - *end=0; - newreg=get_region_struct(); - newreg->name = strdup_local(value); - } - else if (!strcmp(key,"parent")) { - /* - * Note that this is in the initialisation code, so we don't actually - * assign the pointer to the parent yet, because it might not have been - * parsed. - */ - *end=0; - newreg->parent_name = strdup_local(value); - } - else if (!strcmp(key,"longname")) { - *end=0; - newreg->longname = strdup_local(value); - } - else if (!strcmp(key,"jail")) { - /* jail entries are of the form: /path/to/map x y */ - char path[MAX_BUF]; - int x,y; - if (sscanf(value, "%[^ ] %d %d\n", path, &x, &y) != 3) { - LOG(llevError, "region.c: malformated regions entry: jail %s\n", value); - continue; - } - newreg->jailmap = strdup_local(path); - newreg->jailx = x; - newreg->jaily = y; - } - else if (!strcmp(key,"msg")) { - while (fgets(buf, HUGE_BUF-1, fp)!=NULL) { - if (!strcmp(buf,"endmsg\n")) break; - else { - strcpy(msgbuf+msgpos, buf); - msgpos += strlen(buf); - } - } - /* - * There may be regions with empty messages (eg, msg/endmsg - * with nothing between). When maps are loaded, this is done - * so better do it here too... - */ - if (msgpos != 0) - newreg->msg = strdup_local(msgbuf); - - /* we have to reset msgpos, or the next region will store both msg blocks.*/ - msgpos=0; - } - else if (!strcmp(key,"fallback")) { - *end=0; - newreg->fallback = atoi(value); - } - else if (!strcmp(key,"end")) { - /* Place this new region last on the list, if the list is empty put it first */ - for (reg=first_region;reg!=NULL&®->next!=NULL;reg=reg->next); - - if (reg==NULL) first_region=newreg; - else reg->next=newreg; - newreg = NULL; - } - else if (!strcmp(key,"nomore")) { - /* we have reached the end of the region specs....*/ - break; - } - else { - /* we should never get here, if we have, then something is wrong */ - LOG(llevError, "Got unknown value in region file: %s %s\n", key, value); - } + buf[HUGE_BUF-1] = 0; + key = buf; + while (isspace(*key)) key++; + if (*key == 0) continue; /* empty line */ + value = strchr(key, ' '); + if (!value) { + end = strchr(key, '\n'); + *end=0; + } else { + *value = 0; + value++; + while (isspace(*value)) value++; + end = strchr(value, '\n'); + } + + /* + * This is a bizzare mutated form of the map and archetype parser + * rolled into one. Key is the field name, value is what it should + * be set to. + * We've already done the work to null terminate key, + * and strip off any leading spaces for both of these. + * We have not touched the newline at the end of the line - + * these might be needed for some values. the end pointer + * points to the first of the newlines. + * value could be NULL! It would be easy enough to just point + * this to "" to prevent cores, but that would let more errors slide + * through. + */ + if (!strcmp(key,"region")) { + *end=0; + newreg=get_region_struct(); + newreg->name = strdup_local(value); + } + else if (!strcmp(key,"parent")) { + /* + * Note that this is in the initialisation code, so we don't actually + * assign the pointer to the parent yet, because it might not have been + * parsed. + */ + *end=0; + newreg->parent_name = strdup_local(value); + } + else if (!strcmp(key,"longname")) { + *end=0; + newreg->longname = strdup_local(value); + } + else if (!strcmp(key,"jail")) { + /* jail entries are of the form: /path/to/map x y */ + char path[MAX_BUF]; + int x,y; + if (sscanf(value, "%[^ ] %d %d\n", path, &x, &y) != 3) { + LOG(llevError, "region.c: malformated regions entry: jail %s\n", value); + continue; + } + newreg->jailmap = strdup_local(path); + newreg->jailx = x; + newreg->jaily = y; + } + else if (!strcmp(key,"msg")) { + while (fgets(buf, HUGE_BUF-1, fp)!=NULL) { + if (!strcmp(buf,"endmsg\n")) break; + else { + strcpy(msgbuf+msgpos, buf); + msgpos += strlen(buf); + } + } + /* + * There may be regions with empty messages (eg, msg/endmsg + * with nothing between). When maps are loaded, this is done + * so better do it here too... + */ + if (msgpos != 0) + newreg->msg = strdup_local(msgbuf); + + /* we have to reset msgpos, or the next region will store both msg blocks.*/ + msgpos=0; + } + else if (!strcmp(key,"fallback")) { + *end=0; + newreg->fallback = atoi(value); + } + else if (!strcmp(key,"end")) { + /* Place this new region last on the list, if the list is empty put it first */ + for (reg=first_region;reg!=NULL&®->next!=NULL;reg=reg->next); + + if (reg==NULL) first_region=newreg; + else reg->next=newreg; + newreg = NULL; + } + else if (!strcmp(key,"nomore")) { + /* we have reached the end of the region specs....*/ + break; + } + else { + /* we should never get here, if we have, then something is wrong */ + LOG(llevError, "Got unknown value in region file: %s %s\n", key, value); + } } if (!key || strcmp(key,"nomore")) - LOG(llevError, "Got premature eof on regions file!\n"); + LOG(llevError, "Got premature eof on regions file!\n"); } void assign_region_parents(void) { @@ -380,11 +380,11 @@ uint32 parent_count=0; uint32 region_count=0; for (reg=first_region;reg!=NULL&®->next!=NULL;reg=reg->next) { - if (reg->parent_name!=NULL) { - reg->parent=get_region_by_name(reg->parent_name); - parent_count++; - } - region_count++; + if (reg->parent_name!=NULL) { + reg->parent=get_region_by_name(reg->parent_name); + parent_count++; + } + region_count++; } LOG(llevDebug, "Assigned %u regions with %u parents.", region_count, parent_count); }