--- deliantra/server/common/region.c 2006/02/03 07:11:40 1.1.1.1 +++ deliantra/server/common/region.c 2006/02/22 18:01:23 1.1.1.2 @@ -68,7 +68,7 @@ * the map code. */ -const char *get_name_of_region_for_map(mapstruct *m) { +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) { @@ -141,7 +141,7 @@ * if passed a NULL region returns -1 */ -int region_is_child_of_region(region *child, region *r) { +int region_is_child_of_region(const region *child, const region *r) { if (r==NULL) return -1; @@ -162,7 +162,7 @@ * 3. return a obviously wrong string if we can't get a longname, this should * never happen. We also log a debug message. */ -const char *get_region_longname(region *r) { +const char *get_region_longname(const region *r) { if (r->longname!=NULL) return r->longname; @@ -174,7 +174,7 @@ } } -const char *get_region_msg(region *r) { +const char *get_region_msg(const region *r) { if (r->msg!=NULL) return r->msg; else if(r->parent!=NULL) @@ -185,6 +185,35 @@ } } +/** Returns an object which is an exit through which the player represented by op should be + * sent in order to be imprisoned. If there is no suitable place to which an exit can be + * constructed, then NULL will be returned. The caller is responsible for freeing the object + * created by this function. + */ +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=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; + } + LOG(llevDebug,"No suitable jailmap for region %s was found.\n", reg->name); + return NULL; +} + /* * First initialises the archtype hash-table (init_archetable()). * Reads and parses the archetype file (with the first and second-pass @@ -290,6 +319,18 @@ *end=0; new->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; + } + new->jailmap = strdup_local(path); + new->jailx = x; + new->jaily = y; + } else if (!strcmp(key,"msg")) { while (fgets(buf, HUGE_BUF-1, fp)!=NULL) { if (!strcmp(buf,"endmsg\n")) break;