%%
%% This is file `tikzlibrarywargame.util.code.tex',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% util/core.dtx  (with options: `utils')
%% util/misc.dtx  (with options: `utils')
%% util/compound.dtx  (with options: `utils')
%% util/bb.dtx  (with options: `utils')
%% util/tikz.dtx  (with options: `utils')
%% util/randomid.dtx  (with options: `utils')
%% util/icons.dtx  (with options: `utils')
%% 
%% 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.
%% 

\tikzset{
  wargame logo text/.style={
    font=\sffamily\bfseries\fontsize{12}{14}\selectfont,
    scale=2.8,
    inner sep=0,
    text width=1.8cm,
    transform shape,
    align=center},
  wargame logo text content/.store in=\wg@logo@text@content,
  wargame logo text content={{\huge\LaTeX} wargame},
  wargame logo chit/.style={
    chit={symbol={[
        faction=friendly,
        command=land,
        echelon=division,
        main=infantry]},
      factors={chit/2 factors={4,3}},
      left={chit/identifier=III},
      right={chit/small identifier={10\textsuperscript{th}}},
      color=white,
      fill=red!50!black
    }
  },
  wargame logo/.style={
    transform shape,
    every hex/.style={fill=gray!5!white,draw=gray!75!black},
    hex/first row is=0,
    hex/first column is=0,
    hex/short top columns=none,
    hex/short bottom columns=none,
    hex/row direction is=normal,
    hex/column direction is=normal
  }
}
\newcommand\wargamelogo[1][]{%
  \begin{scope}[wargame logo,#1]
    \node[hex={fill=gray!30!white}] (logo center)      at (hex cs:c=0,r=0) {};
    \node[hex={terrain=light woods}](logo light woods) at (hex cs:c=0,r=1) {};
    \node[hex={terrain=city}]       (logo city)        at (hex cs:c=0,r=-1){};
    \node[hex={terrain=woods}]      (logo woods)       at (hex cs:c=-1,r=0){};
    \node[hex={terrain=mountains}]  (logo mountains)   at (hex cs:c=-1,r=1){};
    \node[hex={terrain=beach}]      (logo beach)       at (hex cs:c=1,r=1) {};
    \node[hex={terrain=swamp}]      (logo swamp)       at (hex cs:c=1,r=0) {};
    \node[wargame logo chit]        (logo chit)        at (hex cs:)        {};
    \node[wargame logo text]        (logo text) {\wg@logo@text@content};
  \end{scope}}
\newcount\wargamedbglvl\wargamedbglvl=0
\def\wg@dbg#1#2{%
  \ifnum#1>\wargamedbglvl\relax\else\message{^^J#2}\fi}
\long\def\wg@addto@macro#1#2{%
  \begingroup
  \toks@\expandafter\expandafter\expandafter{\expandafter#1#2}%
  \xdef#1{\the\toks@}%
  \endgroup}
\def\wg@sub@nchor#1#2{%
  \wg@dbg{3}{^^JGet `#2' in `#1'}%
  \@ifundefined{pgf@sh@ns@#1}{%
    \pgf@x=0cm\pgf@y=0cm}{%
    \pgf@process{%
      \csname pgf@sh@ma@#1\endcsname% MW
      \csname pgf@sh@np@#1\endcsname%
      \pgf@sh@reanchor{\csname pgf@sh@ns@#1\endcsname}{#2}}}%
  \wg@dbg{10}{-> \the\pgf@x,\the\pgf@y}%
}
\newdimen\wg@tmpa
\newdimen\wg@tmpb
\newdimen\wg@tmpc
\newdimen\wg@tmpd
\def\settosave#1{
  \pgfsyssoftpath@setcurrentpath{#1}}
\def\wg@pic{%
  \@ifnextchar[{\wg@@pic}{\wg@@pic[]}%]
}
\def\wg@@pic[#1]#2\@endwg@pic{%
  \wg@dbg{2}{Options: `#1', picture: `#2'}%
  \wg@@@pic{#1}{#2}%
}
\def\wg@@@pic#1#2#3#4#5{%
  \ifx|#2|\wg@dbg{3}{No picture given}%
  \else%
    \wg@dbg{3}{^^JWG Pic:
      ^^J  User options:  #1
      ^^J  Picture:       #2
      ^^J  Prefix:        #3
      ^^J  Coordinates:   #4
      ^^J  Fixed options: #5}%
    % \wg@dbg{2}{\string\pic[#5,#1] at (#4) {#3#2}}%
    \pic[#5,#1] at (#4) {#3#2};%
    \ifwg@s@ve%
      \pgf@relevantforpicturesizetrue%
      \begin{getbbl}%
        \pic[draw=none,fill=none,transform shape] at (#4) {#3#2};%
      \end{getbbl}%
      \wg@dbg{5}{Clipping to local bounding box}%
      \clip (L.south west) rectangle (L.north east);%
      \pgf@relevantforpicturesizefalse \global\wg@s@vefalse%
    \fi
  \fi%
  \wg@dbg{3}{End of WG Pic}
}
\def\wg@pic@all#1#2#3#4{%
  \wg@dbg{2}{WG picture loop
    ^^J  List:    \meaning#1
    ^^J  Prefix:  `#2'
    ^^J  Position: `#3'
    ^^J  Styles:   `#4'}
  \foreach \p in #1{%
    \wg@dbg{2}{WG picture element: \meaning\p}%
    \expandafter\wg@pic\p\@endwg@pic {#2}{#3}{#4}%
  }%
}
\def\wg@node{%
  \@ifnextchar[{\wg@@node}{\wg@@node[]}%]
}
\def\wg@@node[#1]#2\@endwg@node{%
  \wg@dbg{2}{Options: `#1', body: `#2'}%
  \wg@@@node{#1}{#2}%
}
\def\wg@@@node#1#2#3#4#5{%
  \ifx|#2|\wg@dbg{3}{No body given}%
  \else%
    \wg@dbg{3}{^^JWG Pic:
      ^^J  User options:  #1
      ^^J  Body:          #2
      ^^J  Prefix:        #3
      ^^J  Coordinates:   #4
      ^^J  Fixed options: #5}%
    % \wg@dbg{2}{\string\pic[#5,#1] at (#4) {#3#2}}%
    \node[#5,#1] at (#4) {#3#2};%
  \fi%
  \wg@dbg{3}{End of WG Node}
}
\def\wg@node@all#1#2#3#4{%
  \wg@dbg{2}{WG picture loop
    ^^J  List:    \meaning#1
    ^^J  Prefix:  `#2'
    ^^J  Position: `#3'
    ^^J  Styles:   `#4'}
  \foreach \p in #1{%
    \wg@dbg{2}{WG picture element: \meaning\p}%
    \expandafter\wg@node\p\@endwg@node {#2}{#3}{#4}%
  }%
}
\newdimen\wg@bb@minx
\newdimen\wg@bb@miny
\newdimen\wg@bb@maxx
\newdimen\wg@bb@maxy
\newif\ifwg@notrelevantforpathsize\wg@notrelevantforpathsizefalse
\def\wg@resetbb{%
  \global\wg@bb@minx=16000pt\relax%
  \global\wg@bb@miny=16000pt\relax%
  \global\wg@bb@maxx=-16000pt\relax%
  \global\wg@bb@maxy=-16000pt\relax%
}
\let\old@pgf@protocolsize\pgf@protocolsizes
\def\wg@protocolsizes#1#2{%
  \old@pgf@protocolsize{#1}{#2}
  \ifwg@notrelevantforpathsize\else%
  \ifdim#1<\wg@bb@minx\global\wg@bb@minx#1\fi%
  \ifdim#1>\wg@bb@maxx\global\wg@bb@maxx#1\fi%
  \ifdim#2<\wg@bb@miny\global\wg@bb@miny#2\fi%
  \ifdim#2>\wg@bb@maxy\global\wg@bb@maxy#2\fi%
  \fi
}
\newenvironment{getbbl}{%
  \wg@resetbb%
  \wg@notrelevantforpathsizefalse%
  \global\let\pgf@protocolsizes\wg@protocolsizes}{%
  \gdef\pgf@sh@ns@L{rectangle}
  \gdef\pgf@sh@np@L{%
    \def\southwest{\pgfqpoint{\the\wg@bb@minx}{\the\wg@bb@miny}}%
    \def\northeast{\pgfqpoint{\the\wg@bb@maxx}{\the\wg@bb@maxy}}%
  }
  \gdef\pgf@sh@nt@L{{1}{0}{0}{1}{0pt}{0pt}}
  \gdef\pgf@sh@pi@L{\pgfpictureid}
  \global\let\pgf@protocolsizes\old@pgf@protocolsize
}
\newenvironment{getbb}{%
  \wg@resetbb%
  \wg@notrelevantforpathsizefalse%
  \global\let\pgf@protocolsizes\wg@protocolsizes}{%
  \gdef\pgf@sh@ns@M{rectangle}
  \gdef\pgf@sh@np@M{%
    \def\southwest{\pgfqpoint{\the\wg@bb@minx}{\the\wg@bb@miny}}%
    \def\northeast{\pgfqpoint{\the\wg@bb@maxx}{\the\wg@bb@maxy}}%
  }
  \gdef\pgf@sh@nt@M{{1}{0}{0}{1}{0pt}{0pt}}
  % \pgfgettransform\pgf@temp%
  % \xdef\pgf@sh@nt@M{\pgf@temp}
  % \pgfgettransformentries{\wg@tmp@a}{\wg@tmp@b}{\wg@tmp@c}{\wg@tmp@d}{\pgf@temp}{\pgf@temp}
  % \message{^^JTransform of M: \meaning\pgf@temp}
  % \xdef\pgf@sh@nt@M{{\wg@tmp@a}{\wg@tmp@b}{\wg@tmp@c}{\wg@tmp@d}{0pt}{0pt}}%
  % \message{^^JTransform of M: \meaning\pgf@sh@nt@M}
  \gdef\pgf@sh@pi@M{\pgfpictureid}
  \global\let\pgf@protocolsizes\old@pgf@protocolsize
}
\def\wg@pt@to@cm#1{\pgfmathparse{#1 * 0.0351367}}
\def\ptpoint@to@cm#1#2{%
  \wg@pt@to@cm{#1}\edef\x{\pgfmathresult}%
  \wg@pt@to@cm{#2}\edef\y{\pgfmathresult}}
\def\wg@get@nchor#1#2{%
  \wg@dbg{2}{Get anchor coordinates #1.#2}
  \pgfpointanchor{#1}{#2}%
  \wg@dbg{2}{ `\the\pgf@x',`\the\pgf@y'}
  \pgfgetlastxy\tmp@x\tmp@y%
  \wg@dbg{2}{ `\tmp@x',`\tmp@y'}
  \wg@pt@to@cm{\tmp@x}\edef\tmp@x{\pgfmathresult}
  \wg@pt@to@cm{\tmp@y}\edef\tmp@y{\pgfmathresult}
}
\def\wg@get@global@nchor#1#2{%
  \pgfpointanchor{#1}{#2}%
  \pgfgetlastxy\tmp@x\tmp@y%
  \pgfpointtransformed{\pgfpoint{\tmp@x}{\tmp@y}}
  \pgf@xa=\pgf@x
  \pgf@ya=\pgf@y
  %% \message{^^JAnchor #1.#2 @ (\the\pgf@xa,\the\pgf@ya)}
  \wg@pt@to@cm{\the\pgf@xa}\edef\tmp@x{\pgfmathresult}
  \wg@pt@to@cm{\the\pgf@ya}\edef\tmp@y{\pgfmathresult}
}
\def\wg@get@bb#1{%
  \wg@get@nchor{#1}{south west}
  \edef\llx{\tmp@x}
  \edef\lly{\tmp@y}
  \wg@get@nchor{#1}{north east}
  \edef\urx{\tmp@x}
  \edef\ury{\tmp@y}
}
\def\wglogbb#1{%
  \wg@get@bb{#1}%
  \message{^^J`#1' BB: (\llx,\lly) x (\urx,\ury)^^J}}
\tikzstyle{reverseclip}=[insert path={(current bounding box.north east) --
  (current bounding box.south east) --
  (current bounding box.south west) --
  (current bounding box.north west) --
  (current bounding box.north east)}]
\tikzset{
  clip even odd rule/.code={\pgfseteorule}, % Credit to Andrew Stacey
}
\tikzset{
  invclip/.style={
    clip,insert path=
    [clip even odd rule]{
      [reset cm](-\maxdimen,-\maxdimen)rectangle(\maxdimen,\maxdimen)
    }
  },
}
\newif\ifwg@s@ve\wg@s@vefalse
\tikzset{
  save clip/.is choice,
  save clip/true/.code={\global\wg@s@vetrue},
  save clip/false/.code={\global\wg@s@vefalse},
  save clip/.default={true},
  save clip/.initial={false},
}
\def\wg@setcornersarched#1{%
  \ifx|#1|\else%
  \edef\pgf@corner@arc{{#1}{#1}}%
  \pgf@arccornerstrue%
  \ifdim#1=0pt%
    \pgf@arccornersfalse%
    \fi\fi}
\newdimen\wg@lw@scaled\wg@lw@scaled=1pt
\def\wg@getscale{%
  \pgfgettransformentries{%
    \wg@jaca}{%
    \wg@jacb}{%
    \wg@jacc}{%
    \wg@jacd}{%
    \wg@tmp}{%
    \wg@tmp}%
  \pgfmathsetmacro{\wg@jac}{sqrt(abs(\wg@jaca*\wg@jacd-\wg@jacb*\wg@jacc))}%
  \wg@dbg{4}{Scale is \wg@jac}
  \xdef\wg@scale{\wg@jac}}
\def\wg@scaled#1{%
  \wg@getscale%
  \wg@dbg{4}{Scaling #1 by \wg@scale}
  \pgfmathsetmacro{\wg@tmp}{\wg@scale*#1}%
  \xdef\wg@tmp{\wg@tmp}%
  \xdef\wg@lw@scale{\wg@tmp}%
  \wg@dbg{4}{Scaled #1 -> \wg@tmp}}
%% \message{^^JRounded corners: \meaning\pgfsetcornersarced}
\tikzset{
  %% Get current scale and store in \wg@scale
  get scale/.code={\wg@getscale},
  scale line widths/.style={%
    /utils/exec=\def\tikz@semiaddlinewidth##1{%
      \wg@scaled{##1}
      \wg@lw@scaled=\wg@tmp pt
      \tikz@addoption{\pgfsetlinewidth{\wg@lw@scaled}}%
      \wg@dbg{4}{Added scaled option \wg@tmp}
      \pgfmathsetlength\pgflinewidth{\wg@tmp pt}
      \wg@dbg{4}{Did set line width \wg@tmp pt}
    }
  },
  scale rounded corners/.style={%
    /utils/exec=\def\pgfsetcornersarced##1{%
      \pgf@process{##1}%
      \pgf@xa=\pgf@x%
      \wg@scaled{\the\pgf@xa}%
      % \tikz@addoption{\wg@setcornersarched{\wg@tmp pt}}%
      \wg@dbg{4}{Scaled rounded corners: \the\pgf@xa -> \wg@tmp}%
      \wg@setcornersarched{\wg@tmp pt}%
    }
  },
  relative line width/.style={%
    /utils/exec=\def\tikz@semiaddlinewidth##1{%
      \wg@dbg{4}{Relative line width #1 times ##1}%
      \pgfmathsetmacro{\wg@lv}{#1*##1}%
      \tikz@addoption{\pgfsetlinewidth{\wg@lw pt}}%
      \pgfmathsetlength\pgflinewidth{\wg@lw pt}}}
}
\tikzset{
  sub pic actions/.code={%
    \tikz@picmode%
    \edef\opts{%
      \iftikz@mode@draw draw,\else draw=none,\fi
      \iftikz@mode@fill fill\else fill=none\fi}
    \wg@dbg{5}{^^JSub Mode: \meaning\tikz@picmode  \meaning\opts}
    \pgfset{/tikz/.cd}
    \pgfkeysalsofrom{\opts}
  }}
\tikzset{
  wg/debug show/.code={%
    \extractcolorspec{pgfstrokecolor}{\wg@tmp@fg}
    \def\wg@tmp@bg{none}
    \@ifundefinedcolor{pgffillcolor}{}{
      \extractcolorspec{pgffillcolor}{\wg@tmp@bg}}
    \begingroup
    \tikz@mode
    \wargamedbglvl=#1
    \wg@dbg{3}{Drawing with w/stroke `\wg@tmp@fg'
      (\tikz@strokecolor,\iftikz@mode@draw\else not\space\fi drawing)
      and fill `\wg@tmp@bg' (\tikz@fillcolor,\iftikz@mode@fill\else
      not\space\fi  filling)}
    \endgroup
  }
}
\def\wg@r@ndom@id{%
  \def\wg@uuid{}
  \foreach \i in {1,...,8}{%
    \pgfmathparse{Hex(random(0,15))}
    \xdef\wg@uuid{\wg@uuid\pgfmathresult}}}
\tikzset{
  trash can line/.style={scale line widths,scale rounded corners,
    line width=.5mm,->},
}
\tikzset{
  trash can body/.pic={%
    \path[fill=black,scale line widths,scale rounded corners,
    rounded corners=.05cm]
    (-.3,.2) --++(.6,0) --++(-.1,-.7) --++(-.4,0) --cycle;
    \path[fill=white]
    (-.025,-.4) arc(180:360:.025) --++(   0,.5) arc(0:180:.025)   --cycle;
    \path[fill=white]
    (-.125,-.4) arc(180:360:.025) --++(-.07,.5) arc(0:180:.025) --cycle;
    \path[fill=white]
    ( .075,-.4) arc(180:360:.025) --++( .07,.5) arc(0:180:.025) --cycle;
  },
  trash can lid/.pic={%
    \path[fill=black,scale line widths,scale rounded corners,
    rounded corners=.05cm]
    (-.35,.23)--++(.7,0)--++(-.07,.07)--++(-.56,0)--cycle;
    \path[fill=black]
    (-.15,.3) --++(.05,0) --++(0,.05) --++(.2,0) --++(0,-.05)
    --++(.05,0) --++(0,.05) arc(0:90:.05) --++(-.2,0) arc(90:180:.05)
    --cycle;
  },
}
\tikzset{
  trash can/.pic={
    \pic{trash can body};
    \pic{trash can lid};
  },
  trash can open/.pic={
    \pic{trash can body};
    \pic[rotate=-30] at (0,.1) {trash can lid};
  },
}
\tikzset{
  eliminate icon/.pic={
    \pic{trash can open};
    \draw[trash can line,color=red!50!black]
    (-.5,.2) to[looseness=1.5] (-.1,.23);
  },
  restore icon/.pic={
    \pic{trash can open};
    \draw[trash can line,<-,color=green!50!black]
    (-.5,.2) to[looseness=1.5] (-.1,.23);
  },
  pool icon/.pic={
    \pic{trash can};
  },
}
\tikzset{
  flip icon/.pic={
    \draw[scale line widths,scale rounded corners,
    line width=1mm,->,color=blue!50!black]
    (-.5,-.5) arc(180:0:.5);% (.5,-.5);
  },
  pics/oob icon/.style n args={2}{code={%
      \begin{scope}[box/.style args={##1,##2,##3,##4}{
          minimum width=##1cm,
          minimum height=##2cm,
          fill=##3,
          anchor=##4,
          draw=gray!50!black,
          scale line widths,
          line width=.5pt,
          transform shape},
        under/.style={
          below=.05cm of ##1}
        ]
        \node[box={.5,.2,#1,north west,fill=#1}] (r1) at (.05,.45) {};
        \node[under=r1.south west,box={.3,.25,#1,north west}] (r2) {};
        \node[under=r2.south west,box={.2,.3, #1,north west}] (r3) {};
        \node[box={.2,.4,#2,north east}] (l1) at (-.05,.45) {};
      \end{scope}
    }
  }
}
%% Local Variables:
%%   mode: LaTeX
%% End:
%%
%% End of file `tikzlibrarywargame.util.code.tex'.
