%%
%% This is file `tikzlibrarywargame.chit.code.tex',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% chit/core.dtx  (with options: `chit')
%% chit/shape.dtx  (with options: `chit')
%% chit/elements.dtx  (with options: `chit')
%% chit/modifiers.dtx  (with options: `chit')
%% chit/stack.dtx  (with options: `chit')
%% chit/oob.dtx  (with options: `chit')
%% chit/table.dtx  (with options: `chit')
%% chit/battle.dtx  (with options: `chit')
%% chit/dice.dtx  (with options: `chit')
%% chit/misc.dtx  (with options: `chit')
%% 
%% Copyright (C) 2019 Christian Holm.
%% 
%% This file is NOT the source for wargame, because almost all comments
%% have been stripped from it.  It is NOT the preferred form of universal
%% for making modifications to it.
%% 
%% Therefore you can NOT redistribute and/or modify THIS file.  You can
%% however redistribute the complete source (wargame.dtx and wargame.ins)
%% and/or modify it under the terms of the GNU General Public License as
%% published by the Free Software Foundation; either version 2, or (at
%% your option) any later version.
%% 
%% The wargame package is distributed in the hope that it will be useful,
%% but WITHOUT ANY WARRANTY; without even the implied warranty of
%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
%% General Public License for more details.
%% 
%% You should have received a copy of the GNU General Public
%% License along with this package; if not, write to the
%%   Free Software Foundation, Inc.,
%%   675 Mass Ave, Cambridge,
%%   MA 02139, USA.
%% 
%% See the file wargame.dtx for further comments and documentation.
%% 
\RequirePackage{amsmath}
\RequirePackage{amstext}
\usetikzlibrary{wargame.util,wargame.natoapp6c,math}
\newcount\chitdbglvl\chitdbglvl=\wargamedbglvl
\def\chit@dbg#1#2{%
  \ifnum#1>\chitdbglvl\relax\else\message{^^J#2}\fi}
\newif\ifchit@clip\chit@cliptrue
\tikzset{%
  /chit/.search also={/tikz},
  /chit/.cd,
  full/.store in=\chit@full,               full/.initial=,%
  symbol/.store in=\chit@symbol,           symbol/.initial=,%
  left/.store in=\chit@left,               left/.initial=,%
  unique/.style={/chit/left={#1}},%
  right/.store in=\chit@right,             right/.initial=,%
  parent/.style={/chit/right={#1}},%
  upper left/.store in=\chit@upper@left,   upper left/.initial=,%
  upper right/.store in=\chit@upper@right, upper right/.initial=,%
  lower left/.store in=\chit@lower@left,   lower left/.initial=,%
  lower right/.store in=\chit@lower@right, lower right/.initial=,%
  factors/.store in=\chit@factors,         factors/.initial=,%
  setup/.store in=\chit@setup,             setup/.initial=,%
  id/.store in=\chit@id,                   id/.initial=,%
  frame/.store in=\chit@frame,             frame/.initial=,%
  extra/.store in=\chit@extra,             extra/.initial=,%
  bev/.store in=\chit@bevel,               bev/.initial=,
  bevel fraction/.store in=\chit@bevel@frac,bevel fraction/.initial=10,
  bevel/.is choice,
  bevel/none/.style       = {/chit/bev=},
  bevel/north west/.style = {/chit/bev=1},
  bevel/north east/.style = {/chit/bev=2},
  bevel/south west/.style = {/chit/bev=3},
  bevel/south east/.style = {/chit/bev=4},
  bevel/NW/.style         = {/chit/bev=1},
  bevel/NE/.style         = {/chit/bev=2},
  bevel/SW/.style         = {/chit/bev=3},
  bevel/SE/.style         = {/chit/bev=4},
  bevel/.default          = north west,
  clip/.is if=chit@clip,%
  nato shape/.store in=\chit@n@to@shape,
}
\def\chit@sym@sc@le{.4}
\tikzset{
  chit/symbol/.style={scale=\chit@sym@sc@le,transform shape},
  chit/parts/.style={shape=rectangle,transform shape},
  chit/factors/.style={chit/parts,anchor=south},
  chit/left/.style={chit/parts,anchor=base,rotate=90},%Anchor was south
  chit/right/.style={chit/parts,anchor=north,rotate=90},
  chit/upper left/.style={chit/parts,anchor=north west},
  chit/upper right/.style={chit/parts,anchor=north east},
  chit/lower left/.style={chit/parts,anchor=south west},
  chit/lower right/.style={chit/parts,anchor=south east},
  chit/setup/.style={chit/parts},
  chit/full/.style={chit/parts},
  chit/frame/.try={draw=pgfstrokecolor},
  chit/bevel highlight/.style={fill=white,opacity=.25},
  chit/bevel shadow/.style={fill=black,opacity=.25},
}
\def\chit@bevel@frac{10}
\newif\ifchit@draw@frame\chit@draw@frametrue
\tikzset{
  chit/frame style/.search also={/tikz},
  chit/frame style/.cd,
  none/.code={\chit@draw@framefalse},
  draw/.code={%
    \chit@dbg{2}{Frame draw option `#1'}
    \edef\tikz@temp{#1}%
    \ifx\tikz@temp\tikz@nonetext%
      \chit@draw@framefalse%
    \else%
      \chit@draw@frametrue%
      \tikzset{/tikz/draw=#1}
    \fi
  }
}

\tikzset{%
  chit/.code={%
    \chit@dbg{2}{chit arguments are `#1'}%
    \pgfkeys{/tikz/transform shape,/tikz/shape=chit}%
    \pgfkeys{/chit/.cd,nato shape=natoapp6c,#1}}}
\newcounter{chit@id}\setcounter{chit@id}{0}
\def\chit@n@to#1#2{%
  %% Without a following start square bracket '[' by-pass to final
  \chit@dbg{1}{Chit NATO App6(c) first step `#1' `#2'}
  \@ifnextchar[{%
    %\message{^^JStart square bracket}%
    \@chit@n@to{#1}{#2}}{%
    %\message{^^JNo start square bracket}%
    \@chit@n@to@{#1}{#2}}%]]
}
\def\chit@n@to@shape{natoapp6c}
\def\@chit@n@to@#1#2#3\@end@chit@n@to{%
  \chit@dbg{1}{Chit NATO App6(c) w/o offset:
    ^^J  Options:  `#3'
    ^^J  ID:       `#1'
    ^^J  Position: `#2'
    ^^J  Style:    `\chit@n@to@shape'
  }
  \chit@dbg{2}{NATO shape: `\chit@n@to@shape'}
  \node[chit/symbol,\chit@n@to@shape={#3,id=#1}] (#1) at (#2) {};
  \chit@dbg{4}{Chit NATO App6(c) ended}%
}
\def\@chit@n@to#1#2[#3]{%
  \chit@dbg{1}{Chit NATO App6(c) second step `#1' `#2' `#3'}
  \@ifnextchar({\@@chit@n@to{#1}{#2}{#3}}{\@@chit@n@to{#1}{#2}{#3}(0,0)}%)
}
\def\@@chit@n@to#1#2#3(#4)\@end@chit@n@to{%
  \chit@dbg{1}{Chit NATO App6(c) w/offset:
    ^^J  Options:  #3
    ^^J  ID:       #1
    ^^J  Position: #2
    ^^J  Offset:   #4}
  \chit@dbg{10}{==== NATO shape: `\chit@n@to@shape' ====}
  \node[chit/symbol,\chit@n@to@shape={#3,id=#1}] (#1) at ($(#2)+(#4)$) {};}
\def\chit@tr@ns@nchor{%
  \chit@dbg{10}{Translating anchor `\the\pgf@x',`\the\pgf@y'}
  \wg@tmpa=\pgf@x%
  \wg@tmpb=\pgf@y%
  \symbol%
  \chit@dbg{10}{Symbol origin `\the\pgf@x',`\the\pgf@y'}
  \wg@tmpc=\pgf@x%
  \wg@tmpd=\pgf@y%
  \pgf@x=\chit@sym@sc@le\wg@tmpa%
  \pgf@y=\chit@sym@sc@le\wg@tmpb%
  \chit@dbg{10}{Scaled anchor `\the\pgf@x',`\the\pgf@y'}
  \advance\pgf@x\wg@tmpc%
  \advance\pgf@y\wg@tmpd%
  \chit@dbg{10}{Offset anchor `\the\pgf@x',`\the\pgf@y'}
}
\def\chit@nchor#1#2{%
  \chit@dbg{10}{Get chit sub anchor of `#1' `#2'}%
  \wg@sub@nchor{#1}{#2}%
  \chit@tr@ns@nchor%
  \chit@dbg{10}{Got chit sub anchor of `\the\pgf@x `\the\pgf@y}%
}
\def\chit@sym@nchor#1{%
  \chit@dbg{10}{Get chit symbol `#1'}%
  \edef\tmpid{\id symbol}%
  \chit@nchor{\tmpid}{#1}}
\def\chit@report{}
\tikzset{
  zone turn/.style={},
  zone mult/.style={}
}
\def\chit@bkg@p@th{%
  \northeast%
  \wg@tmpa=\pgf@x\wg@tmpb=\pgf@y%
  \pgfpathmoveto{\pgfqpoint{\wg@tmpa}{\wg@tmpb}}%
  \wg@tmpa=-\wg@tmpa \pgfpathlineto{\pgfqpoint{\wg@tmpa}{\wg@tmpb}}%
  \wg@tmpb=-\wg@tmpb \pgfpathlineto{\pgfqpoint{\wg@tmpa}{\wg@tmpb}}%
  \wg@tmpa=-\wg@tmpa \pgfpathlineto{\pgfqpoint{\wg@tmpa}{\wg@tmpb}}%
  \pgfclosepath%
}
\def\chit@bevel@path#1{
  \scope[#1]
  \wg@tmpc=\wg@tmpa%
  \wg@tmpd=\wg@tmpb%
  %% Absolute values
  \ifdim\wg@tmpa<0pt\multiply\wg@tmpc by -1\fi%
  \ifdim\wg@tmpb<0pt\multiply\wg@tmpd by -1\fi%
  % Why the hell do I need this?
  \chit@dbg{10}{`\the\wg@tmpa' `\the\wg@tmpb'}%
  %% Smallest dimension
  \ifdim\wg@tmpc>\wg@tmpd \wg@tmpc=\wg@tmpd\fi%
  \ifdim\wg@tmpc<\wg@tmpd \wg@tmpd=\wg@tmpc\fi%
  %% Restore sign
  \ifdim\wg@tmpa<0pt\multiply\wg@tmpc by -1\fi%
  \ifdim\wg@tmpb<0pt\multiply\wg@tmpd by -1\fi%
  %% Take the fraction
  \multiply\wg@tmpc by \chit@bevel@frac%
  \multiply\wg@tmpd by \chit@bevel@frac%
  \divide\wg@tmpc100%
  \divide\wg@tmpd100%
  \pgfpathmoveto{\pgfqpoint{\wg@tmpa}{\wg@tmpb}}%
  % Move down along edge
  \wg@tmpb=-\wg@tmpb%
  \pgfpathlineto{\pgfqpoint{\wg@tmpa}{\wg@tmpb}}%
  % Move left along edge
  \wg@tmpa=-\wg@tmpa%
  \pgfpathlineto{\pgfqpoint{\wg@tmpa}{\wg@tmpb}}%
  % Move in and up
  \advance\wg@tmpa\wg@tmpc%
  \advance\wg@tmpb\wg@tmpd%
  \pgfpathlineto{\pgfqpoint{\wg@tmpa}{\wg@tmpb}}%
  % Move right, but in
  \advance\wg@tmpa-\wg@tmpc\wg@tmpa=-\wg@tmpa%
  \advance\wg@tmpa-\wg@tmpc%
  \pgfpathlineto{\pgfqpoint{\wg@tmpa}{\wg@tmpb}}%
  % Move up but down
  \advance\wg@tmpb-\wg@tmpd\wg@tmpb=-\wg@tmpb%
  \advance\wg@tmpb-\wg@tmpd%
  \pgfpathlineto{\pgfqpoint{\wg@tmpa}{\wg@tmpb}}%
  \pgfclosepath%
  \pgfusepath{fill}%
  \endscope%
}
\pgfdeclareshape{chit}{
  \savedanchor\center{\pgf@x=0cm\pgf@y=0cm}
  \savedanchor\northeast{\pgf@x=0.6cm\pgf@y=\pgf@x}
  \savedanchor\symbol{\pgf@x=0cm\pgf@y=0.1cm}
  \savedanchor\factors{\pgf@x=0cm\pgf@y=-0.5cm}
  \saveddimen\margin{\pgf@x=0.04cm}
  \savedmacro\id{%
    \chit@dbg{4}{Chit ID: \meaning\chit@id}%
    \@ifundefined{chit@id}{\let\chit@id\pgfutil@empty}{}%
    \ifx\chit@id\pgfutil@empty%
      \wg@r@ndom@id%
      \edef\id{chit\wg@uuid}%
    \else%
      \edef\id{\chit@id}%
    \fi%
    \chit@dbg{4}{Chit ID stored: \meaning\chit@id}
  }
  \savedmacro\chitframeopt{%
    \let\chitframeopt\pgfutil@empty%
    \@ifundefined{chit@frame}{}{%
      \edef\chitframeopt{\chit@frame}}
    \chit@dbg{3}{Chit Frame options: \meaning\chitframeopt}%
  }
  \savedmacro\thisname{\def\thisname{chit}}
  \anchor{center}{\center}
  \anchor{north east}{\northeast}
  \anchor{north west}{\northeast\pgf@x=-\pgf@x}
  \anchor{south west}{\northeast\pgf@x=-\pgf@x\pgf@y=-\pgf@y}
  \anchor{south east}{\northeast\pgf@y=-\pgf@y}
  \anchor{north}     {\northeast\pgf@x=0cm}
  \anchor{south}     {\northeast\pgf@x=0cm\pgf@y=-\pgf@y}
  \anchor{east}      {\northeast\pgf@y=0cm}
  \anchor{west}      {\northeast\pgf@x=-\pgf@x\pgf@y=0cm}
  \anchor{symbol north east}{\chit@sym@nchor{north east}}
  \anchor{symbol north west}{\chit@sym@nchor{north west}}
  \anchor{symbol south east}{\chit@sym@nchor{south east}}
  \anchor{symbol south west}{\chit@sym@nchor{south west}}
  \anchor{symbol north}     {\chit@sym@nchor{north}}
  \anchor{symbol west}      {\chit@sym@nchor{west}}
  \anchor{symbol south}     {\chit@sym@nchor{south}}
  \anchor{symbol east}      {\chit@sym@nchor{east}}
  \anchor{symbol upper}     {\chit@sym@nchor{upper}}
  \anchor{symbol lower}     {\chit@sym@nchor{lower}}
  \anchor{symbol left}      {\chit@sym@nchor{left}}
  \anchor{symbol right}     {\chit@sym@nchor{right}}
  \anchor{symbol echelon}   {\chit@sym@nchor{echelon}}
  \anchor{symbol below}     {\chit@sym@nchor{below}}
  \anchor{symbol}    {\symbol}
  \anchor{factors}   {\factors}
  \anchor{left} {\chit@sym@nchor{west}\advance\pgf@x-\margin}
  \anchor{right}{\chit@sym@nchor{east}\advance\pgf@x+\margin}
  \anchor{upper right} {%
    \northeast \advance\pgf@x-\margin \advance\pgf@y-\margin%
  }
  \anchor{upper left}{
    \northeast \advance\pgf@x-\margin \advance\pgf@y-\margin \pgf@x=-\pgf@x%
  }
  \anchor{lower right} {%
    \northeast \advance\pgf@x-\margin \advance\pgf@y-\margin \pgf@y=-\pgf@y%
  }
  \anchor{lower left}{
    \northeast \advance\pgf@x-\margin \advance\pgf@y-\margin%
    \pgf@x=-\pgf@x \pgf@y=-\pgf@y%
  }
  \backgroundpath{%
    %% This is the outline of the chit only.  The rest of the chit is
    %% made on the foreground "path".
    \chit@dbg{1}{Chit drawing background path}
    \chit@bkg@p@th%
    % \northeast%
    % \wg@tmpa=\pgf@x\wg@tmpb=\pgf@y%
    % \pgfpathmoveto{\pgfqpoint{\wg@tmpa}{\wg@tmpb}}%
    % \wg@tmpa=-\wg@tmpa \pgfpathlineto{\pgfqpoint{\wg@tmpa}{\wg@tmpb}}%
    % \wg@tmpb=-\wg@tmpb \pgfpathlineto{\pgfqpoint{\wg@tmpa}{\wg@tmpb}}%
    % \wg@tmpa=-\wg@tmpa \pgfpathlineto{\pgfqpoint{\wg@tmpa}{\wg@tmpb}}%
    % \pgfclosepath
  }
  \behindforegroundpath{%
    \chit@dbg{1}{Chit drawing foreground path}
    % \chit@dbg{4}{%
    %   Chit foreground: \meaning\id
    %   ^^J  ID (set):    \meaning\chit@id
    %   ^^J  Symbol:      \meaning\chit@symbol
    %   ^^J  Full:        \meaning\chit@full
    %   ^^J  Factors:     \meaning\chit@factors
    %   ^^J  Left:        \meaning\chit@left
    %   ^^J  Right:       \meaning\chit@right
    %   ^^J  Upper left:  \meaning\chit@upper@left
    %   ^^J  Lower left:  \meaning\chit@lower@left
    %   ^^J  Upper right: \meaning\chit@upper@right
    %   ^^J  Lower right: \meaning\chit@lower@right
    %   ^^J  Extra:       \meaning\chit@extra
    %   ^^J  Bevel:       \meaning\chit@bevel
    %   ^^J  Frame:       \meaning\chit@frame}
    \chit@dbg{1}{Chit report}
    \chit@report{}
    \chit@dbg{1}{Chit start scope}
    \pgfscope
    %
    \ifchit@clip%
      \chit@dbg{1}{Chit clip path}
      \chit@bkg@p@th%
      % \northeast%
      % \wg@tmpa=\pgf@x\wg@tmpb=\pgf@y%
      % \pgfpathmoveto{\pgfqpoint{\wg@tmpa}{\wg@tmpb}}%
      % \wg@tmpa=-\wg@tmpa \pgfpathlineto{\pgfqpoint{\wg@tmpa}{\wg@tmpb}}%
      % \wg@tmpb=-\wg@tmpb \pgfpathlineto{\pgfqpoint{\wg@tmpa}{\wg@tmpb}}%
      % \wg@tmpa=-\wg@tmpa \pgfpathlineto{\pgfqpoint{\wg@tmpa}{\wg@tmpb}}%
      % \pgfclosepath%
      \pgfusepath{clip}%
    \fi%
    \@ifundefined{chit@symbol}{%
      %% Draw full stuff
      \@ifundefined{chit@full}{}{%
        \chit@dbg{1}{Chit draw full image: `\meaning\chit@full'}
        \center\wg@tmpa=\pgf@x\wg@tmpb=\pgf@y%
        \wg@pic@all{\chit@full}{}{\the\wg@tmpa,\the\wg@tmpb}{chit/full}}%
    }{% With NATO symbol
      \chit@dbg{1}{Chit draw symbol image}
      \edef\symid{\id symbol}%
      \symbol%
      \edef\args{{\symid}{\the\pgf@x,\the\pgf@y}\chit@symbol}%
      \chit@dbg{6}{Arguments to chit NATO symbol: \meaning\args}%
      \chit@dbg{1}{Chit draw nato image `\symid'}
      \expandafter\chit@n@to\args\@end@chit@n@to%
      \chit@dbg{6}{After making NATO symbol in chit}%
      % Put in left of symbol
      \@ifundefined{chit@left}{}{%
        \chit@dbg{2}{Chit draw left: `\meaning\chit@left'}
        \wg@nchor{\thisname}{left}
        \begin{scope}[]
          \wg@pic@all{\chit@left}{}{\pgf@x,\pgf@y}{chit/left}%
        \end{scope}}%
      % Put in right of symbol
      \@ifundefined{chit@right}{}{%
        \chit@dbg{2}{Chit draw right: `\meaning\chit@right'}
        \wg@nchor{\thisname}{right}
        \begin{scope}[]
          \wg@pic@all{\chit@right}{}{\pgf@x,\pgf@y}{chit/right}%
        \end{scope}}%
      % Get coordinates
      \northeast%
      \wg@tmpa=\pgf@x%
      \wg@tmpb=\pgf@y%
      \advance\wg@tmpa-\margin%
      \advance\wg@tmpb-\margin%
      % Put in upper left corner
      \@ifundefined{chit@upper@left}{}{%
        \chit@dbg{1}{Chit draw upper left: `\meaning\chit@upper@left'}%
        \wg@nchor{\thisname}{upper left}
        \begin{scope}[]
          \wg@pic@all{\chit@upper@left}{}{\pgf@x,\pgf@y}{chit/upper left}%
        \end{scope}}
      % Put in upper right corner
      \@ifundefined{chit@upper@right}{}{%
        \chit@dbg{1}{Chit draw upper right: `\meaning\chit@upper@right'}
        \wg@nchor{\thisname}{upper right}%
        \begin{scope}[]
          \wg@pic@all{\chit@upper@right}{}{\pgf@x,\pgf@y}{chit/upper right}%
        \end{scope}}
      % Put in lower left corner
      \@ifundefined{chit@lower@left}{}{%
        \chit@dbg{1}{Chit draw lower left: `\meaning\chit@lower@left'}
        \wg@nchor{\thisname}{lower left}%
        \begin{scope}[]
          \wg@pic@all{\chit@lower@left}{}{\pgf@x,\pgf@y}{chit/lower left}%
        \end{scope}}
      % Put in lower right corner
      \@ifundefined{chit@lower@right}{}{%
        \chit@dbg{1}{Chit draw lower right: `\meaning\chit@lower@right'}
        \wg@nchor{\thisname}{lower right}%
        \begin{scope}[]
          \wg@pic@all{\chit@lower@right}{}{\pgf@x,\pgf@y}{chit/lower right}%
        \end{scope}}
      % Put in factors
      \@ifundefined{chit@factors}{}{%
        \chit@dbg{1}{Chit draw factors: `\meaning\chit@factors'}
        \advance\wg@tmpb-\margin%
        \begin{scope}[]
          \wg@pic@all{\chit@factors}{}{0,-\the\wg@tmpb}{chit/factors}%
        \end{scope}}%
      % Put in extra
      \@ifundefined{chit@extra}{}{%
        \chit@dbg{1}{Chit draw extra: `\meaning\chit@extra'}
        \begin{scope}[]
          \wg@pic@all{\chit@extra}{}{0,0}{chit/factors}%
        \end{scope}}%
    }% End of full or symbol
    \endpgfscope%
    % Make bevel?
    \@ifundefined{chit@bevel}{\let\chit@bevel\empty}{}
    \ifx\chit@bevel\empty\else%
      \chit@dbg{1}{Chit draw bevel}
      %% South east bevel
      \northeast%
      \wg@tmpa=-\pgf@x\wg@tmpb=-\pgf@y%
      \ifcase\chit@bevel\relax%
      \or% 1
      \or\wg@tmpa=-\wg@tmpa% 2
      \or\wg@tmpb=-\wg@tmpb% 3
      \or\wg@tmpa=-\wg@tmpa\wg@tmpb=-\wg@tmpb%4
      \fi
      \chit@bevel@path{chit/bevel highlight}
      %% North west bevel
      \northeast%
      \wg@tmpa=\pgf@x\wg@tmpb=\pgf@y%
      \ifcase\chit@bevel\relax%
      \or% 1
      \or\wg@tmpa=-\wg@tmpa% 2
      \or\wg@tmpb=-\wg@tmpb% 3
      \or\wg@tmpa=-\wg@tmpa\wg@tmpb=-\wg@tmpb%4
      \fi
      \chit@bevel@path{chit/bevel shadow}
    \fi
    % Draw frame?
    \chit@dbg{1}{Chit draw frame: `\meaning\chitframeopt'}
    \edef\tmp@opt{[chit/frame style/.cd,chit/frame/.try,\chitframeopt]}
    \chit@dbg{1}{Chit draw frame: `\meaning\tmp@opt}
    \expandafter\scope\tmp@opt
      \northeast%
      \wg@tmpa=\pgf@x\wg@tmpb=\pgf@y%
      \pgfpathmoveto{\pgfqpoint{\wg@tmpa}{\wg@tmpb}}%
      \wg@tmpa=-\wg@tmpa \pgfpathlineto{\pgfqpoint{\wg@tmpa}{\wg@tmpb}}%
      \wg@tmpb=-\wg@tmpb \pgfpathlineto{\pgfqpoint{\wg@tmpa}{\wg@tmpb}}%
      \wg@tmpa=-\wg@tmpa \pgfpathlineto{\pgfqpoint{\wg@tmpa}{\wg@tmpb}}%
      \pgfclosepath%
      \chit@dbg{3}{Line width for frame: `\the\pgflinewidth'}
      \ifchit@draw@frame\pgfusepath{stroke}\fi%
      \chit@draw@frametrue%
      %\iftikz@mode@fill\pgfusepath{fill}\fi%
    \endscope%
    \chit@dbg{1}{Chit end of shape}
  }
}
\def\chit{%
  \chit@dbg{5}{Chit}
  \@ifnextchar[{\chit@}{\chit@[]}%]
}
\def\chit@[#1]{%
  \chit@dbg{5}{Chit second: `#1'}
  \@ifnextchar({\chit@@{#1}}{\chit@@{#1}(0,0)}%)
}
\def\chit@@#1(#2){%
  \@ifnextchar({\chit@@@{#1}{#2}}{\chit@@@{#1}{#2}()}%)
}
\def\chit@@@#1#2(#3){%
  \chit@dbg{5}{Chit final:
    ^^J  Options:    #1
    ^^J  Position:   #2
    ^^J  Name:       `#3'}
  \let\name\pgfutil@empty%
  \chit@dbg{1}{=== Before chit node}%
  \node[chit={/tikz/every chit/.try,id=#3,#1}] (tmp) at (#2) {};
  \chit@dbg{2}{=== After chit node}%
  \ifx|#3|\relax%
  \else%
    \chit@dbg{3}{=== Renaming chit to user defined name `#3'}%
    \pgfnoderename{#3}{tmp}%
  \fi%
  \@ifnextchar;{\@gobble}{}%
}
\tikzset{
  /chit/kriegspiel/.code={
    \pgfkeys{%
      /tikz/shape=kriegspiel,%
      /chit/nato shape=kriegspiel symbol}
  }
}
\pgfdeclareshape{kriegspiel}{
  \inheritsavedanchors[from=chit]
  \savedanchor\northeast{\pgf@x=0.8cm\pgf@y=0.4cm}
  \savedanchor\symbol{\pgf@x=0cm\pgf@y=0.15cm}
  \savedanchor\factors{\pgf@x=.2cm\pgf@y=-.4cm}
  \savedmacro\thisname{\def\thisname{kriegspiel}}
  \saveddimen\margin{\pgf@x=0.03cm}
  \inheritanchor[from=chit]{center}
  \inheritanchor[from=chit]{north east}
  \inheritanchor[from=chit]{north west}
  \inheritanchor[from=chit]{south west}
  \inheritanchor[from=chit]{south east}
  \inheritanchor[from=chit]{north}
  \inheritanchor[from=chit]{south}
  \inheritanchor[from=chit]{east}
  \inheritanchor[from=chit]{west}
  \inheritanchor[from=chit]{symbol north east}
  \inheritanchor[from=chit]{symbol north west}
  \inheritanchor[from=chit]{symbol south east}
  \inheritanchor[from=chit]{symbol south west}
  \inheritanchor[from=chit]{symbol north}
  \inheritanchor[from=chit]{symbol west}
  \inheritanchor[from=chit]{symbol south}
  \inheritanchor[from=chit]{symbol east}
  \inheritanchor[from=chit]{symbol upper}
  \inheritanchor[from=chit]{symbol lower}
  \inheritanchor[from=chit]{symbol left}
  \inheritanchor[from=chit]{symbol right}
  \inheritanchor[from=chit]{symbol echelon}
  \inheritanchor[from=chit]{symbol below}
  \inheritanchor[from=chit]{symbol}
  \inheritanchor[from=chit]{factors}
  \inheritanchor[from=chit]{left}
  \inheritanchor[from=chit]{right}
  \inheritanchor[from=chit]{upper right}
  \inheritanchor[from=chit]{upper left}
  \inheritanchor[from=chit]{lower right}
  \inheritanchor[from=chit]{lower left}
  % \anchor{upper right} {%
  %   \northeast%
  %   \advance\pgf@x-\margin%
  %   \advance\pgf@y-\margin%
  %   \pgf@y=-\pgf@y%
  %   \advance\pgf@y5pt%
  % }
  % \anchor{upper left}{
  %   \northeast%
  %   \advance\pgf@x-\margin%
  %   \advance\pgf@y-\margin%
  %   \pgf@x=-\pgf@x%
  %   \pgf@y=-\pgf@y%
  %   \advance\pgf@y5pt%
  % }
  %%
  \inheritbackgroundpath[from=chit]
  \inheritbehindforegroundpath[from=chit]
}
\DeclareRobustCommand\chit@sep[2][/]{%
  \foreach[count=\is] \s in {#2}{%
    \ifnum\is>1\relax#1\fi%
    \s}}
\def\chit@oset#1#2{%
  %$\stackrel{{}_{\text{\scriptsize #1}}}{\text{#2}}$%
  %$\stackrel{\lower2ex\hbox{\text{\scriptsize #1}}}{\text{#2}}$%
  %${}\overset{\text{\scriptsize #1}}{\text{#2}}{}$%
  \tikz[]{%
    \node[inner sep=0pt](chit@dd){#2};%
    \node[above=-.1ex of chit@dd,inner sep=0pt]{{\scriptsize #1}};%
  }%
}
\tikzset{%
  chit/1 factor/.pic={
    \chit@dbg{4}{ Chit 1 factor: #1}%
    \node[chit/factor,chit/1 factor,pic actions]{#1};},
  pics/chit/2 factors/.style args={#1,#2}{%
    code={%
      \chit@dbg{4}{ Chit 2 factors: #1 and #2}%
      \node[chit/factor,chit/2 factors,pic actions]{#1--#2};}},
  pics/chit/2 factors artillery/.style args={#1,#2,#3}{%
    code={
      \chit@dbg{4}{ Chit 2 factors w/artillery: `#1' `#2' `#3'}%
      \node[chit/factor,chit/2 factors]{%
        {#1}\chit@oset{#3}{--}{#2}};}},
  pics/chit/3 factors/.style args={#1,#2,#3}{%
    code={
      \chit@dbg{4}{ Chit 3 factors: `#1' `#2' `#3'}%
      \node[chit/factor,chit/3 factors]{#1-#2-#3};}},
  pics/chit/4 factors/.style args={#1,#2,#3,#4}{%
    code={
      \chit@dbg{4}{ Chit 3 factors: `#1' `#2' `#3' `#4'}%
      \node[chit/factor,chit/4 factors]{#1-#2-#3-#4};}},
  chit/identifier/.pic={
    \chit@dbg{4}{  Chit identifier: `#1'}%
    \node[chit/identifier,pic actions]{#1};
  },
  chit/identifiers/.pic={
    \chit@dbg{4}{  Chit identifiers: `#1'}%
    \node[chit/identifier,pic actions]{\chit@sep{#1}};
  },
  chit/small identifier/.pic={
    \chit@dbg{4}{  Chit small identifier: `#1'}%
    \node[chit/small identifier,pic actions]{#1};
  },
  chit/small identifiers/.pic={
    \chit@dbg{4}{  Chit small identifiers: `#1'}%
    \node[chit/small identifier,pic actions]{\chit@sep{#1}};
  },
  chit/identifier macro/.pic={%
    \chit@dbg{4}{ Chit identifier macro: \meaning#1}
    \edef\chit@i@tmp{#1}
    \node[chit/identifier,pic actions]{\chit@i@tmp};},
}
\tikzset{%
  chit/factor/.style={
    shape=rectangle,
    font=\sffamily\bfseries\fontsize{12}{14}\selectfont,
    anchor=base,
    inner sep=0,
    %text=pgfstrokecolor,
    draw=none,
    fill=none,
    transform shape,
  },
  chit/1 factor/.style={},
  chit/2 factors/.style={},
  chit/3 factors/.style={},
  chit/4 factors/.style={text/.append style=\fontsize{10}{12}\selectfont},
  chit/identifier/.style={
    shape=rectangle,
    font=\sffamily\bfseries\fontsize{8}{9}\selectfont,
    inner sep=0,
    % text=pgfstrokecolor,
    draw=none,
    fill=none,
    transform shape,
  },
  chit/small identifier/.style={
    shape=rectangle,
    font=\sffamily\bfseries\fontsize{6}{7}\selectfont,
    inner sep=0,
    % text=pgfstrokecolor,
    draw=none,
    fill=none,
    transform shape,
  },
}
\tikzset{
  pics/chit/shade/.style={
    code={%
      \path[fill=white,opacity=#1,pic actions] (-.6,-.6) rectangle(.6,.6);}},
  pics/chit/eliminate/.style={
    code={%
      \path[fill=red,opacity=#1,pic actions] (-.6,-.6) rectangle(.6,.6);}},
  pics/chit/shade/.default=0.5,
  pics/chit/eliminate/.default=0.25,
  dummy chit/.style={draw=none,fill=none,chit={}},
}
\def\shadechit{%
  \@ifnextchar[{\sh@dechit}{\sh@dechit[.5]}%]
}
\def\eliminatechit{%
  \@ifnextchar[{\elimin@techit}{\elimin@techit[.25]}%]
}
\def\sh@dechit[#1](#2){%
  % \message{^^JShading chit with opacity `#1'}%
  \pic[transform shape] at (#2) {chit/shade=#1};%
  \@ifnextchar;{\@gobble}{}}
\def\elimin@techit[#1](#2){%
  \pic[transform shape] at (#2) {chit/eliminate=#1};%
  \@ifnextchar;{\@gobble}{}}
\tikzset{%
  chit/stack direction/.store in=\chit@stack@dir,
  chit/stack direction/.initial={(.3,.3)},
}
\def\chit@stack@dir{(.3,.3)}
\def\stackchits(#1){%
  \@ifnextchar({\st@ckchits{#1}}{\st@ckchits{#1}(.3,.3)}%)
}
\def\st@ckchits#1(#2)#3{%
  \chit@dbg{2}{Stacking chits `#1', `#2', `#3'}%
  \edef\xy{#1}%
  \chit@dbg{4}{Stack start at \xy}%
  \foreach[count=\i from 0] \c/\o in {#3} {%
    \ifx\c\empty\else%
      \edef\ccc{\c}%
      \chit@dbg{2}{Adding \meaning\ccc\space to stack at (\xy)' `\o'}%
      \expandafter\ccc(\xy)%
      %%
      \ifx\c\o\else%
        %\chit@dbg{0}{Option: \o}
        \edef\ccc{\o}%
        \expandafter\ccc(\xy)%
      \fi
      \expandafter\ccc(\xy)%
      \tikzmath{%
        coordinate \cc;%
        \cc = (\xy) + (#2);}
      \xdef\xy{\cc}%
    \fi%
  }%
  \@ifnextchar;{\@gobble}{}%
}
\tikzset{
  chit/oob turn/.pic={\node[pic actions]{#1};}}
\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}
}
\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}
}
\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}
}
\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%
  }%
}%
\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}{}}%
\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%
  }%
}
\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}{}}%
\tikzset{
  chit/cell background/.style={draw=black},
  %% Define to not dp anyting to disable wings
  chit/cell wings/.style={
    dashed,
    dash pattern=on 0pt off 3pt on 3pt off 0pt,
    draw=black},
  %chit/cell background flipped/.style={fill=black},
  blank chit/.style={/chit/frame={draw=none,fill=none}},
  chit/grid lines/.style={dashed},
}
\def\chit@blank{blank chit}
\def\chit@cellbg(#1,#2)#3{%
  \draw[chit/cell background](#1-#3/2,#2-#3/2) rectangle++(#3,#3);
}
\def\chit@celldblbg(#1,#2)#3{%
  \draw[chit/cell background,chit/cell background flipped/.try]%
  (#1-#3/2,#2-#3/2) rectangle++(#3,#3);
}
\newif\ifchits@reset\chits@resettrue
\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}%
}
\def\chit@cell@frame#1#2{%
  \coordinate(cell@frame@north east) at ($(#1.north east)+( #2/2, #2/2)$);
  \coordinate(cell@frame@north west) at ($(#1.north west)+(-#2/2, #2/2)$);
  \coordinate(cell@frame@south east) at ($(#1.south east)+( #2/2,-#2/2)$);
  \coordinate(cell@frame@south west) at ($(#1.south west)+(-#2/2,-#2/2)$);
  \draw[chit/cell background,fill=none,scale line widths,line width=#2cm]
  (cell@frame@south west) rectangle (cell@frame@north east);
  \draw[scale line widths,line width=#2cm,chit/cell wings=10pt,fill=none,scale line widths,line width=#2cm]
  (cell@frame@north east)--++(     0,10*#2)
  (cell@frame@north east)--++( 10*#2,0)
  (cell@frame@north west)--++(     0,10*#2)
  (cell@frame@north west)--++(-10*#2,0)
  (cell@frame@south east)--++(     0,-10*#2)
  (cell@frame@south east)--++( 10*#2,0)
  (cell@frame@south west)--++(     0,-10*#2)
  (cell@frame@south west)--++(-10*#2,0)
  ;
}
\def\chits{%
  \@ifstar{\chits@resetfalse\@chits}{\chits@resettrue\@chits}}
\newcount\wg@col
\newcount\wg@row
\def\@chits#1#2#3{
  \ifchits@reset
    %\def\r{0}%
    %\def\c{0}%
    \coordinate(wg@next) at (0,0);
    \wg@col=1
    \wg@row=1
  \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%
              \ifx\u\chit@oob@vspacer%
                \chit@dbg{3}{Ignoring vertical spacer:\u}%
              \else
                \ifx\u\chit@oob@spacer%
                  \chit@dbg{3}{Ignoring horizontal spacer:\u}%
                \else
                  % \chit@cellbg(\c,\r){#3}%
                  %\chit[\u=\ti](\c,\r)%
                  \chit[\u=\ti](wg@next)(wg@chit)%
                  \chit@cell@frame{wg@chit}{#3}
                  \global\advance\wg@col1
                  \ifnum\wg@col>#2%
                    \path
                    let
                    \p1=(wg@chit.north),
                    \p2=(wg@chit.south),
                    \p3=(wg@chit),
                    \n1={\y3-\y1+\y2-#3cm} in
                    coordinate(wg@next) at (0,\n1);
                    \global\wg@col=1
                    \global\advance\wg@row1
                    \chit@dbg{10}{Row row, next column `\the\wg@col'}
                  \else
                    \path
                    let
                    \p1=(wg@chit.east),
                    \p2=(wg@chit.west),
                    \p3=(wg@chit),
                    \n1={\x3+\x1-\x2+#3cm} in
                    coordinate(wg@next) at (\n1,\y3);
                    \chit@dbg{10}{Next column `\the\wg@col'}
                  \fi
                  %\chit@sng@cellupdate(\c,\r){#2}{#3}%
                \fi%
              \fi%
            \fi%
          }%
        \fi%
      }%
    \fi%
  }%
  \chit@dbg{10}{Table is `\the\wg@col'x`\the\wg@row'}
  \@ifnextchar;{\@gobble}{}}
\def\chitgrid#1#2#3{%
  \pgfmathparse{#3/2}\edef\rmin{\pgfmathresult}%
  \pgfmathparse{#2*#3-#3/2}\edef\rmax{\pgfmathresult}%
  %\draw[red](-#3/2,\rmin)rectangle(#3*#1-#3/2,-\rmax);
  \foreach \cc in {0,...,#1}{
    \draw[chit/grid lines] (\cc*#3-#3/2,3*#3/4)--(\cc*#3-#3/2,-\rmax-#3/4);}
  %\chit@dbg{0}{Drawing horizontal lines from `\rmin, `-\rmin', ..., `-\rmax'}
  \foreach \rr in {\rmin,-\rmin,...,-\rmax}{
    %\chit@dbg{0}{Horizontal line at `\rr'}
    \draw[chit/grid lines] (-3*#3/4,\rr)--(#1*#3-#3/4,\rr);}
}
\def\chit@dbl@flip(#1,#2)#3{%
  \pgfmathparse{-#1}%
  \xdef\mc{\pgfmathresult}%
}
\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}%
}
\def\doublechits{%
  \@ifstar{\chits@resetfalse\@doublechits}{\chits@resettrue\@doublechits}}
\newdimen\chit@w
\newdimen\chit@h
\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}
    \coordinate(wg@next) at (0,0);%
    \coordinate(wg@fnxt) at (0,0);%
    \wg@col=1%
    \wg@row=1%
    \chit@w=0pt%
    \chit@h=0pt%
  \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
              \ifx\u\chit@oob@vspacer%
                \chit@dbg{3}{Ignoring vertical spacer:\u}%
              \else
                \ifx\u\chit@oob@spacer%
                  \chit@dbg{3}{Ignoring horizontal spacer:\u}%
                \else
                  \chit@dbg{10}{Drawing `\u' at wg@next}
                  \chit[\u=\ti](wg@next)(wg@chit)%
                  \chit@cell@frame{wg@chit}{#3}
                  \ifdim\chit@w=0pt
                    \pgfextractx\chit@w{\pgfpointanchor{wg@chit}{east}}%
                    \pgfextractx\wg@tmpa{\pgfpointanchor{wg@chit}{west}}%
                    \advance\chit@w-\wg@tmpa%
                    \global\advance\chit@w#3cm%
                    \pgfextracty\chit@h{\pgfpointanchor{wg@chit}{north}}%
                    \pgfextracty\wg@tmpa{\pgfpointanchor{wg@chit}{south}}%
                    \advance\chit@h-\wg@tmpa%
                    \global\advance\chit@h#3cm%
                  \fi
                  \ifnum\wg@col=1
                    \pgfextractx\wg@tmpa{\pgfpointanchor{wg@chit}{center}}%
                    \advance\wg@tmpa+\chit@w%
                    \coordinate(wg@fnxt) at ($(wg@chit)+(\the\chit@w,0pt)$);
                    %\coordinate(wg@fnxt
                    %\chit@dbg{10}{Calculating wg@fnxt since `\the\wg@col'==1}
                    %\path
                    %let
                    %\p1=(wg@chit.east),
                    %\p2=(wg@chit.west),
                    %\p3=(wg@chit),
                    %\n1={\x3+\x1-\x2+#3cm} in
                    %coordinate(wg@fnxt) at (\n1,\y3);
                  \fi
                  %\chit@dbg{10}{Drawing `\u\space flipped' at wg@fnxt}
                  \chit[\u\space flipped=\ti,
                  zone turn=\t,
                  zone mult=\n](wg@fnxt)(wg@flip)%
                  \chit@cell@frame{wg@flip}{#3}
                  \chit@dbg{10}{Next column: `\the\wg@col'}
                  \ifnum\wg@col=1
                    \ifnum\wg@row=1
                      \coordinate(wg@table@top) at (wg@chit.north east);
                    \fi
                    \coordinate(wg@table@bot) at (wg@chit.south east);
                  \fi
                  \global\advance\wg@col1
                  \ifnum\wg@col>#2%
                    % \path
                    %    let
                    %    \p1=(wg@chit.north),
                    %    \p2=(wg@chit.south),
                    %    \p3=(wg@chit),
                    %    \n1={\y3-\y1+\y2-#3cm} in %1.21991
                    %    coordinate(wg@next) at (0,\n1);
                    \coordinate(wg@next) at (0,-\wg@row\chit@h);
                    \global\wg@col=1
                    \global\advance\wg@row1
                    \chit@dbg{10}{Row row, next column `\the\wg@col'}
                  \else
                    % \path
                    % let
                    % \p1=(wg@chit.east),
                    % \p2=(wg@chit.west),
                    % \p3=(wg@chit),
                    % \p4=(wg@flip.east),
                    % \p5=(wg@flip.west),
                    % \p6=(wg@flip),
                    % \n1={\x3-\x1+\x2-#3cm},
                    % \n2={\x6+\x4-\x5+#3cm} in
                    % coordinate(wg@next) at (\n1,\y3)
                    % coordinate(wg@fnxt) at (\n2,\y6);
                    \coordinate(wg@next) at ($(wg@chit)+(-\the\chit@w,0)$);
                    \coordinate(wg@fnxt) at ($(wg@flip)+(+\the\chit@w,0)$);
                    \chit@dbg{10}{Next column `\the\wg@col'}
                  \fi
                \fi%
              \fi%
            \fi%
          }%
        \fi%
      }%
    \fi%
  }%
  \draw[dashed,scale line widths](wg@table@top)--++(0,.4);
  \draw[dashed,scale line widths](wg@table@bot)--++(0,-.4);
  \draw[dashed,scale line widths,{Stealth[]}-]
  ($(wg@table@top)+(0,.2)$) -- ++(.5,0)
  node[transform shape,anchor=west]{Back};
  \draw[dashed,scale line widths,{Stealth[]}-]
  ($(wg@table@top)+(0,.2)$) -- ++(-.5,0)
  node[transform shape,anchor=east]{Front};
  \draw[dashed,scale line widths,{Stealth[]}-]
  ($(wg@table@bot)+(0,-.2)$) -- ++(.5,0)
  node[transform shape,anchor=west]{Back};
  \draw[dashed,scale line widths,{Stealth[]}-]
  ($(wg@table@bot)+(0,-.2)$) -- ++(-.5,0)
  node[transform shape,anchor=east]{Front};
  % \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};%
  % \foreach \cc in {0,...,#2}{
  %   \draw[dashed] (\cc*#3,-3*#3/4)--(\cc*#3,\r-#3/4);
  %   \draw[dashed] (-\cc*#3,-3*#3/4)--(-\cc*#3,\r-#3/4);}
  % \pgfmathparse{#3/2}\edef\rmin{\pgfmathresult}%
  % \chit@dbg{0}{Drawing horizontal lines from `-\rmin, `\rmin', ..., `\r'}
  % \foreach \rr in {-\rmin,\rmin,...,\r}{
  %   \chit@dbg{0}{Horizontal line at `\rr'}
  %   \draw[dashed] (-#2*#3-#3/4,\rr)--(#2*#3+#3/4,\rr);}
  \@ifnextchar;{\@gobble}{}}
\def\doublechitgrid#1#2#3{%
  \message{^^JWARNING - the grid table might be messed up!}
  %\iffalse
  \pgfmathparse{#3/2}\edef\rmin{\pgfmathresult}%
  \pgfmathparse{#2*#3-#3/2}\edef\rmax{\pgfmathresult}%
  \foreach \cc in {0,...,#1}{
    \draw[chit/grid lines] (\cc*#3+\rmin,3*#3/4)--(\cc*#3+\rmin,-\rmax-#3/4);
    \draw[chit/grid lines] (-\cc*#3+\rmin,3*#3/4)--(-\cc*#3+\rmin,-\rmax-#3/4);}
  %\chit@dbg{0}{Drawing horizontal lines from `-\rmin, `\rmin', ..., `\rmax'}
  \foreach \rr in {\rmin,-\rmin,...,-\rmax}{
    \chit@dbg{0}{Horizontal line at `\rr'}
    \draw[chit/grid lines] (-#1*#3-#3/4+\rmin,\rr)--(#1*#3+#3/4+\rmin,\rr);}
  %\fi
}
\tikzset{%
  battle marker/.pic={
    \node[shape=circle,
    font=\sffamily\bfseries,
    inner sep=0pt,
    minimum size=5mm,
    draw=black,
    fill=yellow!85!black,
    every battle marker/.try] at (-.3,.3) {%
      \ifnum#1>0\relax #1\fi%
    };
  },
  battle marker/.style={
    chit={full={battle marker=#1},frame={draw=none}}},
}
\tikzset{%
  pics/odds marker/.style args={#1,#2}{
    code={
      \node[shape=circle,
      font=\sffamily\bfseries\large,
      inner sep=0pt,
      minimum size=8mm,
      draw=black,
      fill=#2,
      every odds marker/.try] at (.16,-.16) {#1};
    }
  },
  odds marker/.style args={#1,#2}{
    chit={full={odds marker={#1,#2}},frame={draw=none}}},
}
\tikzset{
  pics/result marker/.style args={#1,#2}{
    code={
      \chit@dbg{3}{Results marker #1 (#2)}
      \node[shape=circle,
      font=\sffamily\bfseries\large,
      inner sep=0pt,
      minimum size=8mm,
      draw=black,
      fill=#2,
      every result marker/.try] at (0,0) {#1};}},
  result marker/.style args={#1,#2}{
    chit={full={result marker={#1,#2}},frame={draw=none}}}
}
\tikzset{
  dice bg/.style={
    % /utils/exec={
    %   \pgfgettransformentries{%
    %     \wg@jaca}{%
    %     \wg@jacb}{%
    %     \wg@jacc}{%
    %     \wg@jacd}{%
    %     \wg@tmp}{%
    %     \wg@tmp}%
    %   \pgfmathsetmacro{\wg@tmp}{%
    %     sqrt(abs(\wg@jaca*\wg@jacd-\wg@jacb*\wg@jacc))}
    %   \xdef\wg@tmp{\wg@tmp}},%
    fill=black,
    draw=none,
    minimum width=1cm,
    minimum height=1cm,
    scale rounded corners,
    rounded corners=.1cm,
    inner sep=0pt,
    transform shape},
  dice fg/.style={
    fill=white,
    shape=circle,
    inner sep=0pt,
    minimum size=.2cm,
    transform shape},
  pics/dice/.style={
    code={
      \node[dice bg] (dice bg) {};
      \ifodd#1\node[dice fg] at (dice bg) {};\fi
      \ifnum#1>1%
      \node[dice fg] at ($(dice bg)+(-45:.4)$){};%
      \node[dice fg] at ($(dice bg)+(135:.4)$){};%
      \fi%
      \ifnum#1>3%
      \node[dice fg] at ($(dice bg)+(  45:.4)$){};%
      \node[dice fg] at ($(dice bg)+(-135:.4)$){};%
      \fi%
      \ifnum#1=6%
      \node[dice fg] at ($(dice bg)+(-.282,0)$){};
      \node[dice fg] at ($(dice bg)+( .282,0)$){};
      \fi
    }
  },
  pics/dice/.default=3
}
\newcommand\dicemark[2][scale=.5]{%
  \tikz[baseline={($(dice bg.south east)!.25!(dice bg.north east)$)},#1]{
    \pic[transform shape]{dice=3};}}
\pgfdeclareshape{d4}{
  \anchor{center}{\pgfpointorigin}    % within the node, (0,0) is the center
  \anchor{text}{
    % this is used to center the text in the node
    \pgfpoint{-.5\wd\pgfnodeparttextbox}{-.5\ht\pgfnodeparttextbox}}
  \backgroundpath{ % draw border
    \pgfpathmoveto{\pgfpoint{0cm}{.4cm}}
    \pgfpathlineto{\pgfpoint{.433cm}{-.35cm}}
    \pgfpathlineto{\pgfpoint{-.433cm}{-.35cm}}
    \pgfpathlineto{\pgfpoint{0cm}{.4cm}}
    % \pgfusepath{draw}  %draw border
    % \pgfusepath{draw}  %draw rectangle
  }}
\newif\ifwg@dsixdot\wg@dsixdotfalse
\tikzset{
  d6 dots/.is if=wg@dsixdot,
  d6 dots/.initial=false,
  d6 dots/.default=true
}
\pgfdeclareshape{d6}{
  \anchor{center}{\pgfpointorigin}    % within the node, (0,0) is the center
  \anchor{text}{
    % this is used to center the text in the node
    \pgfpoint{-.5\wd\pgfnodeparttextbox}{-.5\ht\pgfnodeparttextbox}}
  \backgroundpath{ % draw border
    \pgfpathrectanglecorners{\pgfpoint{.4cm}{.4cm}}{\pgfpoint{-.4cm}{-.4cm}}
    % \pgfusepath{draw}  %draw rectangle
  }
  \behindforegroundpath{ % draw border
    \ifwg@dsixdot%
      \edef\numdots{\tikz@node@content}%
      % Draw over text
      \pgfpathrectanglecorners{\pgfpoint{.4cm}{.4cm}}{\pgfpoint{-.4cm}{-.4cm}}%
      \pgfusepath{fill}  %draw rectangle
      \ifx\tikz@textcolor\pgfutilempty%
        \pgfutil@colorlet{.}{pgfstrokecolor}%
      \else
        % \pgfsetfillcolor{\tikz@textcolor}%
        \pgfutil@colorlet{.}{\tikz@textcolor}%
      \fi
      \pgfsetfillcolor{.}%
      \ifodd\numdots
        %\message{^^JCenter dot}
        \pgfpathcircle{\pgfpoint{0cm}{0cm}}{.09cm}
      \fi
      \ifnum\numdots=2%
        %\message{^^JSpecial 2}
        \pgfpathcircle{\pgfpointpolar{-45}{.32cm}}{.09cm}
        \pgfpathcircle{\pgfpointpolar{135}{.32cm}}{.09cm}
      \fi%
      \ifnum\numdots>2%
        %\message{^^JAt least 2}
        \pgfpathcircle{\pgfpointpolar{-45}{.35cm}}{.09cm}
        \pgfpathcircle{\pgfpointpolar{135}{.35cm}}{.09cm}
      \fi%
      \ifnum\numdots>3%
        %\message{^^JAt least 4}
        \pgfpathcircle{\pgfpointpolar{  45}{.35cm}}{.09cm}
        \pgfpathcircle{\pgfpointpolar{-135}{.35cm}}{.09cm}
      \fi%
      \ifnum\numdots=6%
        %\message{^^JLucky 6}
        \pgfpathcircle{\pgfpoint{-.247cm}{0cm}}{.09cm}
        \pgfpathcircle{\pgfpoint{ .247cm}{0cm}}{.09cm}
      \fi
      \pgfusepath{fill}  %draw rectangle
    \fi%
  }
}
\pgfdeclareshape{d8}{
  \anchor{center}{\pgfpointorigin}    % within the node, (0,0) is the center
  \anchor{text}{
    % this is used to center the text in the node
    \pgfpoint{-.5\wd\pgfnodeparttextbox}{-.5\ht\pgfnodeparttextbox}}
  \backgroundpath{ % draw border
    \pgfpathmoveto{\pgfpoint{0cm}{.5cm}}
    \pgfpathlineto{\pgfpoint{.433cm}{.25cm}}
    \pgfpathlineto{\pgfpoint{.433cm}{-.25cm}}
    \pgfpathlineto{\pgfpoint{0cm}{-.5cm}}
    \pgfpathlineto{\pgfpoint{-.433cm}{-.25cm}}
    \pgfpathlineto{\pgfpoint{-.433cm}{.25cm}}
    \pgfpathlineto{\pgfpoint{0cm}{.5cm}}
    \pgfpathlineto{\pgfpoint{.433cm}{-.25cm}}
    \pgfpathlineto{\pgfpoint{-.433cm}{-.25cm}}
    \pgfpathlineto{\pgfpoint{0cm}{.5cm}}
    % \pgfusepath{draw}  %draw interiaor
  }}
\pgfdeclareshape{d10}{
  \anchor{center}{\pgfpointorigin}    % within the node, (0,0) is the center
  \anchor{text}{
    % this is used to center the text in the node
    \pgfpoint{-.5\wd\pgfnodeparttextbox}{-.5\ht\pgfnodeparttextbox}}
  \backgroundpath{ % draw border
    \pgfpathmoveto{\pgfpoint{0cm}{.5cm}}
    \pgfpathlineto{\pgfpoint{.294cm}{-.154cm}}
    \pgfpathlineto{\pgfpoint{0cm}{-.3cm}}
    \pgfpathlineto{\pgfpoint{-.294cm}{-.154cm}}
    \pgfpathlineto{\pgfpoint{0cm}{.5cm}}
    \pgfpathlineto{\pgfpoint{.475cm}{.1cm}}
    \pgfpathlineto{\pgfpoint{.475cm}{-.1cm}}
    \pgfpathlineto{\pgfpoint{0cm}{-.5cm}}
    \pgfpathlineto{\pgfpoint{-.475cm}{-.1cm}}
    \pgfpathlineto{\pgfpoint{-.475cm}{.1cm}}
    \pgfpathlineto{\pgfpoint{0cm}{.5cm}}
    \pgfpathmoveto{\pgfpoint{.294cm}{-.154cm}}
    \pgfpathlineto{\pgfpoint{.475cm}{-.1cm}}
    \pgfpathmoveto{\pgfpoint{-.475cm}{-.1cm}}
    \pgfpathlineto{\pgfpoint{-.294cm}{-.154cm}}
    \pgfpathmoveto{\pgfpoint{0cm}{-.5cm}}
    \pgfpathlineto{\pgfpoint{0cm}{-.3cm}}
    % \pgfusepath{draw}  %draw interiaor
  }}
\pgfdeclareshape{d12}{
  \anchor{center}{\pgfpointorigin}    % within the node, (0,0) is the center
  \anchor{text}{   % this is used to center the text in the node
    \pgfpoint{-.5\wd\pgfnodeparttextbox}{-.5\ht\pgfnodeparttextbox}}
  \backgroundpath{ % draw border
    \pgfpathmoveto{\pgfpoint{0cm}{.5cm}}
    \pgfpathlineto{\pgfpoint{0.294cm}{.405cm}}
    \pgfpathlineto{\pgfpoint{.475cm}{.173cm}}
    \pgfpathlineto{\pgfpoint{.475cm}{-.173cm}}
    \pgfpathlineto{\pgfpoint{.294cm}{-.405cm}}
    \pgfpathlineto{\pgfpoint{0cm}{-.5cm}}
    \pgfpathlineto{\pgfpoint{-.294cm}{-.405cm}}
    \pgfpathlineto{\pgfpoint{-.475cm}{-.173cm}}
    \pgfpathlineto{\pgfpoint{-.475cm}{.173cm}}
    \pgfpathlineto{\pgfpoint{-.294cm}{.405cm}}
    \pgfpathlineto{\pgfpoint{0cm}{.5cm}}
    \pgfpathlineto{\pgfpoint{0cm}{.349cm}}
    \pgfpathlineto{\pgfpoint{.332cm}{.108cm}}
    \pgfpathlineto{\pgfpoint{.205cm}{-.282cm}}
    \pgfpathlineto{\pgfpoint{-.205cm}{-.282cm}}
    \pgfpathlineto{\pgfpoint{-.332cm}{.108cm}}
    \pgfpathlineto{\pgfpoint{0cm}{.349cm}}
    \pgfpathmoveto{\pgfpoint{.475cm}{.173cm}}
    \pgfpathlineto{\pgfpoint{.332cm}{.108cm}}
    \pgfpathmoveto{\pgfpoint{.294cm}{-.405cm}}
    \pgfpathlineto{\pgfpoint{.205cm}{-.282cm}}
    \pgfpathmoveto{\pgfpoint{-.294cm}{-.405cm}}
    \pgfpathlineto{\pgfpoint{-.205cm}{-.282cm}}
    \pgfpathmoveto{\pgfpoint{-.475cm}{.173cm}}
    \pgfpathlineto{\pgfpoint{-.332cm}{.108cm}}
    % \pgfusepath{draw}  %draw interiaor
  }}
\pgfdeclareshape{d20}{
  \anchor{center}{\pgfpointorigin} % within the node, (0,0) is the center
  \anchor{text}{    % this is used to center the text in the node
    \pgfpoint{-.5\wd\pgfnodeparttextbox}{-.5\ht\pgfnodeparttextbox}}
  \backgroundpath{ % draw border
    \pgfpathmoveto{\pgfpoint{0cm}{.5cm}}
    \pgfpathlineto{\pgfpoint{.454cm}{.262cm}}
    \pgfpathlineto{\pgfpoint{.454cm}{-.262cm}}
    \pgfpathlineto{\pgfpoint{0cm}{-.5cm}}
    \pgfpathlineto{\pgfpoint{-.454cm}{-.262cm}}
    \pgfpathlineto{\pgfpoint{-.454cm}{.262cm}}
    \pgfpathlineto{\pgfpoint{0cm}{.5cm}}
    \pgfpathlineto{\pgfpoint{0cm}{.292cm}}
    \pgfpathlineto{\pgfpoint{.253cm}{-.146cm}}
    \pgfpathlineto{\pgfpoint{-.253cm}{-.146cm}}
    \pgfpathlineto{\pgfpoint{0cm}{.292cm}}
    \pgfpathlineto{\pgfpoint{.454cm}{.262cm}}
    \pgfpathlineto{\pgfpoint{.253cm}{-.146cm}}
    \pgfpathlineto{\pgfpoint{0cm}{-.5cm}}
    \pgfpathlineto{\pgfpoint{-.253cm}{-.146cm}}
    \pgfpathlineto{\pgfpoint{-.454cm}{.262cm}}
    \pgfpathlineto{\pgfpoint{0cm}{.292cm}}
    \pgfpathmoveto{\pgfpoint{.454cm}{-.262cm}}
    \pgfpathlineto{\pgfpoint{.253cm}{-.146cm}}
    \pgfpathmoveto{\pgfpoint{-.454cm}{-.262cm}}
    \pgfpathlineto{\pgfpoint{-.253cm}{-.146cm}}
    % \pgfusepath{draw}  %draw interiaor
  }}
\usetikzlibrary{shadows.blur}
\newif\ifwg@chit@drop\wg@chit@dropfalse
\tikzset{
  chit has drop/.is if=wg@chit@drop,
  chit has drop/.default=true,
  chit has drop/.initial=false,
  /tikz/render blur shadow/.add code={%
    \chit@dbg{2}{Number of blur steps: \pgfbs@steps}%
    \ifnum\pgfbs@steps=0\else
    \chit@dbg{2}{Making shadow blur}%
    }{\fi}}
\tikzset{%
  chit drop/.code={%
    %% \message{^^J Args `#1'}%
    \pgfkeysalso{%
      chit has drop=true,
      /tikz/blur shadow={shadow blur steps=5,
        shadow opacity=30,
        shadow xshift=.05cm,
        shadow yshift=-.05cm,
        shadow blur radius=.05cm,
        #1}}%
    \ifnum\pgfbs@steps=0%
      \gdef\wg@drop@margin{0pt}%
    \else%
      \ifwg@chit@drop%
        \pgfmathparse{
          \pgfbs@radius+
          veclen(
          \pgfkeysvalueof{/tikz/shadow xshift},
          \pgfkeysvalueof{/tikz/shadow yshift})}
        \xdef\wg@drop@margin{\pgfmathresult pt}%
      \else%
        \gdef\wg@drop@margin{0pt}%
      \fi
      %% \message{^^J Drop margin is `\wg@drop@margin'
      %%   `\pgfbs@radius'
      %%   `\pgfkeysvalueof{/tikz/shadow xshift}',
      %%   `\pgfkeysvalueof{/tikz/shadow yshift}'}%
    \fi%
  },%
  chit drop/.default=,%
  no chit drop/.code={%
    \pgfkeysalso{
      /tikz/blur shadow={shadow blur steps=0}}
    \gdef\wg@drop@margin{0pt}%
  }
}%
\tikzset{
  chit/text base/.style={
    shape=rectangle,
    inner sep=0pt,
    align=center,
    text width=1.1cm},
  chit/number/.style={
    chit/text base,
    font=\sffamily\bfseries\fontsize{12}{14}\selectfont},
  chit/game turn/.style={
    chit/text base,
    font=\sffamily\bfseries},
  chit/text/.style={
    chit/text base,
    font=\sffamily\bfseries},
  chit/small text/.style={
    chit/text base,
    font=\sffamily\bfseries\fontsize{9}{10}\selectfont},
  chit/number/.pic={\node[chit/number]{#1};},
  chit/game turn/.pic={\node[chit/game turn]{Game\\Turn};},
  chit/text/.pic={\node[chit/text]{#1};},
  chit/small text/.pic={\node[chit/small text]{#1};},
  game turn chit/.style={
    /chit/full={chit/game turn},
    color=black,
    fill=white},
  game turn chit flipped/.style={game turn chit},
  dummy chit/.style={fill=white},
}
\providecommand\chitmark[2][]{\tikz[scale=.25,#1]{\chit[#2]}}
\tikzset{
  wg stacking/.style={fill=white,
    /chit/symbol={[faction=friendly,command=land]}},
}
\DeclareRobustCommand\stackmark[1][]{%
  \tikz[baseline=(current bounding box.center),scale=.3,#1]{
    \stackchits(0,0)(.3,-.3){%
      \noexpand\chit[wg stacking],
      \noexpand\chit[wg stacking],
      \noexpand\chit[wg stacking]}}}
\DeclareRobustCommand\zocmark[1][]{%
  \tikz[baseline=($(current bounding box.center)!.5!(current bounding box.south)$),scale=.1,#1]{%
    \begin{scope}[hex/first row and column are=0,
      hex/row direction is=normal,
      hex/column direction is=normal,
      hex/short columns=none]
      \hex[label=,fill=gray](c=1,r=1)%
      \hex[label=,fill=white](c=1,r=2)%
      \hex[label=,fill=white](c=1,r=0)%
      \hex[label=,fill=white](c=0,r=0)%
      \hex[label=,fill=white](c=0,r=1)%
      \hex[label=,fill=white](c=2,r=1)%
      \hex[label=,fill=white](c=2,r=0)
    \end{scope}}}
\tikzset{
  zone point/.code n args={3}{},
  zone oob point/.code n args={3}{}}
%% Local Variables:
%%   mode: LaTeX
%% End:
%%
%% End of file `tikzlibrarywargame.chit.code.tex'.
