Mercurial > hg > batmud > maputils
changeset 2402:0a4dd01fe74a
Separate area name and creator flags. Add some helper functions to liblocfile.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 10 Nov 2021 09:27:29 +0200 |
parents | 4185a550c48f |
children | 3049aafc269d |
files | src/liblocfile.c src/liblocfile.h src/mkloc.c |
diffstat | 3 files changed, 165 insertions(+), 104 deletions(-) [+] |
line wrap: on
line diff
--- a/src/liblocfile.c Wed Nov 10 09:26:01 2021 +0200 +++ b/src/liblocfile.c Wed Nov 10 09:27:29 2021 +0200 @@ -20,7 +20,22 @@ } LocFileParseContext; -static void locAddName(LocName *dst, int *ndst, LocName *src, const int nsrc) +const char * locGetAreaNameType(const int flags, const BOOL type) +{ + const char *pfx; + const char *desc; + + switch (flags) + { + case NAME_ORIG : pfx = "@"; desc = "original"; break; + default : pfx = "" ; desc = NULL; break; + } + + return type ? desc : pfx; +} + + +static void locAddAreaName(LocName *dst, int *ndst, const LocName *src, const int nsrc) { if (src != NULL && src[nsrc].name != NULL) { @@ -29,9 +44,44 @@ switch (src[nsrc].name[0]) { case '@': n++; flags |= NAME_ORIG; break; - case '!': n++; flags |= NAME_RECODER; break; - case '%': n++; flags |= NAME_MAINTAINER; break; - case '&': n++; flags |= NAME_EXPANDER; break; + } + dst[*ndst].name = th_strdup(&(src[nsrc].name[n])); + dst[*ndst].flags = flags; + (*ndst)++; + } +} + + +const char * locGetAreaCreatorRole(const int flags, const BOOL type) +{ + const char *pfx; + const char *desc; + + switch (flags) + { + case CREATOR_ORIG : pfx = "@"; desc = "original"; break; + case CREATOR_RECODER : pfx = "!"; desc = "recoder"; break; + case CREATOR_MAINTAINER : pfx = "%"; desc = "maintainer"; break; + case CREATOR_EXPANDER : pfx = "&"; desc = "expander"; break; + default : pfx = "" ; desc = "undefined"; break; + } + + return type ? desc : pfx; +} + + +static void locAddAreaCreator(LocName *dst, int *ndst, const LocName *src, const int nsrc) +{ + if (src != NULL && src[nsrc].name != NULL) + { + int flags = 0; + int n = 0; + switch (src[nsrc].name[0]) + { + case '@': n++; flags |= CREATOR_ORIG; break; + case '!': n++; flags |= CREATOR_RECODER; break; + case '%': n++; flags |= CREATOR_MAINTAINER; break; + case '&': n++; flags |= CREATOR_EXPANDER; break; } dst[*ndst].name = th_strdup(&(src[nsrc].name[n])); dst[*ndst].flags = flags; @@ -40,6 +90,54 @@ } +const char *locGetTypePrefix(const int flags) +{ + switch (flags & LOCF_M_MASK) + { + case LOCF_M_CITY: return "CITY"; + case LOCF_M_PCITY: return "PCITY"; + + default: + switch (flags & LOCF_T_MASK) + { + case LOCF_T_SHRINE: return "SHRINE"; + case LOCF_T_GUILD: return "GUILD"; + case LOCF_T_SS: return "SS"; + case LOCF_T_MONSTER: return "MOB"; + case LOCF_T_TRAINER: return "TRAINER"; + case LOCF_T_FORT: return "FORT"; + } + break; + } + + return NULL; +} + + +const char *locGetTypeName(const int flags) +{ + switch (flags & LOCF_M_MASK) + { + case LOCF_M_CITY: return "city"; + case LOCF_M_PCITY: return "pcity"; + + default: + switch (flags & LOCF_T_MASK) + { + case LOCF_T_SHRINE: return "shrine"; + case LOCF_T_GUILD: return "guild"; + case LOCF_T_SS: return "ss"; + case LOCF_T_MONSTER: return "monster"; + case LOCF_T_TRAINER: return "trainer"; + case LOCF_T_FORT: return "fort"; + } + break; + } + + return "default"; +} + + LocMarker * locCopyLocMarker(const LocMarker *src) { LocMarker *res = th_malloc0(sizeof(LocMarker)); @@ -56,8 +154,8 @@ for (int i = 0; i < res->nnames; i++) res->names[i].name = th_strdup(src->names[i].name); - for (int i = 0; i < res->ncoders; i++) - res->coders[i].name = th_strdup(src->coders[i].name); + for (int i = 0; i < res->ncreators; i++) + res->creators[i].name = th_strdup(src->creators[i].name); return res; } @@ -77,7 +175,7 @@ BOOL locAddNew(MapLocations *l, int xc, int yc, int dir, int flags, - LocName *names, LocName *coders, LocDateStruct *added, BOOL valid, + LocName *names, LocName *creators, LocDateStruct *added, BOOL valid, const char *uri, const char *freeform, LocFileInfo *file) { LocMarker *tmp; @@ -95,8 +193,8 @@ for (i = 0; i < LOC_MAX_NAMES; i++) { - locAddName(tmp->names, &tmp->nnames, names, i); - locAddName(tmp->coders, &tmp->ncoders, coders, i); + locAddAreaName(tmp->names, &tmp->nnames, names, i); + locAddAreaCreator(tmp->creators, &tmp->ncreators, creators, i); } if (added != NULL) @@ -156,7 +254,7 @@ for (int i = 0; i < LOC_MAX_NAMES; i++) { th_free_r(&marker->names[i].name); - th_free_r(&marker->coders[i].name); + th_free_r(&marker->creators[i].name); } th_free_r(&marker->uri); @@ -493,8 +591,8 @@ locParseMultiField(ctx, "|;", '|', "location names", marker->names); break; - case 5: // Coders - locParseMultiField(ctx, ",;", ',', "coder names", marker->coders); + case 5: // Creators + locParseMultiField(ctx, ",;", ',', "creator names", marker->creators); break; case 6: // Date @@ -548,7 +646,7 @@ { // Add new location to our list locAddNew(l, marker->xc, marker->yc, marker->align, marker->flags, - marker->names, marker->coders, &marker->added, + marker->names, marker->creators, &marker->added, marker->valid, marker->uri, tmpStr, ctx->file); locPMSet(ctx, PM_IDLE, -1); } @@ -769,54 +867,6 @@ } -const char *locGetTypePrefix(const int flags) -{ - switch (flags & LOCF_M_MASK) - { - case LOCF_M_CITY: return "CITY"; - case LOCF_M_PCITY: return "PCITY"; - - default: - switch (flags & LOCF_T_MASK) - { - case LOCF_T_SHRINE: return "SHRINE"; - case LOCF_T_GUILD: return "GUILD"; - case LOCF_T_SS: return "SS"; - case LOCF_T_MONSTER: return "MOB"; - case LOCF_T_TRAINER: return "TRAINER"; - case LOCF_T_FORT: return "FORT"; - } - break; - } - - return NULL; -} - - -const char *locGetTypeName(const int flags) -{ - switch (flags & LOCF_M_MASK) - { - case LOCF_M_CITY: return "city"; - case LOCF_M_PCITY: return "pcity"; - - default: - switch (flags & LOCF_T_MASK) - { - case LOCF_T_SHRINE: return "shrine"; - case LOCF_T_GUILD: return "guild"; - case LOCF_T_SS: return "ss"; - case LOCF_T_MONSTER: return "monster"; - case LOCF_T_TRAINER: return "trainer"; - case LOCF_T_FORT: return "fort"; - } - break; - } - - return "default"; -} - - void locSetFileInfo(LocFileInfo *file, const char *filename, const char *continent) { file->filename = th_strdup(filename);
--- a/src/liblocfile.h Wed Nov 10 09:26:01 2021 +0200 +++ b/src/liblocfile.h Wed Nov 10 09:27:29 2021 +0200 @@ -78,10 +78,17 @@ #define LOC_MAX_FILES (64) -#define NAME_ORIG (0x00001) // '@' Original area name or coder -#define NAME_RECODER (0x00002) // '!' Converter or recoder of area -#define NAME_MAINTAINER (0x00004) // '%' Maintainer -#define NAME_EXPANDER (0x00008) // '&' Expander, adding new things +/* Creator roles + */ +#define CREATOR_ORIG (0x00001) // '@' Original area creator +#define CREATOR_RECODER (0x00002) // '!' Converter or recoder of area +#define CREATOR_MAINTAINER (0x00004) // '%' Maintainer +#define CREATOR_EXPANDER (0x00008) // '&' Expander, adding new things + + +/* Area name flags + */ +#define NAME_ORIG (0x00001) // '@' Original area name /* Structures @@ -118,8 +125,8 @@ LocDateStruct added; // Date / time information BOOL valid; - int nnames, ncoders; - LocName names[LOC_MAX_NAMES], coders[LOC_MAX_NAMES]; + int nnames, ncreators; + LocName names[LOC_MAX_NAMES], creators[LOC_MAX_NAMES]; char *uri, *freeform; @@ -140,9 +147,18 @@ /* Location file parsing and data handling */ +const char * locGetAreaNameType(const int flags, const BOOL type); +const char * locGetAreaCreatorRole(const int flags, const BOOL type); +const char * locGetTypePrefix(const int flags); +const char * locGetTypeName(const int flags); + + +LocMarker *locCopyLocMarker(const LocMarker *); +void locCopyLocations(MapLocations *dst, const MapLocations *src); + BOOL locAddNew(MapLocations *l, int xc, int yc, int dir, int flags, - LocName *names, LocName *coders, LocDateStruct *added, BOOL valid, - const char *uri, const char *freeform, LocFileInfo *file); + LocName *names, LocName *creators, LocDateStruct *added, BOOL valid, + const char *uri, const char *freeform, LocFileInfo *file); BOOL locParseLocStream(FILE *fp, LocFileInfo *file, MapLocations *l, const int offX, const int offY); void locFreeMarkerData(LocMarker *marker); @@ -150,12 +166,6 @@ int locFindByCoords(const MapLocations *l, const int x, const int y, const BOOL locTrue); -const char * locGetTypePrefix(const int flags); -const char * locGetTypeName(const int flags); - -LocMarker *locCopyLocMarker(const LocMarker *); -void locCopyLocations(MapLocations *dst, const MapLocations *src); - void locSetFileInfo(LocFileInfo *file, const char *filename, const char *continent); void locFreeFileInfo(LocFileInfo *file);
--- a/src/mkloc.c Wed Nov 10 09:26:01 2021 +0200 +++ b/src/mkloc.c Wed Nov 10 09:27:29 2021 +0200 @@ -627,15 +627,7 @@ */ void printLocNameEsc(FILE *outFile, LocName *name) { - char *prefix = ""; - switch (name->flags) - { - case NAME_ORIG: prefix = "@"; break; - case NAME_RECODER: prefix = "!"; break; - case NAME_MAINTAINER: prefix = "%"; break; - case NAME_EXPANDER: prefix = "&"; break; - } - fputs(prefix, outFile); + fputs(locGetAreaCreatorRole(name->flags, FALSE), outFile); fputsesc2(name->name, outFile); } @@ -714,13 +706,13 @@ } fprintf(outFile, ";"); - if (tmp->ncoders > 0) + if (tmp->ncreators > 0) { - printLocNameEsc(outFile, &tmp->coders[0]); - for (int n = 1; n < tmp->ncoders; n++) + printLocNameEsc(outFile, &tmp->creators[0]); + for (int n = 1; n < tmp->ncreators; n++) { fprintf(outFile, ","); - printLocNameEsc(outFile, &tmp->coders[n]); + printLocNameEsc(outFile, &tmp->creators[n]); } } @@ -934,38 +926,38 @@ tmp->added.day, tmp->added.month, tmp->added.year); } - // Coder names or societies - if (tmp->ncoders > 0) + // Creator names or societies + if (tmp->ncreators > 0) { if (tmp->flags & LOCF_M_PCITY) { fprintf(outFile, "Societies: "); - for (int n = 0; n < tmp->ncoders; n++) + for (int n = 0; n < tmp->ncreators; n++) { - fps(tmp->coders[n].name, outFile); - if (n < tmp->ncoders - 1) + fps(tmp->creators[n].name, outFile); + if (n < tmp->ncreators - 1) fprintf(outFile, ", "); } } else { - fprintf(outFile, "Coders: "); - for (int n = 0; n < tmp->ncoders; n++) + fprintf(outFile, "Creators: "); + for (int n = 0; n < tmp->ncreators; n++) { char *info = "", *sinfo = ""; - switch (tmp->coders[n].flags) + switch (tmp->creators[n].flags) { - case NAME_ORIG: info = " (O)"; sinfo = "Original coder"; break; - case NAME_RECODER: info = " (R)"; sinfo = "Re-coder"; break; - case NAME_MAINTAINER: info = " (M)"; sinfo = "Maintainer"; break; - case NAME_EXPANDER: info = " (E)"; sinfo = "Expander"; break; + case CREATOR_ORIG: info = " (O)"; sinfo = "Original coder"; break; + case CREATOR_RECODER: info = " (R)"; sinfo = "Re-coder"; break; + case CREATOR_MAINTAINER: info = " (M)"; sinfo = "Maintainer"; break; + case CREATOR_EXPANDER: info = " (E)"; sinfo = "Expander"; break; } //fpr(outFile, "<a target=\"_blank\" href=\"http://www.bat.org/char/%s\">%s%s</a>", fpr(outFile, "<a target=\"_blank\" href=\"https://tnsp.org/maps/loc.php?a=%s\" title=\"%s\">%s%s</a>", - tmp->coders[n].name, sinfo, - tmp->coders[n].name, info); + tmp->creators[n].name, sinfo, + tmp->creators[n].name, info); - if (n < tmp->ncoders - 1) + if (n < tmp->ncreators - 1) fprintf(outFile, ", "); } } @@ -1043,8 +1035,17 @@ } // Type of the marker - fprintf(outFile, " type=\"%s\"/>\n", + fprintf(outFile, " type=\"%s\"", locGetTypeName(tmp->flags)); + + // Added to game timestamp + if (tmp->valid) + { + fprintf(outFile, " added=\"" LOC_TIMEFMT "\"", + tmp->added.day, tmp->added.month, tmp->added.year); + } + + fprintf(outFile, "/>\n"); } fprintf(outFile, "</markers>\n");