% \iffalse
% --------------------------------------------------------------------
%<*natoapp6c>
% \fi
% \subsubsection{Text \texttt{natoapp6c} namespace}
%
% \begin{NatoAppKey}{/natoapp6c}
%
%   Here, we set up the key path \spec{/natoapp6c}
%
%    \begin{macrocode}
\def\natoapp@report{}
\tikzset{
  /natoapp6c/.search also={/tikz},
  /natoapp6c/.cd,
}
%    \end{macrocode}
% \end{NatoAppKey}
%
% \subsubsubsection{Choices of faction, command, and echelon}
%
% \begin{NatoAppKey}{natoapp6c/id,
%   natoapp6c/fac,
%   natoapp6c/cmd,
%   natoapp6c/ech}
%
%   The keys \spec{id}, spec{fac}, \spec{cmd}, and \spec{ech} are
%   internal keys used to store the choice of faction, command, and
%   echelon, respectively, in.
%
%    \begin{macrocode}
\tikzset{
  /natoapp6c/.cd,
  id/.store in=\natoapp@id,
  fac/.store in=\natoapp@fac,
  cmd/.store in=\natoapp@cmd,
  ech/.store in=\natoapp@ech,
  path/.store in=\n@to@ppp@th
}  
%    \end{macrocode}
% \end{NatoAppKey}
%
% \begin{NatoAppKey}{natoapp6c/faction}
%
%   Choice of \meta{faction}.  This is limited to predefined values.
%   The choice is stored in the key \spec{natoapp6c/fac}.
% 
%    \begin{macrocode}
\tikzset{
  /natoapp6c/.cd,
  faction/.is choice,
  faction/none/.code={\let\natoapp@fac\@undefined},
  faction/friendly/.style={fac=friendly},
  faction/friend/.style={fac=friendly},
  faction/hostile/.style={fac=hostile},
  faction/enemy/.style={fac=hostile},
  faction/neutral/.style={fac=neutral},
  faction/unknown/.style={fac=unknown},
  faction/?/.style={fac=unknown},
  faction/.initial=friendly,
}
%    \end{macrocode}
% \end{NatoAppKey}
% 
% \begin{NatoAppKey}{natoapp6c/command}
%
%   Choice of \meta{command}.  This is limited to predefined values.
%   The choice is stored in the key \spec{natoapp6c/cmd}.
% 
%    \begin{macrocode}
\tikzset{
  /natoapp6c/.cd,
  command/.is choice,
  command/base/.style={cmd=base},
  command/activity/.style={cmd=activity},
  command/air/.style={cmd=air},
  command/missile/.style={cmd=air},
  command/equipment/.style={cmd=equipment},
  command/installation/.style={cmd=installation},
  command/land/.style={cmd=land},
  command/sea surface/.style={cmd=sea surface},
  command/space/.style={cmd=space},
  command/sub surface/.style={cmd=sub surface},
  command/sea mine/.style={cmd=sub surface},
  command/dismounted/.style={cmd=dismounted},
  command/none/.style={cmd=none},
}
%    \end{macrocode}
% \end{NatoAppKey}
%
% \begin{NatoAppKey}{natoapp6c/echolon}
%
%   Unit size.  The choice is limited to one of the below.  The choice
%   is stored in the key \spec{natoapp6c/ech}.
% 
%    \begin{macrocode}
\tikzset{
  /natoapp6c/.cd,
  echelon/.is choice,
  echelon/none/.style={ech=},
  echelon/team/.style={ech=},
  echelon/squad/.style={ech=squad},
  echelon/section/.style={ech=section},
  echelon/platoon/.style={ech=platoon},
  echelon/company/.style={ech=company},
  echelon/battalion/.style={ech=battalion},
  echelon/regiment/.style={ech=regiment},
  echelon/brigade/.style={ech=brigade},
  echelon/division/.style={ech=division},
  echelon/corps/.style={ech=corps},
  echelon/army/.style={ech=army},
  echelon/army group/.style={ech=army group},
  echelon/theatre/.style={ech=theatre},
  echelon/command/.style={ech=command},
  echelon/dummy/.style={ech=dummy},
}
%    \end{macrocode}
% \end{NatoAppKey}
%
% \begin{NatoAppKey}{natoapp6c/main,
%                    natoapp6c/left,
%                    natoapp6c/right,
%                    natoapp6c/top,
%                    natoapp6c/bottom,
%                    natoapp6c/below,
%                    natoapp6c/frame}
% \begin{Macro}{\natoapp@main,
%               \natoapp@left,
%               \natoapp@right,
%               \natoapp@upper,
%               \natoapp@lower,
%               \natoapp@below}
%
%   The various parts of the symbols.  The keys \spec{upper} and
%   \spec{lower} are aliases for \spec{top} and \spec{bottom},
%   respectively.   The choices are stored in macros 
% 
%    \begin{macrocode}
\newif\ifnatoapp@decoy\natoapp@decoyfalse
\tikzset{
  /natoapp6c/.cd,
  main/.store in=\natoapp@main,   main/.initial=,%
  left/.store in=\natoapp@left,   left/.initial=,%    
  right/.store in=\natoapp@right, right/.initial=,%
  upper/.store in=\natoapp@upper, upper/.initial=,%
  lower/.store in=\natoapp@lower, lower/.initial=,%
  top/.store in=\natoapp@upper,%   
  bottom/.store in=\natoapp@lower,%
  below/.store in=\natoapp@below, below/.initial=,%
  frame/.store in=\natoapp@frame, frame/.initial=,%
  decoy/.is if=natoapp@decoy,%
}
%    \end{macrocode}
% \end{Macro}
% \end{NatoAppKey}
%
% \begin{TikzKey}{/tikz/natoapp6c/main,
%   /tikz/natoapp6c/modifiers,
%   /tikz/natoapp6c/lower,
%   /tikz/natoapp6c/upper,
%   /tikz/natoapp6c/left,
%   /tikz/natoapp6c/right,
%   /tikz/natoapp6c/echelon,
%   /tikz/natoapp6c/below}
%
% Styles used by the various parts of the symbol.
% 
%    \begin{macrocode}
\tikzset{
  natoapp6c/parts/.style={
    scale line widths,
    draw,
    shape=rectangle,
    transform shape},
  natoapp6c/main/.style={natoapp6c/parts},
  natoapp6c/modifiers/.style={natoapp6c/parts,scale=.6},
  natoapp6c/lower/.style={natoapp6c/parts},
  natoapp6c/upper/.style={natoapp6c/parts},
  natoapp6c/left/.style={natoapp6c/parts},
  natoapp6c/right/.style={natoapp6c/parts},
  natoapp6c/echelon/.style={natoapp6c/parts},
  natoapp6c/below/.style={natoapp6c/parts}
}      
%    \end{macrocode}
% \end{TikzKey}
% \iffalse
% --------------------------------------------------------------------
% \fi
% 
% \subsubsection{The \texttt{natoapp6c} styles}
% 
% \begin{TikzKey}{/tikz/natoapp6c}
%   This key sets up a node to make a NATO App6(c) symbol.  The key
%   takes a single argument which in turn must contain key--value
%   pairs in the \texttt{/natoapp6c} (or \texttt{/tikz}) namespace(s).  We
%   set the \texttt{shape} parameter of the node, and calls the passed
%   keys in the \texttt{/natoapp6c} namespace to set-up elements of the
%   chit.
%
%    \begin{macrocode}
\tikzset{%
  natoapp6c/.code={%
    \pgfkeys{/tikz/transform shape,/tikz/shape=natoapp6c}
    \pgfkeys{/natoapp6c/.cd,path=natoapp6c/s/,#1}}}
%    \end{macrocode}
% \end{TikzKey}
%
% We define a counter to set-up unique names for symbol nodes.
% 
%    \begin{macrocode}
\newcounter{natoappid}\setcounter{natoappid}{0}
%    \end{macrocode}
%
% \iffalse
% --------------------------------------------------------------------
% \fi
% \subsubsection{The \cs{natoapp6c} shape}
%
% \begin{Macro}{\ifn@to@pp@below,\ifn@to@pp@mod}
%
%   We define an \cs{if} to allow us to detect if something is
%   rendered below the frame
% 
%    \begin{macrocode}
\newif\ifn@to@pp@below\n@to@pp@belowfalse%
\newif\ifn@to@pp@mod\n@to@pp@modfalse%
%    \end{macrocode}
% \end{Macro}
%
% \begin{NatoAppFrame}{natoapp6c}
%
%   Next, we define the mother shape of NATO App6(c) nodes.  This is a
%   composite node with sub-nodes for the various parts (including the
%   frame) of the symbol.
%
%   It is quite complex so we will go through the implementation in
%   bits.
%
%   First, we make some saved anchors (the centre) and macros
%   (identifier, frame type, and frame options).
%   
%    \begin{macrocode}
% \def\wg@n@to@p@th{}
\pgfdeclareshape{natoapp6c}{%
  \savedanchor\center{\pgf@x=0cm\pgf@y=0cm}
  \savedmacro\id{%
    \n@to@pp@dbg{3}{NATO App6(c) id (set): \meaning\natoapp@id}
    \@ifundefined{natoapp@id}{\let\natoapp@id\pgfutil@empty}{}%
    \ifx\natoapp@id\pgfutil@empty\relax%
      \wg@r@ndom@id%
      \edef\id{natoapp6c\wg@uuid}%
    \else%
      \edef\id{\natoapp@id}%
    \fi%
    \n@to@pp@dbg{3}{NATO App6(c) id: \meaning\id}}      
  \savedmacro\frameshape{%
    \let\frameshape\pgfutil@empty%
    \@ifundefined{natoapp@cmd}{\def\frameshape{base}}{%
      \edef\frameshape{\natoapp@cmd}
      \@ifundefined{natoapp@fac}{\def\frameshape{base}}{%
        \edef\frameshape{\natoapp@fac\space\frameshape}}}
    \n@to@pp@dbg{3}{NATO App6(c) frame shape: \meaning\frameshape}}
  \savedmacro\frameopt{%
    \let\frameopt\pgfutil@empty%
    \@ifundefined{natoapp@frame}{}{%
      \edef\frameopt{\natoapp@frame}}
    \n@to@pp@dbg{3}{NATO App6(c) Frame options: \meaning\frameopt}%
  }
  \savedmacro\thisname{\def\thisname{natoapp6c}}
%    \end{macrocode}
%
% Then we define a number of regular anchors 
% 
%    \begin{macrocode}
  \anchor{center}    {\center}
%    \end{macrocode}
% 
% The remaining anchors depend on the shape being used.   We reference
% the anchors of the embedded node of the frame. 
%
%    \begin{macrocode}
  \anchor{north east}{\wg@sub@nchor{M\id}{north east}}
  \anchor{north west}{\wg@sub@nchor{M\id}{north west}}
  \anchor{south east}{\wg@sub@nchor{M\id}{south east}}
  \anchor{south west}{\wg@sub@nchor{M\id}{south west}}
  \anchor{north}     {\wg@sub@nchor{M\id}{north}}
  \anchor{west}      {\wg@sub@nchor{M\id}{west}}
  \anchor{south}     {\wg@sub@nchor{M\id}{south}}
  \anchor{east}      {\wg@sub@nchor{M\id}{east}}
  \anchor{upper}     {\wg@sub@nchor{M\id}{upper}}
  \anchor{lower}     {\wg@sub@nchor{M\id}{lower}}
  \anchor{left}      {\wg@sub@nchor{M\id}{left}}
  \anchor{right}     {\wg@sub@nchor{M\id}{right}}
%    \end{macrocode}
%
%  The next two anchors are a little funny.
%
%    \begin{macrocode}
  \anchor{echelon}   {%
    \wg@sub@nchor{M}{north}%
    \wg@tmpa\pgflinewidth% by 1.5%
    %\wg@getscale%
    %\pgfmathparse{ifthenelse(\wg@scale>0.00001,\wg@tmpa/\wg@scale,\wg@tmpa)}
    %\edef\wg@a{\pgfmathresult}\pgfmathsetlength{\wg@tmpa}{\wg@a pt}
    %\n@to@pp@dbg{0}{Scale is `\wg@scale' -> `\the\wg@tmpa'}%
    %\divide\wg@tmpa by \wg@scale%
    \advance\wg@tmpa by\n@to@pp@e@y cm%
    \advance\pgf@y\wg@tmpa%
  }
  \anchor{below}     {%
    \n@to@pp@dbg{3}{NATO App6(c) get below anchor}%
    \wg@sub@nchor{M}{south}%
    \wg@tmpa=\n@to@pp@e@yy cm%
    \advance\wg@tmpa-\pgflinewidth% by 1.5%
    \advance\pgf@y-\wg@tmpa%
  }
%    \end{macrocode}
%
% All right, so time to make the actual frame.  Note that we do this
% in a `behind' path so we can actually draw stuff.  First, we flag
% that we're not in a modifier, nor in the `below' part.
%
%    \begin{macrocode}
  \behindbackgroundpath{%
    \wg@ignore@sub@nchortrue%
    \n@to@pp@dbg{3}{NATO App6(c) Before print}
    \n@to@pp@dbg{3}{NATO App6(c) background path: \meaning\id
      ^^J  ID:      \meaning\natoapp@id
      ^^J  Faction: \meaning\natoapp@fac
      ^^J  Command: \meaning\natoapp@cmd
      ^^J  Echelon: \meaning\natoapp@ech
      ^^J  Main:    \meaning\natoapp@main
      ^^J  Left:    \meaning\natoapp@left
      ^^J  Right:   \meaning\natoapp@right
      ^^J  Upper:   \meaning\natoapp@upper
      ^^J  Lower:   \meaning\natoapp@lower
      ^^J  Below:   \meaning\natoapp@below
      ^^J  Shape:   \meaning\frameshape
      ^^J  Options: \meaning\frameopt}
    \natoapp@report
    \n@to@pp@modfalse
    \n@to@pp@belowfalse
%    \end{macrocode}
%
% If the symbol is empty, then do nothing.
%
%    \begin{macrocode}
    \ifx\frameshape\pgfutil@empty%
    \n@to@pp@dbg{2}{NATO App6(c) has no frame!}
    \else
%    \end{macrocode}
%
% We start a scope because we want to do some clipping here.  Then, we
% use the frame to clip the remaining part.   Note that we do this via
% a node which we give the identifier \spec{M}.   Various elements of
% the symbol can then refer to this shape to define paths, etc. 
%
%    \begin{macrocode}
    \begin{scope}
      \pgfinterruptboundingbox
      %% Clip to shape in scope
      %% \message{^^JClipping to NATO App6(c) shape}
      \n@to@pp@iscliptrue%
      \n@to@pp@dbg{1}{NATO App6(c) frame node M (clip)}
      \pgfnode{natoapp6c \frameshape}{center}{}{M}{\pgfusepath{clip}}
      \n@to@pp@isclipfalse%
%    \end{macrocode}
%
% Next, we should see if we need to fill the frame.  We do that by
% expanding the passed \spec{frame} key-values in a scope, and
% \emph{then} get the fill colour.
%
%    \begin{macrocode}
      %% Start new scope including frame key options 
      \edef\tmp@opt{[\frameopt]}
      \expandafter\scope\tmp@opt
      % Get fill color {possibly from frame key}
      \expandafter\let\expandafter\tmp@fill%
      \csname\string\color@pgffillcolor\endcsname%
%    \end{macrocode}
%
%  If the fill colour is not \cs{relax}, then we fill the frame.  Note
%  that this is done in the background, so when we draw in the
%  foreground we will render on top of the fill. 
%
%    \begin{macrocode}      
      % Check if we need to fill shape (fill colour us not \relax)
      \ifx\tmp@fill\relax\else%
      \n@to@pp@dbg{2}{NATO App6(c) frame fill}
      \pgfnode{natoapp6c \frameshape}{center}{}{}{\pgfusepath{fill}}%
      \fi%
      % End the fill scope 
      \endscope%
%    \end{macrocode}
%
% Now we need to render some of the elements of the symbol. We start
% with the main elements.  We can specify many main elements (to make
% composite symbols). 
%
%    \begin{macrocode}
      % Render mains 
      \@ifundefined{natoapp@main}{}{
        \n@to@pp@dbg{1}{NATO App6(c) mains: \meaning\natoapp@main}
        \begin{scope}[natoapp6c/main]
          \n@to@pp@dbg{1}{NATO symbol path `\n@to@ppp@th'}
          \wg@pic@all{\natoapp@main}{\n@to@ppp@th}{M.center}{natoapp6c/main}%
        \end{scope}}%
      % Modififiers flagged
%    \end{macrocode}
%
% The next thing is to render the various modifiers.  We start by
% flagging this globally. 
%
%    \begin{macrocode}
      \n@to@pp@modtrue
      \n@to@pp@dbg{2}{NATO App6(c) modifiers}
%    \end{macrocode}
%
% Below we render the lower, upper, left, and right elements.  This is
% all done in the same way.  Note that the elements positions are
% dictated by anchors of the frame shape (via shape identifier
% \spec{M}). 
%
%    \begin{macrocode}
      % Render lowers
      \@ifundefined{natoapp@lower}{}{%
        \begin{scope}%
          \wg@pic@all{\natoapp@lower}{natoapp6c/s/}{M.lower}{%
            natoapp6c/modifiers,natoapp6c/lower}%
        \end{scope}}%     
      % Render uppers
      \@ifundefined{natoapp@upper}{}{%
        \begin{scope}[]
          \wg@pic@all{\natoapp@upper}{natoapp6c/s/}{M.upper}{%
            natoapp6c/modifiers,natoapp6c/upper}%
        \end{scope}}%
      % Render lefts
      \@ifundefined{natoapp@left}{}{%
        \begin{scope}[]
          \wg@pic@all{\natoapp@left}{natoapp6c/s/}{M.left}{%
            natoapp6c/modifiers,natoapp6c/left}%
        \end{scope}}%
      % Render rights
      \@ifundefined{natoapp@right}{}{%
        \begin{scope}[]
          \wg@pic@all{\natoapp@right}{natoapp6c/s/}{M.right}{%
            natoapp6c/modifiers,natoapp6c/right}%
        \end{scope}}%     
      % Modififiers end 
      \n@to@pp@modfalse%
      \endpgfinterruptboundingbox
    \end{scope}%
    \fi%
    \wg@ignore@sub@nchorfalse%
  }
%    \end{macrocode}
%
% That concludes rendering most of the symbol.  We have not put in the
% echelon, below element, or drawn the frame yet.  That we will do on
% the foreground path. 
% 
%    \begin{macrocode}
%    \end{macrocode}
%
% In the foreground `behind' path we render the echelon, below
% element, and draw the frame.
% 
%    \begin{macrocode}
  \behindforegroundpath{%
    \wg@ignore@sub@nchortrue%
    \n@to@pp@dbg{2}{NATO App6(c) foreground path: `\meaning\id'
      ^^J  Echelon: \meaning\natoapp@ech
      ^^J  Symbol:  \meaning\frameshape
      ^^J  Below:   \meaning\natoapp@below
      ^^J  Frame:   \meaning\frameopt}
    %
    %
%    \end{macrocode}
%
% We check if we have a frame.  If not, stop.
% 
%    \begin{macrocode}
    \ifx\frameshape\pgfutil@empty%
      \n@to@pp@dbg{2}{NATO App6(c) has no frame shape!}%
    \else%
%    \end{macrocode}
%
% We want to draw the rest of the symbol as a part of the frame, so we
% expand the \spec{frame} options in a scope. 
%
%    \begin{macrocode}
      \edef\tmp@opt{[\frameopt]}
      \expandafter\scope\tmp@opt
%    \end{macrocode}
%
% First thing in this scope is to draw the actual frame.  Again, this
% is done via a node with the right shape.  Note that we label this
% node as \spec{M}\meta{id} so we way refer to it later on. 
%
%    \begin{macrocode}
      \edef\mid{M\id{}}
      \n@to@pp@dbg{1}{NATO App6(c) inner node `M\id' ===}
      \pgfnode{natoapp6c \frameshape}{center}{}{M\id}{\pgfusepath{stroke}}
      \wg@ignore@sub@nchorfalse%
%    \end{macrocode}
%
% If the user gave an echelon, then put that in. Note that echelons
% are limited to predefined values. 
% 
%    \begin{macrocode}
    % Put in the echelon
      \n@to@pp@dbg{2}{Echelon}
      \@ifundefined{natoapp@ech}{}{%
        \ifx\natoapp@ech\pgfutil@empty\else%
          \def\args{echelon=\natoapp@ech}
          \n@to@pp@dbg{3}{Make the echelon}%
          \wg@nchor{\thisname}{echelon}%
          \expandafter\wg@pic\args\@endwg@pic%
          {natoapp6c/s/}{\pgf@x,\pgf@y}{natoapp6c/echelon}
        \fi%
      }
%    \end{macrocode}
%
% If the user want something under the frame, put that in. 
% 
%    \begin{macrocode}
      % Put in stuff below main 
      \n@to@pp@dbg{2}{Below}
      \@ifundefined{natoapp@below}{}{%
        \n@to@pp@belowtrue
        \begin{scope}
          \n@to@pp@dbg{3}{Make below}%
          \wg@nchor{\thisname}{below}%
          \wg@pic@all{\natoapp@below}{natoapp6c/s/}{\pgf@x,\pgf@y}{%
            natoapp6c/below}%
        \end{scope}%
        \n@to@pp@belowfalse}
%    \end{macrocode}
%
% If the \spec{decoy} flag was set, we draw that.
% 
%    \begin{macrocode}
      \n@to@pp@dbg{2}{Decoy}
      \ifnatoapp@decoy%
        \scope[dash pattern=on 3\pgflinewidth off 2\pgflinewidth]%
        \n@to@pp@dbg{1}{Drawing decoy modifier}%
        \wg@sub@nchor{M\id}{north east}
        \wg@tmpa=\pgf@x%
        \wg@tmpb=\pgf@y%
        \pgfpathmoveto{\pgfqpoint{\wg@tmpa}{\wg@tmpb}}%
        \wg@tmpc=\n@to@pp@e@yy cm%
        \advance\wg@tmpc\n@to@pp@e@yy cm%
        \advance\wg@tmpc\wg@tmpb%
        \pgfpathlineto{\pgfqpoint{0cm}{\wg@tmpc}}%
        \pgfpathlineto{\pgfqpoint{-\wg@tmpa}{\wg@tmpb}}%
        \pgfusepath{stroke}%
        \endscope%                           
      \fi%                         
      \endscope%
    \fi%
    \wg@ignore@sub@nchorfalse%
  }
}
%    \end{macrocode}
%
% That finished the shape for NATO App6(c) symbols.   We could stop
% here, but for convenience we define a wrapper macro. 
%
% \end{NatoAppFrame}
% 
% \iffalse
% --------------------------------------------------------------------
% \fi
% \subsubsection{The \cs{natoapp} wrapper macro}
% 
% \begin{Macro}{\natoapp}
%
%   This is a wrapper macro for inserting a node with a NATO App6(c)
%   symbol in it. The syntax of the macro is
%
%   \begin{Syntax}
%     \cs{natoapp}\oarg{natoapp6c options}\parg{position}\parg{identifier};
%   \end{Syntax}
%
% Note that the trailing semi-colon (\spec{;}) is optional. 
%
% This macro forwards to \cs{n@toapp}.
%
%    \begin{macrocode}
\newcommand\natoapp[1][]{%
  \n@to@pp@dbg{2}{NATO App6(c) macro -> `#1'}
  \tikzset{/natoapp6c/.cd,faction=friendly,command=land}%
  \@ifnextchar({\n@toapp{#1}}{\n@toapp{#1}(0,0)}%)
}
%    \end{macrocode}
% \end{Macro}
%
% \begin{Macro}{\n@toapp}
%
%   This macro takes care to parse the location argument --- if any.
%   It forwards to \cs{n@to@pp}.
%
%    \begin{macrocode}
\def\n@toapp#1(#2){%
  \n@to@pp@dbg{2}{NATO App6(c) second macro -> `#1', `#2'}
  \@ifnextchar({\n@to@pp{#1}{#2}}{\n@to@pp{#1}{#2}()}%)
}
%    \end{macrocode}
% \end{Macro}
%
% 
% \begin{Macro}{\n@to@pp}
%   This is the main work-horse of the wrapper.  It makes a node with
%   the shape \spec{natoapp6c} passing the relevant parameters.  The
%   syntax of the macro is
%
%    \begin{macrocode}
\def\n@to@pp#1#2(#3){%
  \node[draw,transform shape,natoapp6c={#1}] (#3) at (#2) {};%
  \@ifnextchar;{\@gobble}{}}
%    \end{macrocode}
% \end{Macro}
% 
% 
% \iffalse
% --------------------------------------------------------------------
% \fi
% \subsubsection{Kriegspiel-like symbols}
%
% Style that selects Kriegspiel-like symbols by setting the symbols
% picture path.
% 
%    \begin{macrocode}
\tikzset{
  kriegspiel symbol/.code={
    \pgfkeys{%
      /tikz/transform shape,%
      /tikz/shape=kriegspiel symbol}
    \n@to@pp@dbg{10}{Args for symbol `#1'}
    \pgfkeys{/natoapp6c/.cd,%
      path=kriegspiel/s/,%
      #1}
  }
}
%    \end{macrocode}
%
% Shape of Kriegspiel-like symbols (always the same).  This mainly
% inherits from the NATO shape.  This hard-codes the frame shape to be
% \texttt{kriegspiel} (shape \texttt{natoapp6c kriegspiel}).  
%
%    \begin{macrocode}
\pgfdeclareshape{kriegspiel symbol}{
  \inheritsavedanchors[from=natoapp6c]
  \savedmacro\frameshape{%
    \def\frameshape{kriegspiel}}
  \inheritanchor[from=natoapp6c]{center}
  \inheritanchor[from=natoapp6c]{north east}
  \inheritanchor[from=natoapp6c]{north west}
  \inheritanchor[from=natoapp6c]{south east}
  \inheritanchor[from=natoapp6c]{south west}
  \inheritanchor[from=natoapp6c]{north}
  \inheritanchor[from=natoapp6c]{west}
  \inheritanchor[from=natoapp6c]{south}
  \inheritanchor[from=natoapp6c]{east}
  \inheritanchor[from=natoapp6c]{upper}
  \inheritanchor[from=natoapp6c]{lower}
  \inheritanchor[from=natoapp6c]{left}
  \inheritanchor[from=natoapp6c]{right}
  \anchor{echelon}   {%
    \wg@sub@nchor{M\id}{north west}%
    \wg@tmpa=\n@to@pp@e@y cm%
    \divide\wg@tmpa by 2%
    \advance\pgf@y\wg@tmpa%
  }%
  \inheritbackgroundpath[from=natoapp6c]
  \inheritbehindforegroundpath[from=natoapp6c]
  \inheritbehindbackgroundpath[from=natoapp6c]
  \savedmacro\thisname{\def\thisname{kriegspiel symbol}}
}    
%    \end{macrocode}
%
% The shape of a Kriegspiel-like frame.  Always the same.  This never
% draws the background path.  
%
%    \begin{macrocode}
\pgfdeclareshape{natoapp6c kriegspiel}{
  \inheritsavedanchors[from=rectangle]
  \inheritbackgroundpath[from=rectangle]
  \savedanchor\northeast{\pgf@x=1.4cm\pgf@y=.3125cm}
  \savedanchor\southwest{\pgf@x=-1.4cm\pgf@y=-.3125cm}
  \inheritanchor[from=rectangle]{center}
  \inheritanchor[from=rectangle]{north east}
  \inheritanchor[from=rectangle]{north west}
  \inheritanchor[from=rectangle]{south east}
  \inheritanchor[from=rectangle]{south west}
  \inheritanchor[from=rectangle]{north}
  \inheritanchor[from=rectangle]{west}
  \inheritanchor[from=rectangle]{south}
  \inheritanchor[from=rectangle]{east}
  \backgroundpath{}
}
%    \end{macrocode}
%
% Now some symbols.  We do not define a whole lot, since we do not
% need that for Kriegspiel-like counters.
%
%    \begin{macrocode}
\tikzset{
  ks debug frame/.style={
    draw=none,
    %draw=magenta,
    %dashed,
  },
  kriegspiel/s/infantry/.pic={
    \coordinate(a) at (M.south west);
    \coordinate(b) at ($(M.north east)+(0,-.2)$);
    \@ifundefinedcolor{pgffillcolor}{}{
      \path[fill=pgffillcolor](a)rectangle(b);}
    \path[pic actions,fill=none](a)rectangle(b);
    \path[pic actions,fill=none](a)--(b);
    \path[pic actions,fill=none] let
    \p1=(a),\p2=(b) in (\x2,\y1)--(\x1,\y2);
    \path[fill=pgfstrokecolor] let
    \p2=(b) in (-.05,\y2)rectangle++(.1,.2);
    \draw[ks debug frame](M.south west)rectangle(M.north east);
  },
  kriegspiel/s/reconnaissance/.pic={
    \coordinate(a) at (M.south west);
    \coordinate(b) at ($(M.north east)+(0,-.2)$);
    \@ifundefinedcolor{pgffillcolor}{}{
      \path[fill=pgffillcolor](a)rectangle(b);}
    \path[pic actions,fill=none](a)rectangle(b);
    \path[fill=pgfstrokecolor] (a)--(b)--(a|-b)--cycle;
    \path[fill=pgfstrokecolor] let
    \p2=(b) in
    (-.05,\y2)--++(0,.2)--++(-10:.4)--++(-170:.3)--(.05,\y2)--cycle;
    \draw[ks debug frame](M.south west)rectangle(M.north east);
  },
  kriegspiel/s/artillery/.pic={
    \coordinate(a) at (M.south west);
    \coordinate(b) at ($(M.north east)+(0,-.5)$);
    \@ifundefinedcolor{pgffillcolor}{}{
      \path[fill=pgffillcolor](a)rectangle(b);}
    \path[pic actions,fill=none](a)rectangle(b);
    \foreach \s in {-.8,0,.8}{
      \path[fill=pgfstrokecolor] let
      \p2=(b),%
      \n1={\y2+\pgflinewidth} in
      (\s-.04,\y2)rectangle++( .08,.5)
      ($(\s-.18,\n1)+(0,.05)$)rectangle++( .08,.2)
      ($(\s+.18,\n1)+(0,.05)$)rectangle++(-.08,.2);
    }
    \draw[ks debug frame](M.south west)rectangle(M.north east);
  },
  kriegspiel/s/reconnaissance artillery/.pic={
    \coordinate(a) at (M.south west);
    \coordinate(b) at ($(M.north east)+(0,-.5)$);
    \@ifundefinedcolor{pgffillcolor}{}{
      \path[fill=pgffillcolor](a)rectangle(b);}
    \path[pic actions,fill=none](a)rectangle(b);
    \path[fill=pgfstrokecolor] (a)--(b)--(a|-b)--cycle;
    \foreach \s in {-.8,0,.8}{
      \path[fill=pgfstrokecolor] let
      \p2=(b),%
      \n1={\y2+\pgflinewidth} in
      (\s-.04,\y2)rectangle++( .08,.5)
      ($(\s-.18,\n1)+(0,.05)$)rectangle++( .08,.2)
      ($(\s+.18,\n1)+(0,.05)$)rectangle++(-.08,.2);
    }
    \draw[ks debug frame](M.south west)rectangle(M.north east);
  }
}

%    \end{macrocode}
% 
% \iffalse
% --------------------------------------------------------------------
% \fi
% \subsubsection{Macros for markings}
% 
% \begin{Macro}{\natoappmark}
%
%   A macro for making NATO App6(c) markings.
%   
%    \begin{macrocode}
\providecommand\natoappmark[2][]{%
  \tikz[transform shape,
  scale=.25,
  baseline=(natoapp6c mark.south east),
  natoapp6c mark/.try,
  #1]{%1
    \node[draw,transform
    shape,natoapp6c={faction=friendly,command=land,
      main=#2}] (natoapp6c mark){}}}
% \natoapp[faction=friendly,command=land,main=#2](0,0)(natoapp6c mark)}}
%    \end{macrocode}
% \end{Macro}
%
% \begin{Macro}{\echelonmark}
%    \begin{macrocode}
\providecommand\echelonmark[2][]{\tikz[transform shape,scale=.5,#1]{%
    \pic[scale line widths,line width=1pt] {natoapp6c/s/echelon=#2};}}
%    \end{macrocode}
% \end{Macro}
%
% Some specific NATO App6(c) markers.
%
%    \begin{macrocode}
\DeclareRobustCommand\armouredmark[1][]{\natoappmark[#1]{armoured}}
\DeclareRobustCommand\infantrymark[1][]{\natoappmark[#1]{infantry}}
\DeclareRobustCommand\artillerymark[1][]{%
  \natoappmark[#1]{{[fill=pgfstrokecolor]artillery}}}
\DeclareRobustCommand\combinedmark[1][]{\natoappmark[#1]{combined arms}}
\DeclareRobustCommand\pgmark[1][]      {\natoappmark[#1]{{armoured,infantry}}}
\DeclareRobustCommand\reconnaissancemark[1][]{\natoappmark[#1]{reconnaissance}}
\DeclareRobustCommand\corpsmark[1][]{\natoappmark[#1]{,echelon=corps}}
\DeclareRobustCommand\divisionmark[1][]{\natoappmark[#1]{,echelon=division}}
\DeclareRobustCommand\brigademark[1][] {\natoappmark[#1]{,echelon=brigade}}
\DeclareRobustCommand\regimentmark[1][]{\natoappmark[#1]{,echelon=regiment}}
\DeclareRobustCommand\sofmark[1][]     {\natoappmark[#1]{{infantry,text=SOF}}}
\DeclareRobustCommand\mountaineermark[1][]{%
  \natoappmark[#1]{infantry,lower=mountain}}
\DeclareRobustCommand\airbornemark[1][]{%
  \natoappmark[#1]{infantry,lower=airborne}}
\DeclareRobustCommand\amphibiousmark[1][]{\natoappmark[#1]{,lower=amphibious}}
\DeclareRobustCommand\airassaultmark[1][]{%
  \natoappmark[#1]{infantry,upper=air assault}}
%    \end{macrocode}
% \iffalse
% </natoapp6c>
% --------------------------------------------------------------------
% \fi
