summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/wargame/source/chit/table.dtx
blob: 7094e436edbfb18c5da9140d197543964dbc5025 (plain)
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
% \iffalse
% <*chit>
% --------------------------------------------------------------------
% \fi
% \subsubsection{Table of chits}
%
%    \begin{macrocode}
\tikzset{
  chit/cell background/.style={fill=black},
  blank chit/.style={/chit/frame={draw=none,fill=none}},
}
%    \end{macrocode}
% 
% These macros are used when we set tables of chits.  This allows us
% to define blank spaces in the table by giving the element
% \texttt{blank~chit}.
% 
%    \begin{macrocode}
\def\chit@blank{blank chit}
\def\chit@cellbg(#1,#2)#3{%
  \draw[chit/cell background](#1-#3/2,#2-#3/2) rectangle++(#3,#3);
}
%    \end{macrocode}
% 
% \begin{Macro}{\ifchits@reset}
%
%   This `if' controls whether to reset the coordinates to the origin
%   when \cs{chits} is called.  If true, then reset for a new table.
%   
%    \begin{macrocode}
\newif\ifchits@reset\chits@resettrue
%    \end{macrocode}
% \end{Macro}
% 
% \begin{Macro}{\chits,\@chits,\chit@sng@cellupdate}
%    \begin{macrocode}
\def\chit@sng@cellupdate(#1,#2)#3#4{%
  \chit@dbg{2}{Current `#1' vs `#4'*(`#3'+1)}
  \pgfmathparse{ifthenelse(#1>=#4*(#3-1),#2-#4,#2)}%
  \xdef#2{\pgfmathresult}%
  \pgfmathparse{ifthenelse(#1>=#4*(#3-1),0,#1+#4)}%
  \xdef#1{\pgfmathresult}%
}
%    \end{macrocode}
%
% The stared version (\cs{chits*}) of this macro continues the
% previously set chit table.
% 
%    \begin{macrocode}
\def\chits{%
  \@ifstar{\chits@resetfalse\@chits}{\chits@resettrue\@chits}}
%    \end{macrocode}
% 
%    \begin{macrocode}
\def\@chits#1#2#3{
  \ifchits@reset
    \def\r{0}%
    \def\c{0}%
  \fi
  \chit@dbg{1}{Chits to make: #1}%
  \foreach[count=\ti from 0] \t/\x in #1{%
    \chit@dbg{2}{Turn `\t' with option `\x'}
    \ifx\t\empty\else%
      \foreach \u/\m in \t{%
        \ifx\u\empty\else%
          \chit@dbg{2}{Next chit `\u' with possible multiplicity `\m'}%
          \ifx\m\@empty\def\m{1}\fi%
          \ifx\u\m\def\m{1}\fi%
          \chit@dbg{2}{Next chit `\u' multiplicity `\m'}%
          \foreach \n in {1,...,\m}{%
            \ifx\u\chit@blank%
              \chit@dbg{3}{Ignoring blank chit:\u}%
            \else%
              \chit@cellbg(\c,\r){#3}%
              \chit[\u=\ti](\c,\r)%
              \chit@sng@cellupdate(\c,\r){#2}{#3}%
            \fi%
          }%
        \fi%
      }%
    \fi%
  }%
  \@ifnextchar;{\@gobble}{}}
%    \end{macrocode}
% \end{Macro}
%
% \begin{Macro}{\doublechits,
%   \@doublechits,
%   \chit@dbl@cellupdate,
%   \chit@dbl@flip}
% \begin{enumerate}
% \item coordinates
% \item coordinates
% \item cell-size
% \end{enumerate}
% 
%    \begin{macrocode}
\def\chit@dbl@flip(#1,#2)#3{%
  \pgfmathparse{-#1}%
  \xdef\mc{\pgfmathresult}%
}
%    \end{macrocode}
% 
%   \begin{enumerate}
%   \item coordinates
%   \item coordinates
%   \item Number of columns
%   \item cell-size
%   \end{enumerate}
%
%    \begin{macrocode}
\def\chit@dbl@cellupdate(#1,#2)#3#4{%
  \pgfmathparse{ifthenelse(#1<-#4/2,#2,#4+#2)}%
  \xdef#2{\pgfmathresult}%
  \pgfmathparse{ifthenelse(#1<-#4/2,#4+#1,-(#3-.5)*#4)}%
  \xdef#1{\pgfmathresult}%
}
%    \end{macrocode}
%
%   \begin{enumerate}
%   \item List of list of keys
%   \item Number of columns
%   \item size of each cell
%   \end{enumerate}
% 
%   The stared version (\cs{doublechits*}) of this macro continues the
%   previously set chit table.
% 
%    \begin{macrocode}
\def\doublechits{%
  \@ifstar{\chits@resetfalse\@doublechits}{\chits@resettrue\@doublechits}}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\@doublechits#1#2#3{%
  \chit@dbg{1}{Setting double-sided chits: #1}
  \ifchits@reset
    \pgfmathparse{-(#2-.5)*#3}
    \xdef\c{\pgfmathresult}
    \def\r{0}
  \fi
  
  \foreach[count=\ti from 0] \t/\x in #1{
    \ifx\t\empty\else%
      \foreach \u/\m in \t{
        \ifx\u\empty\else
          \ifx\m\@empty\def\m{1}\else%
            \ifx\u\m\def\m{1}\fi\fi
          \chit@dbg{2}{`\u'=`\m' (\c,\r)}
          \foreach \n in {1,...,\m}{%
            \ifx\u\chit@blank
              \chit@dbg{3}{Ignoring blank chit:\u}
            \else
              \chit@cellbg(\c,\r){#3}
              \chit[\u=\ti](\c,\r)
              \chit@dbl@flip(\c,\r){#3}
              \chit@cellbg(\mc,\r){#3}
              \chit[\u\space flipped=\ti,zone turn=\t,zone mult=\n](\mc,\r)
              \chit@dbl@cellupdate(\c,\r){#2}{#3}
            \fi
          }
        \fi
      }
    \fi
  }
  \draw[dashed](0,-3*#3/4)--(0,\r-#3/4);%
  \draw[dashed,<-] (#3/5,-2*#3/3)--(#3/2,-2*#3/3) node[transform shape,anchor=west]{Back};%
  \draw[dashed,<-] (-#3/5,-2*#3/3)--(-#3/2,-2*#3/3) node[transform shape,anchor=east]{Front};%
  \@ifnextchar;{\@gobble}{}}  
%    \end{macrocode}
% \end{Macro}
%    
% \iffalse
% </chit>
% --------------------------------------------------------------------
% \fi