1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
|
% \iffalse
% <*chit>
% --------------------------------------------------------------------
% \fi
% \subsubsection{Making order of battle charts}
%
%
% Macros for making OOBs
%
% Style for turns
%
% \begin{macrocode}
\tikzset{
chit/oob turn/.pic={\node[pic actions]{#1};}}
% \end{macrocode}
%
%
% current c, current r, n-columns, cell size, y
%
% \begin{macrocode}
\def\chit@oob@cellupdate(#1,#2)#3#4#5{%
\edef\f{\ifwg@oob@inv-1\else1\fi}%
\chit@dbg{1}{ \space Cell update `c=|#1|' vs `#4'*(`#3'-1)}
\pgfmathparse{int(ifthenelse(abs(#1)>=#4*(#3-1),#5-1,#5))}%
\xdef#5{\pgfmathresult}
\pgfmathparse{ifthenelse(abs(#1)>=#4*(#3-1),#2-#4,#2)}%
\xdef#2{\pgfmathresult}%
\pgfmathparse{ifthenelse(abs(#1)>=#4*(#3-1),0,#1+\f*#4)}%
\xdef#1{\pgfmathresult}%
\chit@dbg{1}{ \space\space-> `\string#5'=#5 `\string#2'=#2 `\string#1'=#1}
}
% \end{macrocode}
%
% current c, current r, cell size, extra vertical spacing
%
% \begin{macrocode}
\def\chit@oob@rowupdate(#1,#2)#3#4{%
\chit@dbg{2}{ Row update c=`#1',r=`#2',s=`#3',e=`#4'}
%\pgfmathparse{ifthenelse(#1>0,#2-#3,#2)}%
\pgfmathparse{#2-#3-#4}%
\xdef#2{\pgfmathresult}%
\xdef#1{0}%\pgfmathresult}%
%\xdef#1{0}
\chit@dbg{2}{ \space\space-> update `\string#2'=#2}
}
% \end{macrocode}
% current c, current r, cell size, extra spacing
%
% \begin{macrocode}
\def\chit@oob@turnupdate(#1,#2)#3#4{%
\chit@dbg{2}{ Turn update c=`#1',r=`#2',s=`#3',e=`#4'}
% \pgfmathparse{#2-ifthenelse(#1>0,#3,0)-#4}%
\pgfmathparse{#2-#4-ifthenelse(abs(#1)>0.0001,#3,0)}
\xdef#2{\pgfmathresult}%
\xdef#1{0}%
\chit@dbg{2}{ \space\space-> update `\string#1'=#1,`\string#2'=#2}
}
% \end{macrocode}
% chit list, n-colls, cell size, extra vertical spacing
%
% This expects a list of lists of chits, one list per turn; the
% maximum number of columns; the size of cells, extra spacing between
% turns.
%
% Note, the list of lists leaf elements should be styles for the
% chits.
%
% This depends on the Tikz pic \texttt{chit/oob~turn} which takes the
% number as argument.
%
%
% \begin{macrocode}
\newif\ifwg@oob@inv\wg@oob@invfalse
\def\chit@oob@spacer{hspace}
\def\chit@oob@vspacer{vspace}
\def\wg@star@oob{\wg@oob@invtrue\wg@oob}
\def\wg@nostar@oob{\wg@oob@invfalse\wg@oob}
\def\oob{%
\@ifstar{\wg@star@oob%
}{\wg@nostar@oob%
}%
}
% \end{macrocode}
%
% The inner macro of \cs{oob}. The arguments are
% \begin{enumerate}
% \item The list of lists of chits styles
% \item The maximum number of columns
% \item The width of each cell
% \item Additional row spacing between turns
% \end{enumerate}
%
% \begin{macrocode}
\def\wg@oob#1#2#3#4{
\def\r{0}
\pgfmathparse{#3*(#2-1)}%
\edef\a{\pgfmathresult}
\chit@dbg{2}{OOB: `#1'}
\foreach[count=\ti from 0] \t/\y in #1{
\xdef\o{\r}
\def\c{0}
\ifx\t\y\def\y{0}\fi
\chit@dbg{2}{Turn \ti\space(\r,\t,y=\y):'}
\ifwg@oob@inv%
\pic[transform shape] at ( .5*#3,\r) {chit/oob turn=\ti};% was dx=0.5
\else
\pic[transform shape] at (-.5*#3,\r) {chit/oob turn=\ti};% was dx=-0.5
\fi%
\ifx\t\empty\else%
\foreach \u/\m in \t{
%% \chit@dbg{2}{ `\u'=`\m'}
\ifx\u\empty\else
\ifx\m\@empty\def\m{1}\fi
\ifx\u\m\def\m{1}\fi
\foreach \n in {1,...,\m}{%
\chit@dbg{2}{OOB Chit is `\u' `\chit@oob@spacer'}%
\ifx\u\chit@oob@spacer%
\chit@dbg{3}{Chit `\u' is spacer `\chit@oob@spacer'}
\pgfmathparse{\c+#4}%
\xdef\c{\pgfmathresult}%
\else%
\ifx\u\chit@oob@vspacer%
\chit@dbg{3}{Chit `\u' is vspacer `\chit@oob@vspacer'}
\pgfmathparse{ifthenelse(abs(\c)<0.0001,0,#3)}
\xdef\ll{\pgfmathresult}
\chit@dbg{2}{\string\ll=`\ll'}
\chit@oob@rowupdate(\c,\r){\ll}{#4}
\else
\ifnum\chitdbglvl>2%
\node[minimum width=#3cm,minimum height=#3cm,
draw,transform shape] at (\c,\r) {};
\fi
\ifx\u\chit@blank\else%
\chit[\u=\ti,zone oob point={\u}{\c}{\r}](\c,\r);%
\fi%
\chit@oob@cellupdate(\c,\r){#2}{#3}{\y}
\fi
\fi
}
\fi
}
\fi
\chit@dbg{1}{ End of chits in turn
\ti\space(c=`\c',r=`\r',o='\o',y='\y')}
% IF no units where given, then we force \c to be non-zero so that
% \chit@oob@turnupdate increments the row
\ifx\t\@empty
\def\c{#3}
\chit@dbg{2}{ Turn is empty, set c=`\c'}
\fi
%\ifnum\y<0% No explicit number of rows given
% \def\c{#3}
% \chit@dbg{2}{ No explicit number of rows given, set c=`\c'}
%\fi
% In case the user gave and explicit number of rows, add the rows
% that are missing. \y is initially set to the number of
% requested rows, and then decremented every time we go down one
% row. So if the number of rows we did so far is N, and the
% requested number of rows is M, then the loop below adds M-N
% rows.
\ifnum\y>0%
\chit@dbg{2}{ Looping rows from 2 to \y, break when row > \y}%
\foreach \rr in {2,...,\y}{
%\ifnum\rr>\y% A little funny, but \y can be negative!
% \chit@dbg{2}{ \space Breaking loop \rr\space > \y}%
% \breakforeach%
%\else%
\chit@oob@rowupdate(\c,\r){#3}{0}% Extra spacing?
%\fi
}
\fi
% This will zero \c. However, if on entry |\c|>0, then we also
% increment the row
\chit@oob@turnupdate(\c,\r){#3}{#4}
\chit@dbg{2}{End of turn \ti\space(c=`\c',r=`\r',o='\o',y='\y')}
}
\chit@dbg{3}{End of OOB (c=`\c',r=`\r',y=`\y')}
\@ifnextchar;{\@gobble}{}}
% \end{macrocode}
%
% Horizontal flow OOB
%
% \begin{macrocode}
\def\wg@star@hoob{\wg@oob@invtrue\wg@hoob}
\def\wg@nostar@hoob{\wg@oob@invfalse\wg@hoob}
\def\hoob{%
\@ifstar{\wg@star@hoob%
}{\wg@nostar@hoob%
}%
}
% \end{macrocode}
%
% The inner macro of \cs{hoob}. The arguments are
% \begin{enumerate}
% \item The list of lists of chits styles
% \item The maximum number of columns
% \item The width of each cell
% \item Additional row spacing between turns
% \end{enumerate}
%
% \begin{macrocode}
\def\wg@hoob#1#2#3#4{
\def\r{0}
\def\c{0}
\pgfmathparse{#3*(#2-1)}%
\edef\a{\pgfmathresult}
\chit@dbg{2}{OOB: `#1'}
\foreach[count=\ti from 0] \t/\y in #1{
\xdef\o{\r}
% \def\c{0}
\ifx\t\y\def\y{0}\fi
\chit@dbg{2}{Turn \ti\space(\r,\t,y=\y):'}
\ifx\t\empty\else
% Count how many are left for this turn
\chit@dbg{2}{At start of turn \t\space\string\c=\c}
\def\l{\c}%
\let\ig\empty
\foreach \u/\m in \t{
\ifx\ig\empty
\ifx\u\empty\else
\ifx\u\m\def\m{1}\fi
\ifx\u\chit@oob@spacer%
\pgfmathparse{\l+\m*#4}\xdef\l{\pgfmathresult}
\chit@dbg{2}{Got \m\space hspace (#4) -> \l}
\else
\ifx\u\chit@oob@vspace%
\xdef\ig{1}
\chit@dbg{2}{Got vspace -> \l (\ig)}
\else
\pgfmathparse{\l+\m*#3}
\xdef\l{\pgfmathresult}
\chit@dbg{2}{Got \m\space units -> \l}
\fi
\fi
\fi
\fi}
% Check if there's enough room
\chit@dbg{2}{To fill the rest of turn needs `\l' compared to
`\a' (#3*(#2-1))}
\pgfmathparse{ifthenelse(abs(\l)>=#3*(#2-1),0,1}%
\xdef\l{\pgfmathresult}%
\chit@dbg{2}{Break or not `\l'}
\ifnum\l=0\chit@oob@turnupdate(\c,\r){#3}{#4}\fi
\fi
\ifwg@oob@inv%
\pic[transform shape] at (\c+.5*#3,\r) {chit/oob turn=\ti};% was dx=0.5
\else
\pic[transform shape] at (\c+-.5*#3,\r) {chit/oob turn=\ti};% was dx=-0.5
\fi%
%\chit@oob@cellupdate(\c,\r){#2}{#3}{\y}
\ifx\t\empty\else%
\def\lv{0}
\foreach \u/\m in \t{
%% \chit@dbg{2}{ `\u'=`\m'}
\ifx\u\empty\else
\ifx\m\@empty\def\m{1}\fi
\ifx\u\m\def\m{1}\fi
\foreach \n in {1,...,\m}{%
\chit@dbg{2}{OOB Chit is `\u' `\chit@oob@spacer'}%
\ifx\u\chit@oob@spacer%
\chit@dbg{3}{Chit `\u' is spacer `\chit@oob@spacer'}
\pgfmathparse{\c+#4}%
\xdef\c{\pgfmathresult}%
\else%
\ifx\u\chit@oob@vspacer%
\chit@dbg{3}{Chit `\u' is vspacer `\chit@oob@vspacer'}
\pgfmathparse{ifthenelse(abs(\c)<0.0001,0,#3)}
\xdef\ll{\pgfmathresult}
\chit@dbg{2}{\string\ll=`\ll'}
\chit@oob@rowupdate(\c,\r){\ll}{#4}
\xdef\lv{1}
\else
\ifnum\chitdbglvl>2%
\node[minimum width=#3cm,minimum height=#3cm,
draw,transform shape] at (\c,\r) {};
\fi
\ifx\u\chit@blank\else%
\chit[\u=\ti,zone oob point={\u}{\c}{\r}](\c,\r);%
\fi%
\chit@oob@cellupdate(\c,\r){#2}{#3}{\y}
\fi
\fi
}
\fi
}
\fi
\chit@dbg{2}{ End of chits in turn
\ti\space(c=`\c',r=`\r',o='\o',y='\y')}
% --- Not relevant, I think
% IF no units where given, then we force \c to be non-zero so that
% \chit@oob@turnupdate increments the row
% \ifx\t\@empty
% \def\c{#3}
% \chit@dbg{2}{ Turn is empty, set c=`\c'}
% \fi
% ---
%\ifnum\y<0% No explicit number of rows given
% \def\c{#3}
% \chit@dbg{2}{ No explicit number of rows given, set c=`\c'}
%\fi
% In case the user gave and explicit number of rows, add the rows
% that are missing. \y is initially set to the number of
% requested rows, and then decremented every time we go down one
% row. So if the number of rows we did so far is N, and the
% requested number of rows is M, then the loop below adds M-N
% rows.
\ifnum\y>0%
\chit@dbg{2}{ Looping rows from 2 to \y, break when row > \y}%
\foreach \rr in {2,...,\y}{
%\ifnum\rr>\y% A little funny, but \y can be negative!
% \chit@dbg{2}{ \space Breaking loop \rr\space > \y}%
% \breakforeach%
%\else%
\chit@oob@rowupdate(\c,\r){#3}{0}% Extra spacing?
%\fi
}
\fi
% --- Not relevant I think
% This will zero \c. However, if on entry |\c|>0, then we also
% increment the row
% \chit@oob@turnupdate(\c,\r){#3}{#4}
% ---
% Horizontal spacer
%\pgfmathparse{ifthenelse(abs(\c)>=\a,1,0)}\xdef\l{\pgfmathresult}
\pgfmathparse{\c+1.5*#4}%
\xdef\c{\pgfmathresult}%
\ifnum\lv=1%
\pgfmathparse{\r-#4}
\chit@oob@rowupdate(\c,\r){0}{#4}
\else
\chit@oob@cellupdate(\c,\r){#2}{#3}{\y}
\ifnum\y<0
\chit@oob@turnupdate(\c,\r){#3}{#4}
\else
\fi
\fi
% \xdef\y{0}
\chit@dbg{2}{End of turn \ti\space(c=`\c',r=`\r',o='\o',y='\y')}
}
\chit@dbg{3}{End of OOB (c=`\c',r=`\r',y=`\y')}
\@ifnextchar;{\@gobble}{}}
% \end{macrocode}
% \iffalse
% </chit>
% --------------------------------------------------------------------
% \fi
|