changeset 280:65fe1d3c12ee

Work towards new loc-file format has begun.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 18 Jun 2007 00:19:07 +0000
parents d0ba4b07d395
children bf2e10b30488
files mkloc.c
diffstat 1 files changed, 62 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/mkloc.c	Mon Jun 18 00:14:25 2007 +0000
+++ b/mkloc.c	Mon Jun 18 00:19:07 2007 +0000
@@ -52,7 +52,7 @@
 typedef struct {
 	int x, y, ox, oy;
 	int dir, flags;
-	char *desc;
+	char *desc, *url, *freeform;
 } locinfo_t;
 
 
@@ -215,8 +215,8 @@
 }
 
 
-BOOL addLocation(locations_t *l,
-	int x, int y, int dir, char *desc, int flags)
+BOOL addLocation(locations_t *l, int x, int y, int dir,
+	char *desc, int flags, char *url, char *freeform)
 {
 	locinfo_t *tmp;
 	
@@ -229,6 +229,8 @@
 	tmp->dir = dir;
 	tmp->flags = flags;
 	tmp->desc = th_strdup(desc);
+	tmp->url = th_strdup(url);
+	tmp->freeform = th_strdup(freeform);
 
 	/* Add new location */	
 	l->locations = (locinfo_t **) th_realloc(l->locations,
@@ -466,7 +468,7 @@
 			}
 			
 			/* Add new location to our list */
-			addLocation(l, tx, ty, td, &(inLine[f.linePos]), tf);
+			addLocation(l, tx, ty, td, &(inLine[f.linePos]), tf, NULL, NULL);
 			
 		} else if (inLine[f.linePos] != '#' && inLine[f.linePos] != 0) {
 			THERR("Invalid line #%d in '%s'\n",
@@ -534,6 +536,31 @@
 }
 
 
+int printType(FILE *outFile, locinfo_t *loc)
+{
+	char *s = NULL;
+	
+	switch (loc->flags & LOCF_M_MASK) {
+	case LOCF_M_PCITY:	s = "PCITY"; break;
+	case LOCF_M_CITY:	s = "CITY"; break;
+	
+	default:
+		switch (loc->flags & LOCF_T_MASK) {
+		case LOCF_T_SHRINE:	s = "SHRINE"; break;
+		case LOCF_T_GUILD:	s = "GUILD"; break;
+		case LOCF_T_SS:		s = "SS"; break;
+		case LOCF_T_MONSTER:	s = "MONSTER"; break;
+		}
+	}
+	
+	if (s) {
+		fprintf(outFile, "%s ", s);
+		return strlen(s) + 1;
+	} else
+		return 0;
+}
+
+
 /* Output the map with labels and location markers, etc. in
  * special ASCII-CTRL format understood by colormap utility.
  */
@@ -563,6 +590,10 @@
 					fputc('C', outFile);
 					break;
 				
+				case LOCF_M_CITY:
+					fputc('c', outFile);
+					break;
+					
 				default:
 					if (tloc->flags & LOCF_INVALID)
 						fputc('$', outFile);
@@ -582,10 +613,12 @@
 					switch (tloc->flags & LOCF_M_MASK) {
 					case LOCF_M_PCITY:
 						fputc(col_light_green, outFile);
-						fprintf(outFile, "PCITY ");
-						x += 6;
 						break;
-						
+					
+					case LOCF_M_CITY:
+						fputc(col_light_yellow, outFile);
+						break;
+					
 					case LOCF_M_SCENIC1:
 						fputc(col_yellow, outFile);
 						break;
@@ -598,7 +631,9 @@
 						fputc(col_light_white, outFile);
 						break;
 					}
-
+					
+					x += printType(outFile, tloc);
+					
 					fputs(tloc->desc, outFile);
 					fputc(0xfe, outFile);
 					x += strlen(tloc->desc) - 1;
@@ -624,7 +659,11 @@
 	/* Output header */
 	fprintf(outFile,
 		"# Format of this file is one location per line:\n"
-		"# X\tY\textra\tLocation name\n"
+		"#\n"
+		"# x;y;flags;location name;creator[,creatorN];information URL;freeform\n"
+		"#\n"
+		"# The entries may be aligned/padded with whitespace, which will be stripped.\n"
+		"# Empty lines and lines beginning with '#' are ignored.\n\n"
 		);
 	
 	/* Output each location entry */
@@ -636,7 +675,7 @@
 		fprintf(outFile, "\n# Possibly invalid location #%d: %s\n",
 			i, tmp->desc);
 		
-		fprintf(outFile, "%d\t%d\t%d",
+		fprintf(outFile, "%d\t; %d\t; %d",
 			tmp->ox, tmp->oy, tmp->dir);
 		
 		switch (tmp->flags & LOCF_M_MASK) {
@@ -656,7 +695,17 @@
 		if (tmp->flags & LOCF_INVIS)
 			fputc('-', outFile);
 		
-		fprintf(outFile, "\t%s\n", tmp->desc);
+		fprintf(outFile, "\t;%s;", tmp->desc);
+		
+		if (tmp->url)
+			fprintf(outFile, "%s", tmp->url);
+		
+		fprintf(outFile, ";");
+		
+		if (tmp->freeform)
+			fprintf(outFile, "%s", tmp->freeform);
+		
+		fprintf(outFile, "\n");
 	}
 }
 
@@ -827,7 +876,7 @@
 						srcFile, numNewLoc);
 				}
 				
-				addLocation(worldLoc, x, y, LOCD_NONE, tmps, tmpf);
+				addLocation(worldLoc, x, y, LOCD_NONE, tmps, tmpf, NULL, NULL);
 			}
 		} else {
 			/* Check for misplaced locations */
@@ -858,7 +907,7 @@
 	th_memset(&worldLoc, 0, sizeof(worldLoc));
 
 	/* Initialize */
-	th_init("mkloc", "Add locations to ASCII map", "0.6", NULL, NULL);
+	th_init("mkloc", "Add locations to ASCII map", "0.7", NULL, NULL);
 	th_verbosityLevel = 1;
 	
 	/* Parse arguments */