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