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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
28
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /*
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 * mkspecial - Compute complete ASCII map by stitching pieces
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 * together based on a matcher and coordinates
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 *
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 * Programmed by Matti 'ccr' Hämäläinen (Ggr Pupunen)
1487
e72577821dc6 Update copyrights.
Matti Hamalainen <ccr@tnsp.org>
parents: 1484
diff changeset
6 * (C) Copyright 2006-2015 Tecnic Software productions (TNSP)
28
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 #include "th_args.h"
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 #include "th_string.h"
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
12 #define MAX_FILES (256)
28
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15 /* Variables
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16 */
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
17 int nsrcFiles = 0;
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
18 char *srcFiles[MAX_FILES],
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
19 *destFile = NULL;
28
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
21 int optInitialX = 0,
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
22 optInitialY = 0,
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
23 optMapFactor = 10,
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
24 optRounds = 100,
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
25 optReset = 50;
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
26 BOOL optHardDrop = FALSE,
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
27 optDumpRejected = FALSE,
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
28 optAdjustBlocks = FALSE,
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
29 optWalkMode = FALSE;
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
30 float optMatch = 40.0;
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
31 char *optInitialMap = NULL,
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
32 *optCleanChars = " *@",
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
33 optCenterCh = -1;
28
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34
61
4efae5dae2e3 th_args_process() transition.
Matti Hamalainen <ccr@tnsp.org>
parents: 45
diff changeset
35
28
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36 /* Arguments
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37 */
1615
582675ccc3e6 Match th_args API change.
Matti Hamalainen <ccr@tnsp.org>
parents: 1563
diff changeset
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
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 };
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60 void argShowHelp()
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61 {
1249
0dad7911e251 Sync th-lib changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1224
diff changeset
62 th_print_banner(stdout, th_prog_name,
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
63 "[options] <inputfile> [inputfile#2..]");
1249
0dad7911e251 Sync th-lib changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1224
diff changeset
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
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66 }
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
73 case 0:
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
74 argShowHelp();
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
75 exit(0);
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
76 break;
28
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
78 case 1:
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
79 destFile = optArg;
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
80 THMSG(1, "Output file '%s'\n", destFile);
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
81 break;
28
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
83 case 2:
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
84 th_verbosityLevel++;
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
85 break;
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
86
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
87 case 3:
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
88 th_verbosityLevel = -1;
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
89 break;
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
90
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
91 case 4:
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
92 optMatch = atof(optArg);
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
93 THMSG(1, "Match at %1.4f%%\n", optMatch);
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
94 break;
28
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
96 case 5:
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
97 optRounds = atoi(optArg);
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
98 THMSG(1, "Processing rounds timeout %d\n", optRounds);
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
99 break;
28
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
101 case 12:
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
102 optReset = atoi(optArg);
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
103 THMSG(1, "Round reset after %d blocks\n", optReset);
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
104 break;
31
Matti Hamalainen <ccr@tnsp.org>
parents: 29
diff changeset
105
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
106 case 10:
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
107 optInitialMap = optArg;
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
108 THMSG(1, "Using initial map file = '%s'\n", optArg);
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
109 break;
28
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
110
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
111 case 11:
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
112 optHardDrop = TRUE;
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
113 THMSG(1, "Using hard dropping (instant bailout on mismatch).\n");
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
114 break;
28
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
115
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
116 case 14:
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
117 optInitialX = atoi(optArg);
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
118 THMSG(1, "Initial map X offset = %d\n", optInitialX);
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
119 break;
73
8bad1e87b45d Updates
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
120
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
121 case 15:
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
122 optInitialY = atoi(optArg);
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
123 THMSG(1, "Initial map Y offset = %d\n", optInitialY);
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
124 break;
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
125
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
126 case 16:
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
127 THMSG(1, "Dumping rejected blocks.\n");
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
128 optDumpRejected = TRUE;
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
129 break;
73
8bad1e87b45d Updates
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
130
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
131 case 17:
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
132 THMSG(1, "Handling variable size blocks via adjustment.\n");
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
133 optAdjustBlocks = TRUE;
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
134 break;
216
3c3c73273570 Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 209
diff changeset
135
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
136 case 18:
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
137 THMSG(1, "Walk mode enabled.\n");
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
138 optWalkMode = TRUE;
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
139 break;
261
7f08145f4cc1 Added mode changing option for ship/walk map blocks.
Matti Hamalainen <ccr@tnsp.org>
parents: 253
diff changeset
140
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
141 case 19:
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
142 optCleanChars = optArg;
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
143 THMSG(1, "Removing '%s' from input blocks\n", optArg);
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
144 break;
400
2cf90048fc6a New options.
Matti Hamalainen <ccr@tnsp.org>
parents: 322
diff changeset
145
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
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
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
149 THERR("Invalid argument '%s' for -C, only one character symbol can be specified.\n", optArg);
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
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
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
154 optCenterCh = optArg[0];
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
155 THMSG(1, "Using '%c' as centering character symbol\n", optCenterCh);
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
156 }
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
157 break;
400
2cf90048fc6a New options.
Matti Hamalainen <ccr@tnsp.org>
parents: 322
diff changeset
158
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
159 default:
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
160 THERR("Unknown option '%s'.\n", currArg);
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
161 return FALSE;
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
162 break;
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
163 }
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
164
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
165 return TRUE;
28
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
166 }
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
167
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
173 srcFiles[nsrcFiles] = currArg;
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
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
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
178 THERR("Too many input files specified (%d max)!\n", MAX_FILES);
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
179 return FALSE;
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
180 }
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
181
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
182 return TRUE;
28
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
183 }
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
184
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
185
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
186 /* Calculate matching percentage of given block against a map,
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
187 * with using specified x/y offsets.
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
190 {
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
191 int x, y, c1, c2, dy, dx, n, k;
28
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
192
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
193 n = k = 0;
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
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
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
198 dx = (ox + x);
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
199 dy = (oy + y);
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
200 k++;
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
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
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
204 else
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
205 c2 = 0;
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
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
Matti Hamalainen <ccr@tnsp.org>
parents: 29
diff changeset
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
cc59f80b0e78 Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1692
diff changeset
211 // Both empty ...
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
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
cc59f80b0e78 Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1692
diff changeset
215 // Exact match, increase %
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
216 n++;
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
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
cc59f80b0e78 Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1692
diff changeset
220 // Mismatch, return failure
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
221 return -1;
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
222 }
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
223 }
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
224
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
225 if (k > 0)
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
226 return ((float) n * 100.0f) / (float) k;
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
227 else
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
228 return 0.0f;
28
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
229 }
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
230
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
3c3c73273570 Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 209
diff changeset
233 {
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
234 int x, y, c;
216
3c3c73273570 Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 209
diff changeset
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
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
242 block->x -= x;
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
243 block->y -= y;
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
244 return TRUE;
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
245 }
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
246 }
216
3c3c73273570 Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 209
diff changeset
247
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
248 return FALSE;
216
3c3c73273570 Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 209
diff changeset
249 }
3c3c73273570 Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 209
diff changeset
250
3c3c73273570 Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 209
diff changeset
251
28
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
252 /* Parse next block (marked by string optPattern) from
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
253 * input stream into a mapblock, return NULL if not found or error.
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
259 THERR("Unexpected end of file.\n");
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
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
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
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
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
268 size_t width;
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
269
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
270 for (width = 0; width < bufSize && buf[width] && buf[width] != '\r' && buf[width] != '\n'; width++);
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
271 buf[width] = 0;
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
272
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
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
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
280 uint_t i;
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
281 BOOL isFound;
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
282 char s[4096], *p = NULL;
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
283
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
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
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
288 isFound = TRUE;
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
289 }
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
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
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
293 THERR("No block start marker found.\n");
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
294 return NULL;
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
295 }
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
296
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
297 for (i = 0; i < sizeof(s) && s[i] && s[i] != '\r' && s[i] != '\n'; i++);
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
298 s[i] = 0;
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
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
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
302 THERR("Could not get location coordinates:\n'%s'\n", s);
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
303 return NULL;
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
304 }
216
3c3c73273570 Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 209
diff changeset
305
1770
cc59f80b0e78 Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1692
diff changeset
306 // Check for discardable lines
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
307 if (!getLineData(inFile, s, sizeof(s)))
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
308 return NULL;
1224
f7da9eaa149a Added ignoring of some lines in.
Matti Hamalainen <ccr@tnsp.org>
parents: 1162
diff changeset
309
1563
1e33613c1979 Portability fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1543
diff changeset
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
cc59f80b0e78 Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1692
diff changeset
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
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
319 if (!getLineData(inFile, s, sizeof(s)))
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
320 return NULL;
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
321 tmpW = getLineWidth(s, sizeof(s));
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
322 }
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
323
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
324 if (optWalkMode) {
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
325 switch (tmpW) {
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
326 case 31: tmpH = 17; break;
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
327 case 13: tmpH = 7; break;
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
328 case 9: tmpH = 9; break;
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
329 default:
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
330 THERR("Invalid block width %d [%d, %d], rejecting.\n", tmpW, x, y);
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
331 return NULL;
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
332 break;
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
333 }
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
334 } else
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
335 tmpH = tmpW - 8;
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
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
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
338 THERR("Could not allocate mapblock (%d, %d)\n", tmpW, tmpH);
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
339 return NULL;
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
340 }
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
341
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
342 tmp->x = x;
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
343 tmp->y = y;
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
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
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
346 do {
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
347 i = getLineWidth(s, tmpW);
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
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
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
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
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
354 return NULL;
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
355 }
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
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
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
360 }
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
361
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
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
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
364
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
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
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
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
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
371 return NULL;
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
372 }
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
373
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
374 return tmp;
28
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
375 }
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
376
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
377
457
dae2cb64f993 Fix two warnings.
Matti Hamalainen <ccr@tnsp.org>
parents: 400
diff changeset
378 /* Find the min/max of given coordinates.
45
df05fc552cc3 Cleanups
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
379 */
1309
5cd310e1dab9 Rename some structures/data types.
Matti Hamalainen <ccr@tnsp.org>
parents: 1308
diff changeset
380 void findWorldSize(MapBlock *tmp,
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
381 int *worldX0, int *worldY0,
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
382 int *worldX1, int *worldY1)
32
c41ec03eac99 Updates, fixes
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
383 {
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
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
c41ec03eac99 Updates, fixes
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
386
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
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
c41ec03eac99 Updates, fixes
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
389 }
c41ec03eac99 Updates, fixes
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
390
c41ec03eac99 Updates, fixes
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
391
28
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
392 int main(int argc, char *argv[])
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
393 {
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
394 BOOL isOK;
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
395 int i, currRounds, nmapBlocks, currBlocks,
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
396 worldX0, worldY0, worldX1, worldY1,
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
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
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
400
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
401 th_init("mkspecial", "Yet Another ASCII Map Auto-Stitcher", "0.5", NULL, NULL);
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
402 th_verbosityLevel = 1;
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
403
1770
cc59f80b0e78 Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1692
diff changeset
404 // Parse arguments
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
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
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
407 exit(1);
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
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
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
411 THERR("Nothing to do. (try --help)\n");
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
412 exit(0);
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
413 }
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
414
1770
cc59f80b0e78 Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1692
diff changeset
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
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
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
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
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
d8c4932a03b7 Improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 216
diff changeset
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
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
429 THERR("Initial map could not be loaded!\n");
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
430 exit(1);
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
431 }
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
432 }
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
433
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
434 /* Read in continuous mapdata and parse it into map blocks
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
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
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
438 FILE *tmpFile;
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
439 char centerCh;
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
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
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
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
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
447 if (optWalkMode)
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
448 centerCh = '@';
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
449 else
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
450 centerCh = '*';
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
451 }
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
452
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
453
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
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
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
457 THERR("Error opening input file '%s'!\n",
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
458 srcFiles[i]);
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
459 exit(1);
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
460 }
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
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
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
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
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
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
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
478 fclose(tmpFile);
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
479 THERR("Could not allocate/extend mapblock pointer structure (#%d)\n", nmapBlocks);
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
480 exit(3);
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
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
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
484 mapBlocks[nmapBlocks - 1] = tmp;
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
485 }
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
486 }
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
487 }
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
488
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
489 fclose(tmpFile);
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
490 }
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
491
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
492 THMSG(1, "Total of %d mapblocks read.\n", nmapBlocks);
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
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
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
496 THERR("No mapblocks, nothing to do.\n");
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
497 exit(11);
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
498 }
32
c41ec03eac99 Updates, fixes
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
499
28
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
500
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
501 /* ALGORITHM
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
502 * ---------
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
503 find dimensions of the world map:
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
504 for (each block in list) {
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
505 if (block->x < mapx0) mapx0 = block->x; else
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
506 if (block->x+block->w > mapx1) mapx1 = block->x+block->w;
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
507 ...
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
508 }
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
509
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
510 allocate map
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
511
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
512 start placing blocks:
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
513 for (n = 0; n < rounds; n++) {
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
514 for (each block in list) {
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
515 if (check match % at given coordinates > threshold)
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
516 place block
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
517 }
28
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
518
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
519 if (all blocks placed) break
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
520 }
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
521 */
32
c41ec03eac99 Updates, fixes
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
522
c41ec03eac99 Updates, fixes
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
523
1770
cc59f80b0e78 Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1692
diff changeset
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
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
527 initialMap->x = optInitialX;
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
528 initialMap->y = optInitialY;
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
529 }
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
530
1770
cc59f80b0e78 Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1692
diff changeset
531 // Clear marks
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
532 for (i = 0; i < nmapBlocks; i++)
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
533 mapBlocks[i]->mark = FALSE;
32
c41ec03eac99 Updates, fixes
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
534
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
535
1770
cc59f80b0e78 Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1692
diff changeset
536 // Get world dimensions
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
537 worldX0 = worldY0 = worldX1 = worldY1 = 0;
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
538 for (i = 0; i < nmapBlocks; i++)
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
539 findWorldSize(mapBlocks[i], &worldX0, &worldY0, &worldX1, &worldY1);
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
540
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
541 if (initialMap)
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
542 findWorldSize(initialMap, &worldX0, &worldY0, &worldX1, &worldY1);
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
543
1770
cc59f80b0e78 Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1692
diff changeset
544 // Compute offsets, allocate world map
cc59f80b0e78 Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1692
diff changeset
545 // FIXME: check dimensions
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
546 offsetX = -worldX0;
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
547 offsetY = -worldY0;
32
c41ec03eac99 Updates, fixes
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
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
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
551 THERR("Error allocating world map!\n");
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
552 exit(4);
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
553 }
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
554
1770
cc59f80b0e78 Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1692
diff changeset
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
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
561 exit(9);
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
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
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
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
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
570 exit(9);
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
571 }
1770
cc59f80b0e78 Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1692
diff changeset
572 mapBlocks[i]->mark = TRUE;
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
573 }
28
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
574
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
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
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
577
32
c41ec03eac99 Updates, fixes
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
578
1770
cc59f80b0e78 Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1692
diff changeset
579 // Start placing blocks
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
580 currRounds = 0;
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
581 isOK = FALSE;
1770
cc59f80b0e78 Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1692
diff changeset
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
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
584 int usedBlocks;
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
585
1770
cc59f80b0e78 Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1692
diff changeset
586 // Get number of used blocks
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
587 for (usedBlocks = i = 0; i < nmapBlocks; i++)
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
588 if (mapBlocks[i]->mark) usedBlocks++;
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
589
1770
cc59f80b0e78 Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1692
diff changeset
590 // Print out status information
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
591 THPRINT(2, "#%d [%d/%d]: ",
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
592 currRounds, usedBlocks, nmapBlocks);
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
593
1770
cc59f80b0e78 Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1692
diff changeset
594 // Place and match blocks
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
595 isOK = TRUE;
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
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
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
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
cc59f80b0e78 Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1692
diff changeset
603 int qx = offsetX + tmp->x,
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
604 qy = offsetY + tmp->y;
31
Matti Hamalainen <ccr@tnsp.org>
parents: 29
diff changeset
605
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
606 isOK = FALSE;
31
Matti Hamalainen <ccr@tnsp.org>
parents: 29
diff changeset
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
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
613 offsetX, offsetY, i);
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
614 exit(9);
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
615 }
1770
cc59f80b0e78 Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1692
diff changeset
616 tmp->mark = TRUE;
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
617
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
618 currBlocks++;
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
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
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
623 THPRINT(2, ".");
32
c41ec03eac99 Updates, fixes
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
624
c41ec03eac99 Updates, fixes
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
625 #if 0
1770
cc59f80b0e78 Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1692
diff changeset
626 // Debug unmatching blocks
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
627 char mysti[512];
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
628 snprintf(mysti, sizeof(mysti),
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
629 "[%d]: %d,%d (%d,%d)",
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
630 i, qx, qy, tmp->x, tmp->y);
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
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
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
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
Matti Hamalainen <ccr@tnsp.org>
parents: 29
diff changeset
635 #endif
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
636 }
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
637 }
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
638 }
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
639
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
640 THPRINT(2, "\n");
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
641 }
28
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
642
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
643 /* Output generated map
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
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
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
647 int unusedBlocks;
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
648 FILE *tmpFile;
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
649
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
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
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
652
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
653 if (destFile == NULL)
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
654 tmpFile = stdout;
1692
f5d432ccc9d6 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1647
diff changeset
655 else
f5d432ccc9d6 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1647
diff changeset
656 if ((tmpFile = fopen(destFile, "wb")) == NULL) {
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
657 THERR("Error opening output file '%s'!\n",
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
658 destFile);
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
659 exit(1);
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
660 }
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
661
1310
a6be5a68032f Rename map block handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1309
diff changeset
662 mapBlockPrint(tmpFile, worldMap);
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
663
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
664 fclose(tmpFile);
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
665
1770
cc59f80b0e78 Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1692
diff changeset
666 // Compute number of unused blocks
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
667 for (unusedBlocks = i = 0; i < nmapBlocks; i++)
1770
cc59f80b0e78 Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1692
diff changeset
668 if (!mapBlocks[i]->mark)
cc59f80b0e78 Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1692
diff changeset
669 {
cc59f80b0e78 Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1692
diff changeset
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
cc59f80b0e78 Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1692
diff changeset
672 fprintf(stderr, "\n#%d: %d,%d (%d,%d)\n",
cc59f80b0e78 Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1692
diff changeset
673 i, mapBlocks[i]->x, mapBlocks[i]->y,
cc59f80b0e78 Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1692
diff changeset
674 mapBlocks[i]->x + offsetX,
cc59f80b0e78 Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1692
diff changeset
675 mapBlocks[i]->y + offsetY);
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
676
1770
cc59f80b0e78 Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1692
diff changeset
677 mapBlockPrint(stderr, mapBlocks[i]);
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
678 }
1770
cc59f80b0e78 Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1692
diff changeset
679 unusedBlocks++;
cc59f80b0e78 Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1692
diff changeset
680 }
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
681
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
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
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
686 THERR("No map generated?\n");
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
687 }
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
688
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 682
diff changeset
689 return 0;
28
81a329b34878 Added new utility
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
690 }