Mercurial > hg > batmud > maputils
annotate mkspecial.c @ 1770:cc59f80b0e78
Various cleanups.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 27 Oct 2017 04:35:51 +0300 |
parents | f5d432ccc9d6 |
children | 72adabd8e746 |
rev | line source |
---|---|
28 | 1 /* |
2 * mkspecial - Compute complete ASCII map by stitching pieces | |
3 * together based on a matcher and coordinates | |
4 * | |
5 * Programmed by Matti 'ccr' Hämäläinen (Ggr Pupunen) | |
1487 | 6 * (C) Copyright 2006-2015 Tecnic Software productions (TNSP) |
28 | 7 */ |
1308
d11f9751e299
Renamed maputils.[ch] -> libmaputils.[ch], adjusted other code accordingly;
Matti Hamalainen <ccr@tnsp.org>
parents:
1284
diff
changeset
|
8 #include "libmaputils.h" |
28 | 9 #include "th_args.h" |
10 #include "th_string.h" | |
11 | |
714 | 12 #define MAX_FILES (256) |
28 | 13 |
14 | |
15 /* Variables | |
16 */ | |
714 | 17 int nsrcFiles = 0; |
18 char *srcFiles[MAX_FILES], | |
19 *destFile = NULL; | |
28 | 20 |
714 | 21 int optInitialX = 0, |
22 optInitialY = 0, | |
23 optMapFactor = 10, | |
24 optRounds = 100, | |
25 optReset = 50; | |
26 BOOL optHardDrop = FALSE, | |
27 optDumpRejected = FALSE, | |
28 optAdjustBlocks = FALSE, | |
29 optWalkMode = FALSE; | |
30 float optMatch = 40.0; | |
31 char *optInitialMap = NULL, | |
32 *optCleanChars = " *@", | |
33 optCenterCh = -1; | |
28 | 34 |
61
4efae5dae2e3
th_args_process() transition.
Matti Hamalainen <ccr@tnsp.org>
parents:
45
diff
changeset
|
35 |
28 | 36 /* Arguments |
37 */ | |
1615 | 38 static const th_optarg optList[] = { |
1647
e7539466282b
Use OPT_* constants instead of 0/1.
Matti Hamalainen <ccr@tnsp.org>
parents:
1615
diff
changeset
|
39 { 0, '?', "help", "Show this help", OPT_NONE }, |
e7539466282b
Use OPT_* constants instead of 0/1.
Matti Hamalainen <ccr@tnsp.org>
parents:
1615
diff
changeset
|
40 { 1, 'o', "output", "Specify output file", OPT_ARGREQ }, |
e7539466282b
Use OPT_* constants instead of 0/1.
Matti Hamalainen <ccr@tnsp.org>
parents:
1615
diff
changeset
|
41 { 2, 'v', "verbose", "Be more verbose", OPT_NONE }, |
e7539466282b
Use OPT_* constants instead of 0/1.
Matti Hamalainen <ccr@tnsp.org>
parents:
1615
diff
changeset
|
42 { 3, 'q', "quiet", "Be quiet", OPT_NONE }, |
e7539466282b
Use OPT_* constants instead of 0/1.
Matti Hamalainen <ccr@tnsp.org>
parents:
1615
diff
changeset
|
43 { 4, 'm', "match", "Match percentage", OPT_ARGREQ }, |
e7539466282b
Use OPT_* constants instead of 0/1.
Matti Hamalainen <ccr@tnsp.org>
parents:
1615
diff
changeset
|
44 { 5, 'r', "rounds", "Processing timeout # rounds", OPT_ARGREQ }, |
e7539466282b
Use OPT_* constants instead of 0/1.
Matti Hamalainen <ccr@tnsp.org>
parents:
1615
diff
changeset
|
45 { 12,'R', "reset", "Round reset after", OPT_ARGREQ }, |
e7539466282b
Use OPT_* constants instead of 0/1.
Matti Hamalainen <ccr@tnsp.org>
parents:
1615
diff
changeset
|
46 { 11,'d', "drop", "Use hard dropping (bailout on first mismatch)", OPT_NONE }, |
e7539466282b
Use OPT_* constants instead of 0/1.
Matti Hamalainen <ccr@tnsp.org>
parents:
1615
diff
changeset
|
47 { 10,'I', "initial", "Initial map file", OPT_ARGREQ }, |
e7539466282b
Use OPT_* constants instead of 0/1.
Matti Hamalainen <ccr@tnsp.org>
parents:
1615
diff
changeset
|
48 { 14,'x', "initial-x", "Initial map X offset", OPT_ARGREQ }, |
e7539466282b
Use OPT_* constants instead of 0/1.
Matti Hamalainen <ccr@tnsp.org>
parents:
1615
diff
changeset
|
49 { 15,'y', "initial-y", "Initial map Y offset", OPT_ARGREQ }, |
e7539466282b
Use OPT_* constants instead of 0/1.
Matti Hamalainen <ccr@tnsp.org>
parents:
1615
diff
changeset
|
50 { 16,'D', "dump", "Dump rejected pieces", OPT_NONE }, |
e7539466282b
Use OPT_* constants instead of 0/1.
Matti Hamalainen <ccr@tnsp.org>
parents:
1615
diff
changeset
|
51 { 17,'a', "adjust-size","Adjust to variable size blocks", OPT_NONE }, |
e7539466282b
Use OPT_* constants instead of 0/1.
Matti Hamalainen <ccr@tnsp.org>
parents:
1615
diff
changeset
|
52 { 18,'W', "walk-mode", "Walk mode (instead of ship mode)", OPT_NONE }, |
e7539466282b
Use OPT_* constants instead of 0/1.
Matti Hamalainen <ccr@tnsp.org>
parents:
1615
diff
changeset
|
53 { 19,'c', "clean-chars","Characters to filter from input", OPT_ARGREQ }, |
e7539466282b
Use OPT_* constants instead of 0/1.
Matti Hamalainen <ccr@tnsp.org>
parents:
1615
diff
changeset
|
54 { 20,'C', "center-char","Center character symbol (for -a)", OPT_ARGREQ }, |
28 | 55 }; |
56 | |
1484
2350cd3a6feb
Update to match the changes in th_args API.
Matti Hamalainen <ccr@tnsp.org>
parents:
1314
diff
changeset
|
57 static const int optListN = sizeof(optList) / sizeof(optList[0]); |
28 | 58 |
59 | |
60 void argShowHelp() | |
61 { | |
1249 | 62 th_print_banner(stdout, th_prog_name, |
714 | 63 "[options] <inputfile> [inputfile#2..]"); |
1249 | 64 |
1484
2350cd3a6feb
Update to match the changes in th_args API.
Matti Hamalainen <ccr@tnsp.org>
parents:
1314
diff
changeset
|
65 th_args_help(stdout, optList, optListN, 0); |
28 | 66 } |
67 | |
68 | |
65
cceeafe5b400
Use standard types and th-lib types instead of D*
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
69 BOOL argHandleOpt(const int optN, char *optArg, char *currArg) |
28 | 70 { |
1314
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
71 switch (optN) |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
72 { |
714 | 73 case 0: |
74 argShowHelp(); | |
75 exit(0); | |
76 break; | |
28 | 77 |
714 | 78 case 1: |
79 destFile = optArg; | |
80 THMSG(1, "Output file '%s'\n", destFile); | |
81 break; | |
28 | 82 |
714 | 83 case 2: |
84 th_verbosityLevel++; | |
85 break; | |
1543 | 86 |
714 | 87 case 3: |
88 th_verbosityLevel = -1; | |
89 break; | |
1543 | 90 |
714 | 91 case 4: |
92 optMatch = atof(optArg); | |
93 THMSG(1, "Match at %1.4f%%\n", optMatch); | |
94 break; | |
28 | 95 |
714 | 96 case 5: |
97 optRounds = atoi(optArg); | |
98 THMSG(1, "Processing rounds timeout %d\n", optRounds); | |
99 break; | |
28 | 100 |
714 | 101 case 12: |
102 optReset = atoi(optArg); | |
103 THMSG(1, "Round reset after %d blocks\n", optReset); | |
104 break; | |
31 | 105 |
714 | 106 case 10: |
107 optInitialMap = optArg; | |
108 THMSG(1, "Using initial map file = '%s'\n", optArg); | |
109 break; | |
28 | 110 |
714 | 111 case 11: |
112 optHardDrop = TRUE; | |
113 THMSG(1, "Using hard dropping (instant bailout on mismatch).\n"); | |
114 break; | |
28 | 115 |
714 | 116 case 14: |
117 optInitialX = atoi(optArg); | |
118 THMSG(1, "Initial map X offset = %d\n", optInitialX); | |
119 break; | |
73 | 120 |
714 | 121 case 15: |
122 optInitialY = atoi(optArg); | |
123 THMSG(1, "Initial map Y offset = %d\n", optInitialY); | |
124 break; | |
1543 | 125 |
714 | 126 case 16: |
127 THMSG(1, "Dumping rejected blocks.\n"); | |
128 optDumpRejected = TRUE; | |
129 break; | |
73 | 130 |
714 | 131 case 17: |
132 THMSG(1, "Handling variable size blocks via adjustment.\n"); | |
133 optAdjustBlocks = TRUE; | |
134 break; | |
216 | 135 |
714 | 136 case 18: |
137 THMSG(1, "Walk mode enabled.\n"); | |
138 optWalkMode = TRUE; | |
139 break; | |
261
7f08145f4cc1
Added mode changing option for ship/walk map blocks.
Matti Hamalainen <ccr@tnsp.org>
parents:
253
diff
changeset
|
140 |
714 | 141 case 19: |
142 optCleanChars = optArg; | |
143 THMSG(1, "Removing '%s' from input blocks\n", optArg); | |
144 break; | |
400 | 145 |
714 | 146 case 20: |
1314
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
147 if (strlen(optArg) != 1) |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
148 { |
714 | 149 THERR("Invalid argument '%s' for -C, only one character symbol can be specified.\n", optArg); |
150 return FALSE; | |
1314
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
151 } |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
152 else |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
153 { |
714 | 154 optCenterCh = optArg[0]; |
155 THMSG(1, "Using '%c' as centering character symbol\n", optCenterCh); | |
156 } | |
157 break; | |
400 | 158 |
714 | 159 default: |
160 THERR("Unknown option '%s'.\n", currArg); | |
161 return FALSE; | |
162 break; | |
163 } | |
1543 | 164 |
714 | 165 return TRUE; |
28 | 166 } |
167 | |
168 | |
65
cceeafe5b400
Use standard types and th-lib types instead of D*
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
169 BOOL argHandleFile(char *currArg) |
28 | 170 { |
1314
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
171 if (nsrcFiles < MAX_FILES) |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
172 { |
714 | 173 srcFiles[nsrcFiles] = currArg; |
174 nsrcFiles++; | |
1314
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
175 } |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
176 else |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
177 { |
714 | 178 THERR("Too many input files specified (%d max)!\n", MAX_FILES); |
179 return FALSE; | |
180 } | |
1543 | 181 |
714 | 182 return TRUE; |
28 | 183 } |
184 | |
185 | |
186 /* Calculate matching percentage of given block against a map, | |
187 * with using specified x/y offsets. | |
188 */ | |
1309
5cd310e1dab9
Rename some structures/data types.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
189 float matchBlock(MapBlock *map, MapBlock *match, int ox, int oy, BOOL hardDrop) |
28 | 190 { |
714 | 191 int x, y, c1, c2, dy, dx, n, k; |
28 | 192 |
714 | 193 n = k = 0; |
1543 | 194 |
1314
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
195 for (y = 0; y < match->height; y++) |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
196 for (x = 0; x < match->width; x++) |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
197 { |
714 | 198 dx = (ox + x); |
199 dy = (oy + y); | |
200 k++; | |
1543 | 201 |
1314
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
202 if (dx >= 0 && dx < map->width && dy >= 0 && dy < map->height) |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
203 c2 = map->data[(dy * map->scansize) + dx]; |
714 | 204 else |
205 c2 = 0; | |
1543 | 206 |
1314
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
207 c1 = match->data[(y * match->scansize) + x]; |
31 | 208 |
1314
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
209 if (c1 == 0 || c2 == 0) |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
210 { |
1770 | 211 // Both empty ... |
714 | 212 } else |
1314
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
213 if (c1 != 0 && c1 == c2) |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
214 { |
1770 | 215 // Exact match, increase % |
714 | 216 n++; |
217 } else | |
1314
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
218 if (hardDrop) |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
219 { |
1770 | 220 // Mismatch, return failure |
714 | 221 return -1; |
222 } | |
223 } | |
1543 | 224 |
714 | 225 if (k > 0) |
226 return ((float) n * 100.0f) / (float) k; | |
227 else | |
228 return 0.0f; | |
28 | 229 } |
230 | |
231 | |
1309
5cd310e1dab9
Rename some structures/data types.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
232 BOOL adjustBlockCenter(MapBlock *block, char centerCh) |
216 | 233 { |
714 | 234 int x, y, c; |
216 | 235 |
1314
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
236 for (y = 0; y < block->height; y++) |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
237 for (x = 0; x < block->width; x++) |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
238 { |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
239 c = block->data[(y * block->scansize) + x]; |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
240 if (c == centerCh) |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
241 { |
714 | 242 block->x -= x; |
243 block->y -= y; | |
244 return TRUE; | |
245 } | |
246 } | |
216 | 247 |
714 | 248 return FALSE; |
216 | 249 } |
250 | |
251 | |
28 | 252 /* Parse next block (marked by string optPattern) from |
253 * input stream into a mapblock, return NULL if not found or error. | |
254 */ | |
682
21ba542749b7
Improvements in mkspecial to handle the new output from 'map' command in city controller, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
255 BOOL getLineData(FILE *inFile, char *buf, size_t bufSize) |
21ba542749b7
Improvements in mkspecial to handle the new output from 'map' command in city controller, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
256 { |
1314
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
257 if (feof(inFile) || !fgets(buf, bufSize, inFile)) |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
258 { |
714 | 259 THERR("Unexpected end of file.\n"); |
260 return FALSE; | |
1314
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
261 } |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
262 else |
714 | 263 return TRUE; |
682
21ba542749b7
Improvements in mkspecial to handle the new output from 'map' command in city controller, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
264 } |
21ba542749b7
Improvements in mkspecial to handle the new output from 'map' command in city controller, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
265 |
21ba542749b7
Improvements in mkspecial to handle the new output from 'map' command in city controller, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
266 int getLineWidth(char *buf, size_t bufSize) |
21ba542749b7
Improvements in mkspecial to handle the new output from 'map' command in city controller, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
267 { |
714 | 268 size_t width; |
1543 | 269 |
714 | 270 for (width = 0; width < bufSize && buf[width] && buf[width] != '\r' && buf[width] != '\n'; width++); |
271 buf[width] = 0; | |
1543 | 272 |
714 | 273 return width; |
682
21ba542749b7
Improvements in mkspecial to handle the new output from 'map' command in city controller, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
274 } |
21ba542749b7
Improvements in mkspecial to handle the new output from 'map' command in city controller, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
275 |
1309
5cd310e1dab9
Rename some structures/data types.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
276 MapBlock * parseBlock(FILE *inFile) |
28 | 277 { |
1309
5cd310e1dab9
Rename some structures/data types.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
278 MapBlock *tmp; |
1314
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
279 int x, y, tmpW, tmpH; |
714 | 280 uint_t i; |
281 BOOL isFound; | |
282 char s[4096], *p = NULL; | |
1543 | 283 |
714 | 284 isFound = FALSE; |
1314
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
285 while (!feof(inFile) && !isFound && fgets(s, sizeof(s), inFile)) |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
286 { |
1276
472316d37c30
Improve support for HCbat mapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
1249
diff
changeset
|
287 if ((p = strstr(s, ": !!PLR: ")) != NULL && (strstr(s, "party") || strstr(s, "report"))) |
714 | 288 isFound = TRUE; |
289 } | |
1543 | 290 |
1314
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
291 if (!isFound) |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
292 { |
714 | 293 THERR("No block start marker found.\n"); |
294 return NULL; | |
295 } | |
1543 | 296 |
714 | 297 for (i = 0; i < sizeof(s) && s[i] && s[i] != '\r' && s[i] != '\n'; i++); |
298 s[i] = 0; | |
1543 | 299 |
1314
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
300 if (sscanf(p, ": !!PLR: %d,%d", &x, &y) < 2) |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
301 { |
714 | 302 THERR("Could not get location coordinates:\n'%s'\n", s); |
303 return NULL; | |
304 } | |
216 | 305 |
1770 | 306 // Check for discardable lines |
714 | 307 if (!getLineData(inFile, s, sizeof(s))) |
308 return NULL; | |
1224
f7da9eaa149a
Added ignoring of some lines in.
Matti Hamalainen <ccr@tnsp.org>
parents:
1162
diff
changeset
|
309 |
1563 | 310 if (!th_strcasecmp(s, "You glance around.")) |
1314
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
311 { |
1224
f7da9eaa149a
Added ignoring of some lines in.
Matti Hamalainen <ccr@tnsp.org>
parents:
1162
diff
changeset
|
312 if (!getLineData(inFile, s, sizeof(s))) |
f7da9eaa149a
Added ignoring of some lines in.
Matti Hamalainen <ccr@tnsp.org>
parents:
1162
diff
changeset
|
313 return NULL; |
f7da9eaa149a
Added ignoring of some lines in.
Matti Hamalainen <ccr@tnsp.org>
parents:
1162
diff
changeset
|
314 } |
f7da9eaa149a
Added ignoring of some lines in.
Matti Hamalainen <ccr@tnsp.org>
parents:
1162
diff
changeset
|
315 |
1770 | 316 // New 'map' output in city maps has an empty line before the data, ignore it |
1314
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
317 if ((tmpW = getLineWidth(s, sizeof(s))) <= 9) |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
318 { |
714 | 319 if (!getLineData(inFile, s, sizeof(s))) |
320 return NULL; | |
321 tmpW = getLineWidth(s, sizeof(s)); | |
322 } | |
1543 | 323 |
714 | 324 if (optWalkMode) { |
325 switch (tmpW) { | |
326 case 31: tmpH = 17; break; | |
327 case 13: tmpH = 7; break; | |
328 case 9: tmpH = 9; break; | |
329 default: | |
330 THERR("Invalid block width %d [%d, %d], rejecting.\n", tmpW, x, y); | |
331 return NULL; | |
332 break; | |
333 } | |
334 } else | |
335 tmpH = tmpW - 8; | |
1543 | 336 |
1310
a6be5a68032f
Rename map block handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1309
diff
changeset
|
337 if ((tmp = mapBlockAlloc(tmpW, tmpH)) == NULL) { |
714 | 338 THERR("Could not allocate mapblock (%d, %d)\n", tmpW, tmpH); |
339 return NULL; | |
340 } | |
1543 | 341 |
714 | 342 tmp->x = x; |
343 tmp->y = y; | |
1543 | 344 |
1314
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
345 y = 0; |
714 | 346 do { |
347 i = getLineWidth(s, tmpW); | |
1543 | 348 |
1314
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
349 if (i != (uint_t) tmp->width) |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
350 { |
714 | 351 THERR("Broken block, line width %d != %d!\n", |
1314
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
352 i, tmp->width, s); |
1310
a6be5a68032f
Rename map block handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1309
diff
changeset
|
353 mapBlockFree(tmp); |
714 | 354 return NULL; |
355 } | |
1543 | 356 |
1314
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
357 for (x = 0; x < tmp->width; x++) |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
358 { |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
359 tmp->data[(y * tmp->scansize) + x] = s[x]; |
714 | 360 } |
1543 | 361 |
714 | 362 y++; |
1314
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
363 } while (!feof(inFile) && (y < tmp->height) && fgets(s, sizeof(s), inFile)); |
1543 | 364 |
365 | |
1314
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
366 if (y < tmp->height) |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
367 { |
714 | 368 THERR("Broken block, height %d < %d\n", |
1314
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
369 y, tmp->height); |
1310
a6be5a68032f
Rename map block handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1309
diff
changeset
|
370 mapBlockFree(tmp); |
714 | 371 return NULL; |
372 } | |
1543 | 373 |
714 | 374 return tmp; |
28 | 375 } |
376 | |
377 | |
457 | 378 /* Find the min/max of given coordinates. |
45 | 379 */ |
1309
5cd310e1dab9
Rename some structures/data types.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
380 void findWorldSize(MapBlock *tmp, |
714 | 381 int *worldX0, int *worldY0, |
382 int *worldX1, int *worldY1) | |
32 | 383 { |
714 | 384 if (tmp->x < *worldX0) *worldX0 = tmp->x; |
1314
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
385 if ((tmp->x + tmp->width) > *worldX1) *worldX1 = (tmp->x + tmp->width); |
32 | 386 |
714 | 387 if (tmp->y < *worldY0) *worldY0 = tmp->y; |
1314
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
388 if ((tmp->y + tmp->height) > *worldY1) *worldY1 = (tmp->y + tmp->height); |
32 | 389 } |
390 | |
391 | |
28 | 392 int main(int argc, char *argv[]) |
393 { | |
714 | 394 BOOL isOK; |
395 int i, currRounds, nmapBlocks, currBlocks, | |
396 worldX0, worldY0, worldX1, worldY1, | |
397 offsetX = 0, offsetY = 0; | |
1309
5cd310e1dab9
Rename some structures/data types.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
398 MapBlock *worldMap = NULL, *initialMap = NULL; |
5cd310e1dab9
Rename some structures/data types.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
399 MapBlock **mapBlocks = NULL; |
28 | 400 |
714 | 401 th_init("mkspecial", "Yet Another ASCII Map Auto-Stitcher", "0.5", NULL, NULL); |
402 th_verbosityLevel = 1; | |
1543 | 403 |
1770 | 404 // Parse arguments |
714 | 405 if (!th_args_process(argc, argv, optList, optListN, |
1484
2350cd3a6feb
Update to match the changes in th_args API.
Matti Hamalainen <ccr@tnsp.org>
parents:
1314
diff
changeset
|
406 argHandleOpt, argHandleFile, OPTH_BAILOUT)) |
714 | 407 exit(1); |
1543 | 408 |
1314
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
409 if (nsrcFiles < 1) |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
410 { |
714 | 411 THERR("Nothing to do. (try --help)\n"); |
412 exit(0); | |
413 } | |
1543 | 414 |
1770 | 415 // Read initial map |
1314
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
416 if (optInitialMap) |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
417 { |
714 | 418 THMSG(1, "Reading initial map '%s'\n", optInitialMap); |
1310
a6be5a68032f
Rename map block handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1309
diff
changeset
|
419 initialMap = mapBlockParseFile(optInitialMap, FALSE); |
1314
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
420 if (initialMap) |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
421 { |
714 | 422 THMSG(2, "Initial dimensions %d x %d\n", |
1314
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
423 initialMap->width, initialMap->height); |
221 | 424 |
1310
a6be5a68032f
Rename map block handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1309
diff
changeset
|
425 mapBlockClean(initialMap, " "); |
1314
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
426 } |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
427 else |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
428 { |
714 | 429 THERR("Initial map could not be loaded!\n"); |
430 exit(1); | |
431 } | |
432 } | |
1543 | 433 |
714 | 434 /* Read in continuous mapdata and parse it into map blocks |
435 */ | |
1314
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
436 for (nmapBlocks = i = 0; i < nsrcFiles; i++) |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
437 { |
714 | 438 FILE *tmpFile; |
439 char centerCh; | |
1543 | 440 |
1314
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
441 if (optCenterCh > 0) |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
442 { |
714 | 443 centerCh = optCenterCh; |
1314
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
444 } |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
445 else |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
446 { |
714 | 447 if (optWalkMode) |
448 centerCh = '@'; | |
449 else | |
450 centerCh = '*'; | |
451 } | |
1543 | 452 |
453 | |
454 | |
1314
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
455 if ((tmpFile = fopen(srcFiles[i], "rb")) == NULL) |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
456 { |
714 | 457 THERR("Error opening input file '%s'!\n", |
458 srcFiles[i]); | |
459 exit(1); | |
460 } | |
1543 | 461 |
1314
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
462 while (!feof(tmpFile)) |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
463 { |
1309
5cd310e1dab9
Rename some structures/data types.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
464 MapBlock *tmp; |
1314
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
465 if ((tmp = parseBlock(tmpFile)) != NULL) |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
466 { |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
467 if (optAdjustBlocks && !adjustBlockCenter(tmp, centerCh)) |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
468 { |
714 | 469 THERR("Block center not found, rejected.\n"); |
1310
a6be5a68032f
Rename map block handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1309
diff
changeset
|
470 mapBlockFree(tmp); |
1314
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
471 } |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
472 else |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
473 { |
714 | 474 nmapBlocks++; |
1309
5cd310e1dab9
Rename some structures/data types.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
475 mapBlocks = (MapBlock **) th_realloc(mapBlocks, sizeof(MapBlock *) * nmapBlocks); |
1314
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
476 if (!mapBlocks) |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
477 { |
714 | 478 fclose(tmpFile); |
479 THERR("Could not allocate/extend mapblock pointer structure (#%d)\n", nmapBlocks); | |
480 exit(3); | |
481 } | |
1310
a6be5a68032f
Rename map block handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1309
diff
changeset
|
482 |
a6be5a68032f
Rename map block handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1309
diff
changeset
|
483 mapBlockClean(tmp, optCleanChars); |
714 | 484 mapBlocks[nmapBlocks - 1] = tmp; |
485 } | |
486 } | |
487 } | |
1543 | 488 |
714 | 489 fclose(tmpFile); |
490 } | |
1543 | 491 |
714 | 492 THMSG(1, "Total of %d mapblocks read.\n", nmapBlocks); |
1543 | 493 |
1314
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
494 if (nmapBlocks <= 0) |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
495 { |
714 | 496 THERR("No mapblocks, nothing to do.\n"); |
497 exit(11); | |
498 } | |
32 | 499 |
28 | 500 |
714 | 501 /* ALGORITHM |
502 * --------- | |
503 find dimensions of the world map: | |
504 for (each block in list) { | |
505 if (block->x < mapx0) mapx0 = block->x; else | |
506 if (block->x+block->w > mapx1) mapx1 = block->x+block->w; | |
507 ... | |
508 } | |
1543 | 509 |
714 | 510 allocate map |
1543 | 511 |
714 | 512 start placing blocks: |
513 for (n = 0; n < rounds; n++) { | |
514 for (each block in list) { | |
515 if (check match % at given coordinates > threshold) | |
516 place block | |
517 } | |
28 | 518 |
714 | 519 if (all blocks placed) break |
520 } | |
521 */ | |
32 | 522 |
523 | |
1770 | 524 // If initial map is available, find a match and determine coords |
1314
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
525 if (initialMap) |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
526 { |
714 | 527 initialMap->x = optInitialX; |
528 initialMap->y = optInitialY; | |
529 } | |
1543 | 530 |
1770 | 531 // Clear marks |
714 | 532 for (i = 0; i < nmapBlocks; i++) |
533 mapBlocks[i]->mark = FALSE; | |
32 | 534 |
1543 | 535 |
1770 | 536 // Get world dimensions |
714 | 537 worldX0 = worldY0 = worldX1 = worldY1 = 0; |
538 for (i = 0; i < nmapBlocks; i++) | |
539 findWorldSize(mapBlocks[i], &worldX0, &worldY0, &worldX1, &worldY1); | |
1543 | 540 |
714 | 541 if (initialMap) |
542 findWorldSize(initialMap, &worldX0, &worldY0, &worldX1, &worldY1); | |
1543 | 543 |
1770 | 544 // Compute offsets, allocate world map |
545 // FIXME: check dimensions | |
714 | 546 offsetX = -worldX0; |
547 offsetY = -worldY0; | |
32 | 548 |
1314
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
549 if ((worldMap = mapBlockAlloc((worldX1 - worldX0 + 1), (worldY1 - worldY0 + 1))) == NULL) |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
550 { |
714 | 551 THERR("Error allocating world map!\n"); |
552 exit(4); | |
553 } | |
1543 | 554 |
1770 | 555 // Place optional initial map |
1314
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
556 if (initialMap) |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
557 { |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
558 if (mapBlockPut(&worldMap, initialMap, offsetX+initialMap->x, offsetY+initialMap->y) < 0) |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
559 { |
1310
a6be5a68032f
Rename map block handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1309
diff
changeset
|
560 THERR("Initial map mapBlockPut() failed!\n"); |
714 | 561 exit(9); |
562 } | |
1314
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
563 } |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
564 else |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
565 { |
714 | 566 i = 0; |
1314
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
567 if (mapBlockPut(&worldMap, mapBlocks[i], offsetX+mapBlocks[i]->x, offsetY+mapBlocks[i]->y) < 0) |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
568 { |
1310
a6be5a68032f
Rename map block handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1309
diff
changeset
|
569 THERR("Initial map mapBlockPut() failed!\n"); |
714 | 570 exit(9); |
571 } | |
1770 | 572 mapBlocks[i]->mark = TRUE; |
714 | 573 } |
28 | 574 |
714 | 575 THMSG(1, "Initialized world map of (%d x %d), offset (%d, %d)\n", |
1314
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
576 worldMap->width, worldMap->height, offsetX, offsetY); |
28 | 577 |
32 | 578 |
1770 | 579 // Start placing blocks |
714 | 580 currRounds = 0; |
581 isOK = FALSE; | |
1770 | 582 while (currRounds++ < optRounds && !isOK) |
1314
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
583 { |
714 | 584 int usedBlocks; |
1543 | 585 |
1770 | 586 // Get number of used blocks |
714 | 587 for (usedBlocks = i = 0; i < nmapBlocks; i++) |
588 if (mapBlocks[i]->mark) usedBlocks++; | |
1543 | 589 |
1770 | 590 // Print out status information |
714 | 591 THPRINT(2, "#%d [%d/%d]: ", |
592 currRounds, usedBlocks, nmapBlocks); | |
1543 | 593 |
1770 | 594 // Place and match blocks |
714 | 595 isOK = TRUE; |
596 currBlocks = 0; | |
1314
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
597 for (i = 0; i < nmapBlocks && currBlocks < optReset; i++) |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
598 { |
1309
5cd310e1dab9
Rename some structures/data types.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
599 MapBlock *tmp = mapBlocks[i]; |
1543 | 600 |
1314
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
601 if (!tmp->mark) |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
602 { |
1770 | 603 int qx = offsetX + tmp->x, |
714 | 604 qy = offsetY + tmp->y; |
31 | 605 |
714 | 606 isOK = FALSE; |
31 | 607 |
1314
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
608 if (matchBlock(worldMap, tmp, qx, qy, optHardDrop) >= optMatch) |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
609 { |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
610 if (mapBlockPut(&worldMap, tmp, qx, qy) < 0) |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
611 { |
1310
a6be5a68032f
Rename map block handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1309
diff
changeset
|
612 THERR("mapBlockPut(%d, %d, %d) failed!\n", |
714 | 613 offsetX, offsetY, i); |
614 exit(9); | |
615 } | |
1770 | 616 tmp->mark = TRUE; |
1543 | 617 |
714 | 618 currBlocks++; |
619 THPRINT(2, "X"); | |
1314
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
620 } |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
621 else |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
622 { |
714 | 623 THPRINT(2, "."); |
32 | 624 |
625 #if 0 | |
1770 | 626 // Debug unmatching blocks |
714 | 627 char mysti[512]; |
628 snprintf(mysti, sizeof(mysti), | |
629 "[%d]: %d,%d (%d,%d)", | |
630 i, qx, qy, tmp->x, tmp->y); | |
631 fprintf(stderr, "\n--- %.30s ---\n", mysti); | |
1310
a6be5a68032f
Rename map block handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1309
diff
changeset
|
632 mapBlockPrint(stderr, tmp); |
714 | 633 fprintf(stderr, "---------\n"); |
1310
a6be5a68032f
Rename map block handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1309
diff
changeset
|
634 mapBlockPrint(stderr, worldMap); |
31 | 635 #endif |
714 | 636 } |
637 } | |
638 } | |
1543 | 639 |
714 | 640 THPRINT(2, "\n"); |
641 } | |
28 | 642 |
714 | 643 /* Output generated map |
644 */ | |
1647
e7539466282b
Use OPT_* constants instead of 0/1.
Matti Hamalainen <ccr@tnsp.org>
parents:
1615
diff
changeset
|
645 if (worldMap) |
e7539466282b
Use OPT_* constants instead of 0/1.
Matti Hamalainen <ccr@tnsp.org>
parents:
1615
diff
changeset
|
646 { |
714 | 647 int unusedBlocks; |
648 FILE *tmpFile; | |
1543 | 649 |
714 | 650 THMSG(1, "Outputting generated map of (%d x %d) ...\n", |
1314
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
651 worldMap->width, worldMap->height); |
29 | 652 |
714 | 653 if (destFile == NULL) |
654 tmpFile = stdout; | |
1692 | 655 else |
656 if ((tmpFile = fopen(destFile, "wb")) == NULL) { | |
714 | 657 THERR("Error opening output file '%s'!\n", |
658 destFile); | |
659 exit(1); | |
660 } | |
1543 | 661 |
1310
a6be5a68032f
Rename map block handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1309
diff
changeset
|
662 mapBlockPrint(tmpFile, worldMap); |
1543 | 663 |
714 | 664 fclose(tmpFile); |
1543 | 665 |
1770 | 666 // Compute number of unused blocks |
714 | 667 for (unusedBlocks = i = 0; i < nmapBlocks; i++) |
1770 | 668 if (!mapBlocks[i]->mark) |
669 { | |
670 if (optDumpRejected) | |
1314
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
671 { |
1770 | 672 fprintf(stderr, "\n#%d: %d,%d (%d,%d)\n", |
673 i, mapBlocks[i]->x, mapBlocks[i]->y, | |
674 mapBlocks[i]->x + offsetX, | |
675 mapBlocks[i]->y + offsetY); | |
1543 | 676 |
1770 | 677 mapBlockPrint(stderr, mapBlocks[i]); |
714 | 678 } |
1770 | 679 unusedBlocks++; |
680 } | |
1543 | 681 |
714 | 682 THMSG(1, "%d mapblocks unused/discarded\n", unusedBlocks); |
1314
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
683 } |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
684 else |
5d6ddd4d6781
Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
1310
diff
changeset
|
685 { |
714 | 686 THERR("No map generated?\n"); |
687 } | |
1543 | 688 |
714 | 689 return 0; |
28 | 690 } |