diff options
Diffstat (limited to 'macros/latex/contrib/wargame/source/hex')
19 files changed, 1080 insertions, 222 deletions
diff --git a/macros/latex/contrib/wargame/source/hex/board.dtx b/macros/latex/contrib/wargame/source/hex/board.dtx index fd0af295fb..7c791a72b3 100644 --- a/macros/latex/contrib/wargame/source/hex/board.dtx +++ b/macros/latex/contrib/wargame/source/hex/board.dtx @@ -18,82 +18,261 @@ % % % \begin{macrocode} -\tikzset{ - hex/board frame/.style={draw} -} \def\boardframe{% - \@ifnextchar[{\bo@rdframe}{\bo@rdframe[0]}%} + \@ifnextchar[{\bo@rdframe}{\bo@rdframe[0]}%] +} +% \end{macrocode} +% +% Below is our new implementation of \cs{boardframe}. This is split +% into parts. +% +% +% First, a macro that will define the path around rectangular placed +% hexes. This takes 4 mandatory arguments: lower left column and row, +% and upper right column and row, in that order. It also accepts an +% optional argument. If this is not empty, then it is assumed to be a +% style to apply, and hexes will be drawn using that style. The style +% will be passed the hex coordinates and can react accordingly. +% +% \begin{macrocode} +\def\bo@rdfr@me{ + \@ifnextchar[{\bo@rdfr@me@}{\bo@rdfr@me@[]}%] +} +\def\bo@rdfr@me@u(#1)#2#3#4#5{ + \hex@coords@conv{#1} + % \hex@dbg{0}{#1 -> `\hex@x',`\hex@y'} + \pgfmathparse{min(#2,\hex@x)}\xdef#2{\pgfmathresult} + \pgfmathparse{min(#3,\hex@y)}\xdef#3{\pgfmathresult} + \pgfmathparse{max(#4,\hex@x)}\xdef#4{\pgfmathresult} + \pgfmathparse{max(#5,\hex@y)}\xdef#5{\pgfmathresult} + \hex@dbg{2}{#1 -> ll=`#2',`#3', ur=`#4',`#5'} +} +\def\bo@rdfr@me@[#1]#2#3#4#5{ + % Define rtmp and a ctmp to by directions + \pgfmathparse{int(\hex@coords@row@fac)}\edef\rtmp{\pgfmathresult} + \pgfmathparse{int(\hex@coords@col@fac)}\edef\ctmp{\pgfmathresult} + % Define vertices for path + \def\ctfv{SW} + \def\ctsv{SE} + \def\cbfv{NE} + \def\cbsv{NW} + \def\rrfv{E} + \def\rrsv{NE} + \def\rlfv{W} + \def\rlsv{SW} + % Swap around some definitions based on the row direction + \ifnum\rtmp<0 + \let\max@short\hex@bot@short@col + \let\min@short\hex@top@short@col + \let\swp\ctfv\let\ctfv\cbsv\let\cbsv\swp + \let\swp\ctsv\let\ctsv\cbfv\let\cbfv\swp + \def\rrsv{SE} + \def\rlsv{NW} + \else + \let\max@short\hex@top@short@col + \let\min@short\hex@bot@short@col + \fi + % Swap around some definitions based on the column direction + \ifnum\ctmp<0 + \let\swp\ctfv\let\ctfv\ctsv\let\ctsv\swp + \let\swp\cbfv\let\cbfv\cbsv\let\cbsv\swp + \let\swp\rrfv\let\rrfv\rlsv\let\rlsv\swp + \let\swp\rrsv\let\rrsv\rlfv\let\rlfv\swp + \fi + % Define tmp = 0 if no shorts, 1 if top short, 2 if both + \pgfmathparse{ifthenelse(\hex@got@top@short, + ifthenelse(\hex@got@bot@short,2,1),0)}\edef\tmp{\pgfmathresult} + % If top-short, set factors + \ifnum\tmp=1 + \def\mnf{-1} + \def\mxf{-1} + \def\mnn{} + \def\mxn{} + % If both short, set factors + \else\ifnum\tmp=2 + \def\mnf{\rtmp} + \def\mxf{(-\rtmp)} + % If inverse rows, set factors + \ifnum\rtmp<0 + \def\mnn{} + \def\mxn{not} + \else + \def\mnn{not} + \def\mxn{} + \fi + % If none is short + \else + \def\mnf{1} + \def\mxf{1} + \def\mnn{not} + \def\mxn{not} + \fi\fi + % Define row@mn to give least row of column + \def\row@mn##1{% + \pgfmathparse{int(#3+\mnf* + \hex@coords@row@fac*\min@short(##1)* + \mnn(\min@short(\hex@coords@col@off)))} + \edef\lr{\pgfmathresult}} + % Define row@mx to give largest row of column + \def\row@mx##1{% + \pgfmathparse{int(#5+\mxf* + \hex@coords@row@fac*\max@short(##1)* + \mxn(\max@short(\hex@coords@col@off)))} + \edef\ur{\pgfmathresult}} + % + % + % Below defines a path around the perimeter of the hexes. + % + \def\@llx{10000} + \def\@lly{10000} + \def\@urx{-10000} + \def\@ury{-10000} + % Start with an empty path + \def\p{} + % Loop across least row (can be top if \rtmp<0) + \foreach \c in {#2,...,#4}{% + \row@mn{\c} + \row@mx{\c} + % \message{^^JColumn: `\c' -> `\lr',`\ur' (#3,#5)} + } + \foreach \c in {#2,...,#4}{% + \row@mn{\c} + \xdef\p{\p + (hex cs:c=\c,r=\lr,v=\ctfv)-- + (hex cs:c=\c,r=\lr,v=\ctsv)--} + \bo@rdfr@me@u(c=\c,r=\lr,v=\ctfv)\@llx\@lly\@urx\@ury + \bo@rdfr@me@u(c=\c,r=\lr,v=\ctsv)\@llx\@lly\@urx\@ury + } + % Go up (down if \rtmp<0) right side + \row@mn{#4} + \row@mx{#4} + \foreach \r in {\lr,...,\ur}{% + \xdef\p{\p + (hex cs:c=#4,r=\r,v=\rrfv)-- + (hex cs:c=#4,r=\r,v=\rrsv)--} + \bo@rdfr@me@u(c=#4,r=\r,v=\rrfv)\@llx\@lly\@urx\@ury + \bo@rdfr@me@u(c=#4,r=\r,v=\rrsv)\@llx\@lly\@urx\@ury + } + % Go across largest row (can be bottom if \rtmp<0) + \foreach \c in {#4,...,#2}{% + \row@mx{\c} + % \message{^^JColumn: `\c', max:`\ur'} + \xdef\p{\p + (hex cs:c=\c,r=\ur,v=\cbfv)-- + (hex cs:c=\c,r=\ur,v=\cbsv)--} + \bo@rdfr@me@u(c=\c,r=\ur,v=\cbfv)\@llx\@lly\@urx\@ury + \bo@rdfr@me@u(c=\c,r=\ur,v=\cbsv)\@llx\@lly\@urx\@ury + } + % Go up (down if \rtmp<0) left side. + \row@mn{#2} + \row@mx{#2} + \foreach \r in {\ur,...,\lr}{% + \xdef\p{\p + (hex cs:c=#2,r=\r,v=\rlfv)-- + (hex cs:c=#2,r=\r,v=\rlsv)--} + \bo@rdfr@me@u(c=#2,r=\r,v=\rlfv)\@llx\@lly\@urx\@ury + \bo@rdfr@me@u(c=#2,r=\r,v=\rlsv)\@llx\@lly\@urx\@ury + } + % End path with cycle + \edef\p{\p cycle} + % Define global path + \global\let\hex@board@path\p + \hex@dbg{3}{Hex board path: `\meaning\hex@board@path'} + % If an optional argument was given, then use that to actually make + % hexes. + \ifx|#1|\else + \foreach[count=\nc] \c in {#2,...,#4}{% + \row@mn{\c} + \row@mx{\c} + \foreach \r in {\lr,...,\ur}{% + \hex[#1={\c,\r}](c=\c,r=\r) + } + } + \fi +} +% \end{macrocode} +% +% +% This is a no operations style used as default for the macro +% \cs{boardhexes} below. +% +% \begin{macrocode} +\tikzset{% + /hex/board/no op/.style args={#1,#2}{}} +% \end{macrocode} +% +% This macro will make the actual hexes using the specified, optional, +% style. It builds on \cs{bo@rdfr@me} above. +% +% \begin{macrocode} +\def\boardhexes{% + \@ifnextchar[{\bo@rdhexes}{\bo@rdhexes[board/no op]}%] } +\def\bo@rdhexes[#1](#2)(#3){% + \hex@coords@conv{#2} + \edef\llc{\hex@col} + \edef\llr{\hex@row} + \hex@coords@conv{#3} + \edef\urc{\hex@col} + \edef\urr{\hex@row} + \bo@rdfr@me[#1]{\llc}{\llr}{\urc}{\urr}} +% \end{macrocode} +% +% Creates a board frame using \cs{bo@rdfr@me}. +% +% \begin{macrocode} +\tikzset{board frame bb/.code={ + \pgfkeys{ + %/tikz/local bounding box=tmp board frame, + /tikz/transform shape, + /tikz/execute at end scope={% + % \hex@dbg{1}{Getting board frame BB} + %\wg@get@bb{tmp board frame} + \global\let\llx\@llx + \global\let\lly\@lly + \global\let\urx\@urx + \global\let\ury\@ury + % \hex@dbg{0}{Board bounding box (\llx,\lly)x(\urx,\ury)} + }}}} + \def\bo@rdframe[#1](#2)(#3){% \hex@coords@conv{#2} - \edef\llx{\hex@x} - \edef\lly{\hex@y} \edef\llc{\hex@col} \edef\llr{\hex@row} - \edef\ellc{\hex@eff@col} - \edef\ellr{\hex@eff@row} % \hex@coords@conv{#3} - \edef\urx{\hex@x} - \edef\ury{\hex@y} \edef\urc{\hex@col} \edef\urr{\hex@row} - \edef\eurc{\hex@eff@col} - \edef\eurr{\hex@eff@row} % \def\margin{#1} % - \hex@dbg{2}{% - Board Hex range: (\llc,\llr)x(\urc,\urr) - ^^JEffective range: (\ellc,\ellr)x(\eurc,\eurr) - ^^JBB: (\llx,\lly)x(\urx,\ury)}% - \ifnum\hexdbglvl>1 - %\draw[red,very thick](hex cs:c=\llc,r=\llr) rectangle(hex cs:c=\urc,r=\urr); - \draw[red,ultra thick,dashed](\llx,\lly) rectangle(\urx,\ury); - \draw[->,very thick,blue] (0,0) -- (0,1) (0,0) -- (1,0); - \fi - % Calculate how many half hex hides to add to the "bottom" + % This will store the bounding box in tmp node `board frame' + \bo@rdfr@me{\llc}{\llr}{\urc}{\urr}% + \begin{scope}[board frame bb] + \expandafter\path\hex@board@path; + \end{scope} + \hex@dbg{1}{Board frame LL: -> `\llx',`\lly'} + \pgfmathparse{\llx+ifthenelse(\llx<0,-1,1)*\margin}\edef\llx{\pgfmathresult} + \pgfmathparse{\lly+ifthenelse(\lly<0,-1,1)*\margin}\edef\lly{\pgfmathresult} % - \def\oddeven{isodd} - \ifnum\hex@coords@row@fac<0\def\oddeven{iseven}\fi% - \pgfmathparse{ - ifthenelse(\hex@got@bot@short(\ellc), - ifthenelse(\hex@bot@short@col(\llc)*not(\oddeven(\ellc)),2, - ifthenelse(\hex@bot@short@col(\llc),0,1)), - ifthenelse(\oddeven(\ellc),1,2))} - \edef\olly{\pgfmathresult}% - \hex@dbg{2}{Delta lly: \olly half heights} - % Calculate how many half hex heights to add to the "top" - \def\oddeven{iseven} - \ifnum\hex@coords@row@fac<0\def\oddeven{isodd}\fi% + \hex@dbg{1}{Board frame UR: -> `\urx',`\ury'} + \pgfmathparse{\urx+ifthenelse(\urx<0,-1,1)*\margin}\edef\urx{\pgfmathresult} + \pgfmathparse{\ury+ifthenelse(\ury<0,-1,1)*\margin}\edef\ury{\pgfmathresult} % - \pgfmathparse{ - ifthenelse(\hex@got@top@short(\urc), - ifthenelse(\hex@top@short@col(\urc)*\oddeven(\eurc),0, - ifthenelse(\hex@top@short@col(\urc),2,1)), - ifthenelse(\oddeven(\eurc),1,2))} - \edef\oury{\pgfmathresult}% - \hex@dbg{2}{Delta ury: \oury half heights} - % Calculate new LLY and URY - \pgfmathparse{\lly-\hex@coords@row@fac*(\olly*\hex@yy+\margin)} - \edef\lly{\pgfmathresult} - \pgfmathparse{\ury+\hex@coords@row@fac*(\oury*\hex@yy+\margin)} - \edef\ury{\pgfmathresult} - % Calculate new LLX and URX - \pgfmathparse{\llx-1-\margin}\edef\llx{\pgfmathresult} - \pgfmathparse{\urx+1+\margin}\edef\urx{\pgfmathresult} - % Calculate width and height \pgfmathparse{\urx-\llx}\edef\w{\pgfmathresult} \pgfmathparse{\ury-\lly}\edef\h{\pgfmathresult} + %% Print to the log \hex@dbg{0}{Board Frame: (\llx,\lly)x(\urx,\ury) (\w x\h) (\llc,\llr)x(\urc,\urr)} + %% Possibly draw \draw[hex/board frame/.try](\llx,\lly) rectangle(\urx,\ury); + %% Store macros \xdef\boardXmin{\llx}% \xdef\boardYmin{\lly}% \xdef\boardXmax{\urx}% \xdef\boardYmax{\ury}% -} - +} % \end{macrocode} +% % \end{Macro} % % \begin{Macro}{\boardclip} @@ -104,108 +283,28 @@ % \cs{boardclip}\marg{nx}\marg{ny}\marg{preaction} % \end{Syntax} % \begin{macrocode} -\def\boardpath(#1)(#2){% +\def\boardpath(#1)(#2){ \hex@coords@reset% \tikzset{/hex/coords/.cd, #1} - \edef\llx{\hex@col} - \edef\lly{\hex@row} + \edef\llc{\hex@col} + \edef\llr{\hex@row} %% \hex@coords@reset% \tikzset{/hex/coords/.cd, #2} - \edef\urx{\hex@col} - \edef\ury{\hex@row} - \let\board@odd\@undefined% - \hex@dbg{1}{Board BB in hex: (\llx,\lly)x(\urx,\ury)} - %% - \def\fv{south} - \def\sv{north} - \ifnum\hex@coords@row@fac<0 - \def\fv{north} - \def\sv{south} - \fi - - \edef\hex@board@path{(hex cs:c=\llx,r=\lly,v=\fv\space west)} - %% First the left side - \foreach \r in {\lly,...,\ury} {% - \edef\t{ - --(hex cs:c=\llx,r=\r,v=west) - --(hex cs:c=\llx,r=\r,v=\sv\space west)} - \wg@addto@macro{\hex@board@path}{\t}} - %% Then for top of board - \foreach \c in {\llx,...,\urx} {% - % To be done - %\pgfmathparse{int(ifthenelse(\hex@bot@short@col(\c),1,0))} - %\edef\tmp{\pgfmathresult} - %\ifnum\tmp>0 - %\edef\t{ - % --(hex cs:c=\c,r=\ury,v=\sv\space west) - % --(hex cs:c=\c,r=\ury,v=\sv\space east)} - %\else - \edef\t{ - --(hex cs:c=\c,r=\ury,v=\fv\space east) - --(hex cs:c=\c,r=\ury,v=\fv\space west)} - %\fi - \wg@addto@macro{\hex@board@path}{\t}} - %% Then for right of board - \foreach \r in {\ury,...,\lly} {% - \edef\t{ - --(hex cs:c=\urx,r=\r,v=east) - --(hex cs:c=\urx,r=\r,v=\fv\space east)} - \wg@addto@macro{\hex@board@path}{\t}} - - %% Then for bottom of board - \edef\t{--(hex cs:r=\lly,c=\urx,v=\fv\space west)} - \wg@addto@macro{\hex@board@path}{\t} - \foreach \c in {\urx,...,\llx} {% - \pgfmathparse{int(ifthenelse(\hex@bot@short@col(\c),1,0))} - \edef\tmp{\pgfmathresult} - \ifnum\tmp>0 - \edef\t{ - --(hex cs:c=\c,r=\lly,v=\sv\space east) - --(hex cs:c=\c,r=\lly,v=\sv\space west)} - \else - \edef\t{ - --(hex cs:c=\c,r=\lly,v=\fv\space east) - --(hex cs:c=\c,r=\lly,v=\fv\space west)} - \fi - \wg@addto@macro{\hex@board@path}{\t}} - - \def\t{--cycle} - \wg@addto@macro{\hex@board@path}{\t} + \edef\urc{\hex@col} + \edef\urr{\hex@row} + + % This will store the bounding box in tmp node `board frame' + \bo@rdfr@me{\llc}{\llr}{\urc}{\urr}% + %% Use the path to extract the bounding box + %\begin{scope}[local bounding box=board frame] + % \expandafter\path\hex@board@path; + %\end{scope} \global\let\hexboardpath\hex@board@path } -%\def\boardclip#1#2#3{% -% \pgfmathparse{int(#1-1)}\xdef\board@range{\pgfmathresult,...,0}% -% %% \show\board@range -% \draw \ifx|#3|\else[preaction={#3}]\fi% -% [clip] -% % [decorate,decoration={show path construction, -% % moveto code={\fill[red](\tikzinputsegmentfirst) circle(2pt) -% % node [fill=none,below]{moveto};}, -% % lineto code={\draw[thick,blue,->](\tikzinputsegmentfirst)-- -% % (\tikzinputsegmentlast) node [above] {lineto};}, -% % curveto code={\draw[thick,green,->](\tikzinputsegmentfirst).. -% % controls(\tikzinputsegmentsupporta) and -% % (\tikzinputsegmentsupportb) -% % ..(\tikzinputsegmentlast) node[above]{curveto};}, -% % closepath code={\draw[thick,orange,->](\tikzinputsegmentfirst)-- -% % (\tikzinputsegmentlast) node [above] {closepath};} -% % }] -% (hex cs:r=0,c=0,v=south west) -% %% First the left side -% \foreach \r in {0,1,...,#2} {% -% --(hex cs:c=0,r=\r,v=west)--(hex cs:c=0,r=\r,v=north west)} -% %% Then for top of board -% \foreach \c in {0,1,...,#1} {% -% --(hex cs:r=#2,c=\c,v=north west)--(hex cs:c=\c,r=#2,v=north east)} -% %% Then for right of board -% \foreach \r in {#2,...,0} {% -% --(hex cs:c=#1,r=\r,v=east)--(hex cs:c=#1,r=\r,v=south east)} -% %% Then for bottom of board -% --(hex cs:r=0,c=#1,v=south west) \foreach \c in \board@range {% -% --(hex cs:r=0,c=\c,v=south east) --(hex cs:c=\c,r=0,v=south west) } -% --cycle; } -%% New definition - much simpler + +% \end{macrocode} +% \begin{macrocode} \def\boardclip(#1)(#2)#3{% \boardpath(#1)(#2) \draw \ifx|#3|\else[preaction={#3}]\fi% diff --git a/macros/latex/contrib/wargame/source/hex/coord.dtx b/macros/latex/contrib/wargame/source/hex/coord.dtx index b996ffa3c2..147ae82892 100644 --- a/macros/latex/contrib/wargame/source/hex/coord.dtx +++ b/macros/latex/contrib/wargame/source/hex/coord.dtx @@ -278,11 +278,10 @@ % \begin{macrocode} \pgfmathparse{int(\hex@coords@col@fac*(\hex@col+\hex@coords@col@off))}% \xdef\hex@eff@col{\pgfmathresult}% - \hex@dbg{2}{Effective column: \hex@coords@col@fac * (\hex@col - + \hex@dbg{2}{Effective column: \hex@coords@col@fac * (\hex@col + \hex@coords@col@off) -> \hex@eff@col}% \pgfmathparse{\hex@eff@col*1.5}% \xdef\hex@x{\pgfmathresult}% - \expandafter\pgf@x=\hex@x cm% % \end{macrocode} % % And then for the $y$ coordinate and set the dimension \cs{pgf@y}. @@ -304,17 +303,21 @@ \hex@dbg{2}{Effective row: \hex@coords@row@fac * (\hex@row + \hex@coords@row@off) -> \hex@eff@row}% \pgfmathparse{(2*\hex@eff@row-mod(round((\hex@col+\hex@coords@col@off)),2))*\hex@yy}% + \pgfmathparse{(2*\hex@eff@row-mod(abs(round(\hex@col+\hex@coords@col@off)),2))*\hex@yy}% \xdef\hex@y{\pgfmathresult}% - \expandafter\pgf@x=\hex@y cm% % \end{macrocode} % % If we have a vertex specification add that location to the current % coordinates. If not, set the point. % % \begin{macrocode} - \ifx\hex@vtx\@empty\pgfpointxy{\hex@x}{\hex@y}\else% - \pgfpointadd{\pgfpointxy{\hex@x}{\hex@y}}{% - \pgfpointscale{\hex@off}{\pgfpointpolarxy{\hex@vtx}{1}}}\fi% + \ifx\hex@vtx\@empty\else% + \pgfmathparse{\hex@x+\hex@off*cos(\hex@vtx)}\xdef\hex@x{\pgfmathresult} + \pgfmathparse{\hex@y+\hex@off*sin(\hex@vtx)}\xdef\hex@y{\pgfmathresult} + \fi% + % \ifx\hex@vtx\@empty\pgfpointxy{\hex@x}{\hex@y}\else% + % \pgfpointadd{\pgfpointxy{\hex@x}{\hex@y}}{% + % \pgfpointscale{\hex@off}{\pgfpointpolarxy{\hex@vtx}{1}}}\fi% % \end{macrocode} % % If we have an edge specification add that location to the current @@ -322,20 +325,28 @@ % % \begin{macrocode} \ifx\hex@edg\@empty\else% - \pgfpointadd{\pgfpointxy{\hex@x}{\hex@y}}{% - \pgfpointscale{\hex@off}{\pgfpointpolarxy{\hex@edg}{\hex@yy}}}\fi + \pgfmathparse{\hex@x+\hex@off*\hex@yy*cos(\hex@edg)}% + \xdef\hex@x{\pgfmathresult}% + \pgfmathparse{\hex@y+\hex@off*\hex@yy*sin(\hex@edg)}% + \xdef\hex@y{\pgfmathresult}% + \fi% + % \ifx\hex@edg\@empty\else% + % \pgfpointadd{\pgfpointxy{\hex@x}{\hex@y}}{% + % \pgfpointscale{\hex@off}{\pgfpointpolarxy{\hex@edg}{\hex@yy}}}\fi % \end{macrocode} % % For debugging, we can print out stuff. % % \begin{macrocode} + \pgfpointxy{\hex@x}{\hex@y} \hex@dbg{2}{Hex coordinates: #1 - ^^J c=\hex@col - ^^J r=\hex@row - ^^J v=\hex@vtx - ^^J e=\hex@edg - ^^J x=\hex@x - ^^J y=\hex@y}% + ^^J c=`\hex@col' + ^^J r=`\hex@row' + ^^J v=`\hex@vtx' + ^^J e=`\hex@edg' + ^^J o=`\hex@off' + ^^J x=`\hex@x' + ^^J y=`\hex@y'}% \global\let\hex@x\hex@x% \global\let\hex@y\hex@y% \global\let\hex@row\hex@row% diff --git a/macros/latex/contrib/wargame/source/hex/core.dtx b/macros/latex/contrib/wargame/source/hex/core.dtx index ee04290955..89179ef9fd 100644 --- a/macros/latex/contrib/wargame/source/hex/core.dtx +++ b/macros/latex/contrib/wargame/source/hex/core.dtx @@ -89,6 +89,7 @@ % \input{hex/extra.dtx} % \input{hex/paths.dtx} % \input{hex/board.dtx} +% \input{hex/split.dtx} % \iffalse %</hex> % \fi diff --git a/macros/latex/contrib/wargame/source/hex/extra.dtx b/macros/latex/contrib/wargame/source/hex/extra.dtx index 05f7215297..f2e6e1cb75 100644 --- a/macros/latex/contrib/wargame/source/hex/extra.dtx +++ b/macros/latex/contrib/wargame/source/hex/extra.dtx @@ -18,7 +18,7 @@ % \begin{macrocode} \tikzset{% hex/fortress/.pic={ - \path[draw,pic actions] + \path[draw,solid,pic actions] (0: .9) -- (0: .7) -- (60: .7) -- ( 60:.9) -- ( 60:.7) -- diff --git a/macros/latex/contrib/wargame/source/hex/paths.dtx b/macros/latex/contrib/wargame/source/hex/paths.dtx index 833a4a245a..813ab869fa 100644 --- a/macros/latex/contrib/wargame/source/hex/paths.dtx +++ b/macros/latex/contrib/wargame/source/hex/paths.dtx @@ -45,19 +45,45 @@ } }% }% - +% \end{macrocode} +% +% A decoration to make a fortification line +% +% \begin{macrocode} +\pgfdeclaredecoration{fortification}{initial} +{ + \state{initial}[width=4\pgflinewidth] + { + \pgfpathlineto{\pgfpoint{2\pgflinewidth}{0}} + \pgfpathlineto{\pgfpoint{2\pgflinewidth}{2\pgflinewidth}} + \pgfpathlineto{\pgfpoint{4\pgflinewidth}{2\pgflinewidth}} + \pgfpathlineto{\pgfpoint{4\pgflinewidth}{0}} + } + \state{final} + { + \pgfpathlineto{\pgfpointdecoratedpathlast} + } +} +% \end{macrocode} +% +% Roads, railroads, rivers, borders. +% +% \begin{macrocode} \tikzset{ hex/road/.style={ rounded corners=3\pgflinewidth,% .25cm, color=black, transform shape, scale line widths, - thick}, + thick, + every hex road/.try, + }, hex/railroad/.style={ %scale line widths, rounded corners=.25cm, color=gray!50!black, transform shape, + every hex railroad/.try, postaction={draw,decorate}, decoration={ticks, segment length=9\pgflinewidth, @@ -67,29 +93,42 @@ hex/river/.style={ color=blue, scale line widths, + scale rounded corners, line width=3pt, transform shape, + every hex river/.try, decorate, decoration={random steps, - segment length=.3cm, - amplitude=.15cm, + segment length=3\pgflinewidth, + amplitude=1.5\pgflinewidth, pre=lineto, post=lineto, - pre length=.05cm, - post length=.05cm}, - rounded corners=.08cm}, + pre length=.5\pgflinewidth, + post length=.5\pgflinewidth}, + rounded corners=.75\pgflinewidth}, hex/border/.style={ color=gray, - rounded corners=3pt, dashed, transform shape, scale line widths, - very thick + very thick, + rounded corners=3\pgflinewidth, + every hex border/.try }, - every river/.style={}, - every road/.style={}, - every railroad/.style={}, - every border/.style={}, + % + % Fortification line + % + hex/fortified line/.style={ + draw=brown!50!black, + scale line widths, + line width=2pt, + every hex fortification line/.try, + decoration={fortification,raise=-2\pgflinewidth}, + decorate}, + % every river/.style={}, + % every road/.style={}, + % every railroad/.style={}, + % every border/.style={}, } % \end{macrocode} % @@ -97,25 +136,30 @@ % % \begin{macrocode} \def\road{% - \hex@dbg{3}{Road} + %\hex@dbg{3}{Road} \@ifnextchar[{\road@}{\road@[]}%] } \def\road@[#1]{\draw[hex/road,every hex road/.try,#1]} \def\railroad{% - \hex@dbg{3}{Rail road} + %\hex@dbg{3}{Rail road} \@ifnextchar[{\railroad@}{\railroad@[]}%] } \def\railroad@[#1]{\draw[hex/railroad,every hex railroad/.try,#1]} \def\river{% - \hex@dbg{3}{River} + %\hex@dbg{3}{River} \@ifnextchar[{\river@}{\river@[]}%] } -\def\river@[#1]{\draw[hex/river,every hex river/.try,#1]} +\def\river@[#1]{\draw[hex/river,#1]} \def\border{% \hex@dbg{3}{Border} \@ifnextchar[{\border@}{\border@[]}%] } \def\border@[#1]{\draw[hex/border,every hex border/.try,#1]} +\def\fortifiedline{% + \@ifnextchar[{\fortifiedline@}{\fortifiedline@[]}%] +}% +\def\fortifiedline@[#1]{% + \draw[hex/fortified line,every hex fortified line/.try,#1]} % \end{macrocode} % \end{Macro} % @@ -209,10 +253,10 @@ markings, mark=between positions 0 and 1 step 0.75*\hex@scale*\hex@dy with { \node [single arrow, - single arrow head extend=3pt, + single arrow head extend=.1*\hex@scale*\hex@dy, fill=#1, - inner sep=\hex@scale*.5mm, - minimum width=\hex@scale*2mm, + inner sep=0.05*\hex@scale*\hex@dy, + minimum width=0.02*\hex@scale*\hex@dy, minimum height=\hex@scale*\hex@dy/2, transform shape]{}; } @@ -236,10 +280,10 @@ markings, mark=between positions 0 and 1 step 0.5*\hex@scale*\hex@dy with { \node [single arrow, - single arrow head extend=3pt, + single arrow head extend=.1*\hex@scale*\hex@dy, fill=#1, - inner sep=\hex@scale*.5mm, - minimum width=\hex@scale*2mm, + inner sep=0.05*\hex@scale*\hex@dy, + minimum width=0.02*\hex@scale*\hex@dy, minimum height=\hex@scale*\hex@dy/3, transform shape]{}; } @@ -270,7 +314,7 @@ anchor=west, inner sep=\hex@scale*.25mm, outer sep=.3*\hex@scale*\hex@dy, - minimum width=\hex@scale*2mm, + minimum width=0.02*\hex@scale*\hex@dy, minimum height=1.4*\hex@scale*\hex@dy, transform shape]{}; } @@ -300,10 +344,10 @@ transform shape] {};}, mark=between positions 0 and 1 step 0.75*\hex@scale*\hex@dy with { \node [single arrow, - single arrow head extend=\hex@scale*3pt, + single arrow head extend=.1*\hex@scale*\hex@dy, fill=#1, - inner sep=\hex@scale*1mm, - minimum width=\hex@scale*3mm, + inner sep=0.05*\hex@scale*\hex@dy, + minimum width=0.02*\hex@scale*\hex@dy, minimum height=\hex@scale*\hex@dy/2, transform shape]{}; } @@ -331,7 +375,7 @@ fill=#2, transform shape, text=#1, - font=\sffamily\bfseries\Large}, + font=\sffamily\bfseries\fontsize{14.4}{17}\selectfont}, hex/move cost/.default={black}{none}, % Argument is fill colour % \end{macrocode} diff --git a/macros/latex/contrib/wargame/source/hex/ridges.dtx b/macros/latex/contrib/wargame/source/hex/ridges.dtx index 3914ff6ce5..24552e36e2 100644 --- a/macros/latex/contrib/wargame/source/hex/ridges.dtx +++ b/macros/latex/contrib/wargame/source/hex/ridges.dtx @@ -9,23 +9,31 @@ % A hex can be decorated with up to 6 ridges --- one for each edge of % the hexagon. The first thing is to set up the graphics style to use % for the ridges. We use the \spec{wave} decoration. +% +% If rounded corners are set for ridges, (e.g., via \spec{every hex +% ridges}), then it should be \spec{0pt} or \spec{4pt} (roughly 2mm) +% or larger. Otherwise, one will get a ``dimension too large'' +% error. % % \begin{macrocode} \tikzset{% - hex/ridges/.style={ + hex/ridges pre/.style={ line cap=round, draw=pgfstrokecolor, - rounded corners=.25cm, - scale line widths, + solid, + /hex/ridges/.cd,% + radius=0.85,% + n=4, + R=.25, + }, + hex/ridges/.style={ + get scale, decoration={ path has corners=true, - pre=waves, - post=waves, - pre length=-.1cm, - post length=0cm, waves, - radius=.2cm, - segment length=.2cm}, + radius=\wg@scale\hex@r@R, + segment length=\wg@scale\hex@r@s, + }, decorate}} % \end{macrocode} % @@ -57,6 +65,7 @@ south/.is if=hex@r@s, south east/.is if=hex@r@se, radius/.store in=\hex@r@r, + curve radius/.store in=\hex@r@w, NE/.is if=hex@r@ne, N/.is if=hex@r@n, NW/.is if=hex@r@nw, @@ -64,6 +73,8 @@ S/.is if=hex@r@s, SE/.is if=hex@r@se, r/.store in=\hex@r@r, + n/.store in=\hex@r@n, + R/.store in=\hex@r@w, } % \end{macrocode} % @@ -74,10 +85,11 @@ % the routine below is handcrafted since it is relatively simple. % % \begin{macrocode} +\newdimen\hex@r@s +\newdimen\hex@r@R \def\hex@do@ridges{% \edef\hex@r@tmp{[ - /hex/ridges/.cd,% - radius=0.8,% + hex/ridges pre, /tikz/every hex ridges/.try, \hex@ridges]} \expandafter\scope\hex@r@tmp% @@ -89,44 +101,70 @@ ^^Jsouth =\ifhex@r@s yes\else no\fi ^^Jsouth east=\ifhex@r@se yes\else no\fi ^^Jradius =\hex@r@r + ^^Jn =\hex@r@n } + \pgfmathparse{\hex@r@r/\hex@r@n}\xdef\hex@r@t{\pgfmathresult} + \hex@r@s=\hex@r@t cm + \hex@r@R=\hex@r@w cm \def\hex@r@p{} % Hand written algorithm \ifhex@r@ne - \def\hex@r@p{(0:\hex@r@r)--(60:\hex@r@r)} + \ifhex@r@se + \xdef\hex@r@p{(0:\hex@r@r)--(60:\hex@r@r)} + \else + \xdef\hex@r@p{($(0:\hex@r@r)+(-60:\hex@r@t/2)$)--(60:\hex@r@r)} + \fi + \hex@dbg{4}{Ridge along north east edge: `\hex@r@p'} \fi \ifhex@r@n - \hex@dbg{4}{Ridge along north edge: `\hex@r@p'} \ifhex@r@ne\else - \xdef\hex@r@p{\hex@r@p ( 60:\hex@r@r)} + \xdef\hex@r@p{\hex@r@p ($( 60:\hex@r@r)+(0:\hex@r@t/2)$)} \fi \xdef\hex@r@p{\hex@r@p --(120:\hex@r@r)} + \hex@dbg{4}{Ridge along north edge: `\hex@r@p'} \fi \ifhex@r@nw \ifhex@r@n\else - \xdef\hex@r@p{\hex@r@p (120:\hex@r@r)} + \xdef\hex@r@p{\hex@r@p ($(120:\hex@r@r)+(60:\hex@r@t/2)$)} \fi \xdef\hex@r@p{\hex@r@p --(180:\hex@r@r)} + \hex@dbg{4}{Ridge along north west: `\hex@r@p'} \fi \ifhex@r@sw \ifhex@r@nw\else - \xdef\hex@r@p{\hex@r@p (180:\hex@r@r)} + \xdef\hex@r@p{\hex@r@p ($(180:\hex@r@r)+(120:\hex@r@t/2)$)} + \fi + \ifhex@r@s + \xdef\hex@r@p{\hex@r@p --(240:\hex@r@r)} + \else + \xdef\hex@r@p{\hex@r@p --(240:\hex@r@r)} \fi - \xdef\hex@r@p{\hex@r@p --(240:\hex@r@r)} + \hex@dbg{4}{Ridge along south west: `\hex@r@p'} \fi \ifhex@r@s \ifhex@r@sw\else - \xdef\hex@r@p{\hex@r@p (240:\hex@r@r)} + \xdef\hex@r@p{\hex@r@p ($(240:\hex@r@r)+(-\hex@r@t/2,0)$)} \fi - \xdef\hex@r@p{\hex@r@p --(300:\hex@r@r)} + \ifhex@r@se + \xdef\hex@r@p{\hex@r@p --(300:\hex@r@r)} + \else + \xdef\hex@r@p{\hex@r@p --(300.5:\hex@r@r)} + \fi + \hex@dbg{4}{Ridge along south: `\hex@r@p'} \fi \ifhex@r@se \ifhex@r@s\else - \xdef\hex@r@p{\hex@r@p (300:\hex@r@r)} + \xdef\hex@r@p{\hex@r@p ($(300:\hex@r@r)+(-120:\hex@r@t/2)$)} + \fi + \ifhex@r@ne + \xdef\hex@r@p{\hex@r@p --cycle} + \else + \xdef\hex@r@p{\hex@r@p --(.5:\hex@r@r)} \fi - \xdef\hex@r@p{\hex@r@p --(360:\hex@r@r)} + \hex@dbg{4}{Ridge along se: `\hex@r@p'} \fi \hex@dbg{3}{ Ridges path: \hex@r@p} + % \draw[red] \hex@r@p; \draw[hex/ridges] \hex@r@p; \endscope% End of ridges scope } diff --git a/macros/latex/contrib/wargame/source/hex/shape.dtx b/macros/latex/contrib/wargame/source/hex/shape.dtx index 0d31da837f..104dbf23c6 100644 --- a/macros/latex/contrib/wargame/source/hex/shape.dtx +++ b/macros/latex/contrib/wargame/source/hex/shape.dtx @@ -14,6 +14,77 @@ % such as terrain and so on. % % \begin{macrocode} +\tikzset{% + /hex/.cd, + bev/.store in=\hex@bevel, bev/.initial=, + bevel fraction/.store in=\hex@bevel@frac,bevel fraction/.initial=10, + bevel/.is choice, + bevel/none/.style = {/hex/bev=}, + bevel/north west/.style = {/hex/bev=1}, + bevel/north east/.style = {/hex/bev=2}, + bevel/south west/.style = {/hex/bev=3}, + bevel/south east/.style = {/hex/bev=4}, + bevel/NW/.style = {/hex/bev=1}, + bevel/NE/.style = {/hex/bev=2}, + bevel/SW/.style = {/hex/bev=3}, + bevel/SE/.style = {/hex/bev=4}, + bevel/.default = {north west}, +} +\def\hex@bevel@frac{10} +\tikzset{ + hex/bevel highlight/.style={fill=white,opacity=.25}, + hex/bevel shadow/.style={fill=black,opacity=.25}, +} +% \end{macrocode} +% +% +% +% \begin{macrocode} +\newdimen\wg@tmpe +\newdimen\wg@tmpf +\newdimen\wg@tmpg +\def\hex@bevel@path#1{% + \scope[#1] + \wg@tmpe=\wg@tmpa\multiply\wg@tmpe by \hex@bevel@frac + \wg@tmpf=\wg@tmpb\multiply\wg@tmpf by \hex@bevel@frac + \wg@tmpg=\wg@tmpc\multiply\wg@tmpg by \hex@bevel@frac + \divide\wg@tmpe100 + \divide\wg@tmpf100 + \divide\wg@tmpg100 + % Start + \pgfpathmoveto{\pgfqpoint{\wg@tmpa}{\wg@tmpb}}% + % Left + \pgfpathlineto{\pgfqpoint{-\wg@tmpa}{\wg@tmpb}}% + % Left-down + \pgfpathlineto{\pgfqpoint{\wg@tmpc}{\wg@tmpd}}% + % Right down + \wg@tmpa=-\wg@tmpa% + \wg@tmpb=-\wg@tmpb% + \pgfpathlineto{\pgfqpoint{\wg@tmpa}{\wg@tmpb}}% + % Up, in + \advance\wg@tmpa\wg@tmpe% + \advance\wg@tmpb\wg@tmpf% + \pgfpathlineto{\pgfqpoint{\wg@tmpa}{\wg@tmpb}}% + % Left-down, in + \advance\wg@tmpc-\wg@tmpg + \pgfpathlineto{\pgfqpoint{\wg@tmpc}{\wg@tmpd}}% + % Left, down in + \advance\wg@tmpb-\wg@tmpf\wg@tmpb-\wg@tmpb% + \advance\wg@tmpb-\wg@tmpf + \pgfpathlineto{\pgfqpoint{\wg@tmpa}{\wg@tmpb}}% + % Start, down in + \advance\wg@tmpa-\wg@tmpe\wg@tmpa-\wg@tmpa% + \advance\wg@tmpa-\wg@tmpe + \pgfpathlineto{\pgfqpoint{\wg@tmpa}{\wg@tmpb}}% + % % + \pgfclosepath% + \pgfusepath{fill} + \endscope}% +% \end{macrocode} +% +% +% +% \begin{macrocode} \hex@dbg{5}{Base vertex: \hex@xx,\hex@yy} \hex@dbg{5}{Base edges: \hex@e@xx,\hex@e@yy} \pgfdeclareshape{hex/hex}{% @@ -187,6 +258,40 @@ % \begin{macrocode} \@ifundefined{hex@label}{\let\hex@label\empty}{} \ifx\hex@label\empty\else\hex@do@label\fi% +% \end{macrocode} +% +% \begin{macrocode} + \@ifundefined{hex@bevel}{\let\hex@bevel\empty}{} + \ifx\hex@bevel\empty\else% + \northeast + \wg@tmpa=\pgf@x\wg@tmpb=\pgf@y% + \west + \wg@tmpc=\pgf@x\wg@tmpd=\pgf@y% + \ifcase\hex@bevel\relax + \or%1 + \or\wg@tmpa=-\wg@tmpa\wg@tmpc=-\wg@tmpc%2 + \or\wg@tmpb=-\wg@tmpb\wg@tmpd=-\wg@tmpd%3 + \or% 4 + \wg@tmpa=-\wg@tmpa\wg@tmpc=-\wg@tmpc% + \wg@tmpb=-\wg@tmpb\wg@tmpd=-\wg@tmpd% + \fi + \hex@bevel@path{chit/bevel highlight} + \northeast + \wg@tmpa=-\pgf@x\wg@tmpb=-\pgf@y% + \west + \wg@tmpc=-\pgf@x\wg@tmpd=-\pgf@y% + \ifcase\hex@bevel\relax + \or%1 + \or\wg@tmpa=-\wg@tmpa\wg@tmpc=-\wg@tmpc%2 + \or\wg@tmpb=-\wg@tmpb\wg@tmpd=-\wg@tmpd%3 + \or% 4 + \wg@tmpa=-\wg@tmpa\wg@tmpc=-\wg@tmpc% + \wg@tmpb=-\wg@tmpb\wg@tmpd=-\wg@tmpd% + \fi + \hex@bevel@path{chit/bevel shadow} + \fi +% \end{macrocode} +% \begin{macrocode} \endscope% % \end{macrocode} % diff --git a/macros/latex/contrib/wargame/source/hex/split.dtx b/macros/latex/contrib/wargame/source/hex/split.dtx new file mode 100644 index 0000000000..3996b8848f --- /dev/null +++ b/macros/latex/contrib/wargame/source/hex/split.dtx @@ -0,0 +1,517 @@ +% \iffalse +% -------------------------------------------------------------------- +%<*hex> +% \fi +% +% \subsubsection{Board splitting} +% \label{sec:impl:hex:split} +% +% \begin{Macro}{\splitboard} +% +% Calculates how to split a board into sheets of paper. +% +% \begin{Syntax} +% \cs{splitboard}\oarg{options} +% \end{Syntax} +% +% where options are +% +% \begin{itemize} +% \item \spec{paper}=\meta{format}: Specifies the paper format. One +% of \spec{a4}, \spec{a3}, \spec{letter}, \spec{tabloid}. Default +% is \spec{a4}. +% \item \spec{landscape}: Sets the paper format to be in landscape +% mode (default is portrait). +% \item \spec{margin}=\meta{size in centimetres}: Size of margins on +% each sheet in centimetres \emph{without} unit. That is put +% \spec{0.6} for 6mm, \emph{not} \spec{6mm}. Default is \spec{0.6}. +% This should be \emph{slightly} larger (by roughly 5\%) than the +% \emph{least} margin required by the printer used. \emph{Must} be +% given \emph{before} \spec{paper} to have any effect. +% \item \spec{ncol}=\meta{number of columns}: Sets the number of +% columns of sheets. +% \item \spec{nrow}=\meta{number of rows}: Set the number of rows of +% sheets. +% \item \spec{overlap}=\meta{size in centimetres}: Sets the size of +% the overlap between sheets in centimetres \emph{without} unit. +% That is put \spec{2} for 2cm, \emph{not} \spec{2cm}. Default is +% \spec{2}. +% \item \spec{image}=\meta{file name}: File name of the board image +% (a PDF). Default is \spec{board} +% \item \spec{output}=\meta{file name}: File name (without +% \spec{.tex} ending) to write calculated split to. +% \item \spec{standalone}: Boolean flag. If true, then output file +% will be a standalone document (i.e., has a \cs{documentclass}). +% \item \spec{scale}=\meta{scale}: Set scale of board. +% \end{itemize} +% +% The macro will produce a file named \cs{jobname}\spec{\_out.tex} +% which can be included in another document to generate the split +% board PDF. +% +% To use, make, for example, the file \spec{calcsplit.tex} with the +% content +% +% \begin{verbatim} +% \documentclass[11pt]{standalone} +% \usepackage{wargame} +% \usepackage{mystyle} +% \begin{document} +% \splitboard{paper=letter,margin=.7,ncol=2,nrow=2,overlap=1} +% \end{document} +% \end{verbatim} +% +% to calculate the split of \spec{board.pdf} over $2\times2$ letter +% paper sheets, with a non-printable margin of 7mm, and an overlap +% between the segments of 1cm. +% +% The final split document can then be +% +% \begin{verbatim} +% \documentclass[11pt]{article} +% \usepackage[letterpaper,margin=7mm]{geometry} +% \begin{document} +% \input{calcsplit_out} +% \end{document} +% \end{verbatim} +% +% +% If you need to scale down the board, define the style \spec{board +% scale}. E.g., +% +% \begin{verbatim} +% \tikzset{board scale/.style={scale=.9}} +% \end{verbatim} +% +% \end{Macro} +% +% +% Styles used for drawing things. +% +% \begin{macrocode} +\tikzset{% + % Margin must be <1cm + split/paper outline/.style={ + shape=rectangle, + draw=red!50!black, + line width=.5mm}, + split/effective outline/.style={ + shape=rectangle, + draw=green!50!black, + dashed, + line width=.5mm}, + split/board outline/.style={% + draw=magenta, + line width=.5mm, + dotted}, +} +% \end{macrocode} +% +% A scratch dimension used +% +% \begin{macrocode} +\newdimen\split@tmp +% \end{macrocode} +% +% Get upper right and lower left corners of node. Argument is node name. +% +% \begin{macrocode} +\def\split@getem#1{% + \draw (#1.north east);% + \pgfgetlastxy{\split@ulx}{\split@uly}% + \xdef\split@ulx{\split@ulx}% + \xdef\split@ulx{\split@ulx}% + \draw (#1.south west);% + \pgfgetlastxy{\split@lrx}{\split@lry}% + \xdef\split@lrx{\split@lrx}% + \xdef\split@lry{\split@lry}% +} +% \end{macrocode} +% +% Get board dimensions. Argument is node name. +% +% \begin{macrocode} +\def\split@getboard#1{% + \split@getem{#1}% + \xdef\split@bulx{\split@ulx}% + \xdef\split@buly{\split@uly}% + \xdef\split@blrx{\split@lrx}% + \xdef\split@blry{\split@lry}% + \split@w{\@percentchar\space Board: + (\split@bulx,\split@buly)(\split@blrx,\split@blry)}} +% \end{macrocode} +% +% Adjust placement of markers and cut lines. +% \begin{enumerate} +% \item Dimension to adjust +% \item Overlap dimension (with units) +% \end{enumerate} +% +% \begin{macrocode} +\def\split@adj#1#2{% + \split@tmp=#2% + \divide\split@tmp by 2% + \advance\split@tmp by #1% + \edef\t{\the\split@tmp}} +% \end{macrocode} +% +% Get initial offset in a direction. +% +% \begin{enumerate} +% \item Number of segments in direction +% \item Overlap in centimetres (without unit) +% \item Effective size, in centimetres (without unit), of sheets in +% direction +% \item Full size, in centimetres (without unit), of board in +% direction. +% \end{enumerate} +% +% \begin{macrocode} +\def\split@get@init#1#2#3#4{% + \pgfmathparse{((#1 * #3 - (#1 - 1) * #2) - #4)/2}% + \xdef\split@off{\pgfmathresult}% + \hex@dbg{2}{((#1 * #3 - (#1 - 1) * #2) - #4)/2 -> `\split@off'}} +% \end{macrocode} +% +% Get initial offset of first segment. +% +% \begin{enumerate} +% \item Number of rows +% \item Number of columns +% \item Overlap in centimetres (without unit) +% \item Effective height, in centimetres (without unit), of sheets +% \item Effective width, in centimetres (without unit), of sheets +% \item Full height, in centimetres (without unit), of board +% \item Full width, in centimetres (without unit), of board +% \end{enumerate} +% +% \begin{macrocode} +\def\split@getinit#1#2#3#4#5#6#7{% + \split@get@init{#1}{#3}{#4}{#6}\xdef\dy{\split@off cm} + \split@get@init{#2}{#3}{#5}{#7}\xdef\dx{\split@off cm}} +% \end{macrocode} +% +% Get coordinates of a segment +% +% \begin{enumerate} +% \item Column number +% \item Row number +% \item Overlap, in centimetres (without unit) +% \end{enumerate} +% +% \begin{macrocode} +\def\split@getcoords#1#2#3{% + \hex@dbg{2}{Getting coords `c#1r#2'}% + \split@getem{c#1r#2}% + \edef\sulx{\split@ulx}% + \edef\suly{\split@uly}% + \edef\slrx{\split@lrx}% + \edef\slry{\split@lry}% + \edef\mlx{\split@blrx}% + \edef\mrx{\split@bulx}% + \edef\mty{\split@buly}% + \edef\mby{\split@blry}% + \pgfmathparse{int(#1-1)}\edef\pc{\pgfmathresult}% + \pgfmathparse{int(#2-1)}\edef\pr{\pgfmathresult}% + \pgfmathparse{int(#1+1)}\edef\nc{\pgfmathresult}% + \pgfmathparse{int(#2+1)}\edef\nr{\pgfmathresult}% + \pgfutil@ifundefined{pgf@sh@ns@c\pc r#2}{}{% Left + \hex@dbg{3}{\space Getting left `c\pc r#2'}% + \split@getem{c\pc r#2}\split@adj{\split@ulx}{-#3}\edef\mlx{\t}}% + \pgfutil@ifundefined{pgf@sh@ns@c\nc r#2}{}{% Right + \hex@dbg{3}{\space Getting right `c\nc r#2'}% + \split@getem{c\nc r#2}\split@adj{\split@lrx}{#3}\edef\mrx{\t}}% + \pgfutil@ifundefined{pgf@sh@ns@c#1r\pr}{}{% Above + \hex@dbg{3}{\space Getting above `c#1 r\pr'}% + \split@getem{c#1r\pr}\split@adj{\split@lry}{#3} \edef\mty{\t}}% + \pgfutil@ifundefined{pgf@sh@ns@c#1r\nr}{}{% Below + \hex@dbg{3}{\space Getting below `c#1 r\nr'}% + \split@getem{c#1r\nr}\split@adj{\split@uly}{-#3}\edef\mby{\t}}% + \draw[fill=red] (\mlx,\mty) circle(.2);% + \draw[fill=green](\mrx,\mty) circle(.4);% + \draw[fill=blue] (\mlx,\mby) circle(.6);% + \draw[fill=cyan] (\mrx,\mby) circle(.8);% + \split@w{% + \@percentchar^^J% + \string\segment(\sulx,\suly)(\slrx,\slry){\mlx}{\mrx}{\mby}{\mty} + \@percentchar\space c#1r#2} +} +% \end{macrocode} +% +% Stream to write to +% +% \begin{macrocode} +\newwrite\split@calcout +% \end{macrocode} +% +% Short-hand for write outs. +% +% \begin{macrocode} +\def\split@w{\immediate\write\split@calcout} +% \end{macrocode} +% +% Open stream and set-up +% +% \begin{macrocode} +\def\split@header#1{% + \immediate\openout\split@calcout=#1.tex + \ifsplit@standalone + \pgfmathparse{\split@margin*.95}\edef\tmp{\pgfmathresult} + \split@w{\@percentchar\@percentchar\space These are made with + `calcsplit' with `-jobname \jobname'} + \split@w{ + ^^J\string\documentclass[twoside]{article} + ^^J\string\usepackage{geometry} + ^^J\string\geometry{papersize={\the\paperwidth,\the\paperheight},margin=\tmp cm} + ^^J\string\usepackage{wargame} + ^^J\string\setlength{\string\parindent}{0pt} + ^^J\string\setlength{\string\parskip}{0pt} + ^^J\string\begin{document} + ^^J\string\ignorespaces\@percentchar} + \fi + \split@w{\string\def\string\boardfile{\split@img}\@percentchar} + \split@w{\string\def\string\boardscale{\split@scale}\@percentchar} +} +% \end{macrocode} +% +% Write final stuff and close stream +% +% \begin{macrocode} +\def\split@footer{% + \ifsplit@standalone + \split@w{^^J\string\end{document}} + \fi + \split@w{^^J\@percentchar\@percentchar End of `\jobname'^^J} + \immediate\closeout\split@calcout +} +% \end{macrocode} +% +% Initial calculations. This draws the board and then extracts the +% dimensions of the board. It also defines some styles for drawing +% the board segments. +% +% \begin{macrocode} +\def\split@init#1{% + \node[scale=\split@scale, + inner sep=0pt, + outer sep=0pt, + anchor=north west, + transform shape](b){\includegraphics{#1}}; + \split@getboard{b} + %x + \split@tmp=\split@blrx cm\advance\split@tmp by -\split@bulx% + \wg@pt@to@cm{\split@tmp}\edef\split@bw{\pgfmathresult}% + \pgfmathparse{abs(\split@bw)}\edef\split@bw{\pgfmathresult}% + % + \split@tmp=\split@buly cm\advance\split@tmp by -\split@blry% + \wg@pt@to@cm{\split@tmp}\edef\split@bh{\pgfmathresult}% + \pgfmathparse{abs(\split@bh)}\edef\split@bh{\pgfmathresult}% + % + \wg@pt@to@cm{\paperwidth}\edef\split@pw{\pgfmathresult}% + \wg@pt@to@cm{\paperheight}\edef\split@ph{\pgfmathresult}% + % + \wg@pt@to@cm{\textwidth}\edef\split@ew{\pgfmathresult}% + \wg@pt@to@cm{\textheight}\edef\split@eh{\pgfmathresult}% + % + \hex@dbg{1}{Board: + (\split@bulx,\split@buly)(\split@blrx,\split@blry) \split@bw x\split@bh + ^^JPaper: \split@pw x\split@ph + ^^JEffective: \split@ew x\split@eh + } + \tikzset{ + split/paper size/.style={ + shape=rectangle, + minimum width=\paperwidth, + minimum height=\paperheight, + split/paper outline, + }, + split/effective size/.style={ + shape=rectangle, + minimum width=\textwidth, + minimum height=\textheight, + split/effective outline}, + split/board size/.style={ + shape=rectangle, + minimum width=\split@bw cm, + minimum height=\split@bh cm, + split/board outline}} + \node[board/.try,split/board size,anchor=north west] {}; +} +% \end{macrocode} +% +% Calculate effective sheet sizes from sheet dimensions and the +% defined margin. +% +% \begin{macrocode} +\def\split@text@dim#1{% + \textwidth=\paperwidth% + \textheight=\paperheight% + \advance\textwidth by -#1cm% + \advance\textwidth by -#1cm% + \advance\textheight by -#1cm% + \advance\textheight by -#1cm% + \global\textwidth=\textwidth% + \global\textheight=\textheight% +} +% \end{macrocode} +% +% Options for the \cs{splitboard} macro. +% +% \begin{macrocode} +\newif\ifsplit@standalone\split@standalonetrue +\tikzset{% + split/.search also={/tikz},% + split/.cd,% + margin/.store in=\split@margin, + paper/.is choice,% + paper/a4/.code={% + \hex@dbg{3}{A4 paper for split}% + \global\paperwidth=21cm% + \global\paperheight=29.7cm% + \split@text@dim{\split@margin}}, + paper/a3/.code={% + \hex@dbg{3}{A3 paper for split}% + \global\paperheight=42cm% + \global\paperwidth=29.7cm% + \split@text@dim{\split@margin}}, + paper/letter/.code={% + \hex@dbg{3}{Letter paper for split} + \paperheight=27.9cm,% + \paperwidth=21.6cm,% + \split@text@dim{\split@margin}},% + paper/tabloid/.code={% + \hex@dbg{3}{Tabloid paper for split}% + \paperheight=43.2cm,% + \paperwidth=27.9cm,% + \split@text@dim{\split@margin}}, + landscape/.code={% + \hex@dbg{3}{Landscape option for split} + \split@tmp=\paperheight + \global\paperheight=\paperwidth + \global\paperwidth=\split@tmp + \split@tmp=\textheight + \global\textheight=\textwidth + \global\textwidth=\split@tmp}, + standalone/.is if=split@standalone, + scale/.store in=\split@scale, + output/.store in=\split@out, + ncol/.store in=\split@ncol, + nrow/.store in=\split@nrow, + overlap/.store in=\split@ov, % Centimeter, no unit + image/.store in=\split@img, + paper/.default=a4, paper/.initial=a4, + margin/.default=.6, margin/.initial=.6, + ncol/.default=0, ncol/.initial=0, + nrow/.default=0, nrow/.initial=0, + overlap/.default=2, overlap/.initial=2, + image/.default=board, image/.initial=board, + output/.default=\jobname_out, + standalone/.default=true, + scale/.default=1, +} +% \end{macrocode} +% +% The actual macro. The argument is key-value pairs of options. +% +% \begin{macrocode} +\def\splitboard#1{% + \pgfkeys{/tikz/split/.cd,% + standalone,% + output,% + margin,% + paper,% + image,% + overlap,% + scale,% + ncol,% + nrow,% + #1} + \hex@dbg{1}{% + Paper: `\the\paperwidth'x`\the\paperheight' + ^^JEffective: `\the\textwidth'x`\the\textheight' + ^^JNcols: `\split@ncol' + ^^JNrows: `\split@nrow' + ^^JOverlap: `\split@ov' cm} + \split@header{\split@out} + \begin{tikzpicture} + \split@init{\split@img} + \split@getinit{% + \split@nrow}{% + \split@ncol}{% + \split@ov}{\split@eh}{\split@ew}{\split@bh}{\split@bw} + \node[split/effective size, + above left=\dy and \dx of b.north west, + anchor=north west] (c1r1) {}; + \node[split/paper size] at (c1r1) {}; + % + \foreach \r [remember=\r as \pr (initially 0)] in {1,...,\split@nrow}{% + \ifnum\r>1 + \hex@dbg{3}{Placing first column of row `\r'} + \node[split/effective size, + below=-\split@ov cm of c1r\pr.south west,anchor=north west] (c1r\r){}; + \node[split/paper size] at (c1r\r) {}; + \fi + \foreach \c [remember=\c as \pc (initially 1)] in {2,...,\split@ncol}{% + \ifnum\c>\split@ncol\else% + \ifnum\c>\pc + \hex@dbg{3}{Placing column `\c' (`\pc') of row `\r'} + \node[split/effective size, + right=-\split@ov cm of c\pc r\r.north east,anchor=north west] + (c\c r\r) {}; + \node[split/paper size] at (c\c r\r) {}; + \fi + \fi + } + } + \foreach \r [remember=\r as \pr (initially 0)] in {1,...,\split@nrow}{% + \foreach \c [remember=\c as \pc (initially 0)] in {1,...,\split@ncol}{% + \split@getcoords{\c}{\r}{\split@ov cm}}} + \end{tikzpicture} + \split@footer +} +% \end{macrocode} +% +% Macro used by the written file. +% +% +% \begin{enumerate} +% \item first coordinate (e.g., \spec{(hex ak:c=C,r=17)}) +% \item second coordinate (e.g., \spec{(hex ak:c=M,r=33)}) +% \item Crop mark left +% \item Crop mark right +% \item Crop mark bottom +% \item Crop mark top +% \end{enumerate} +% +% \begin{macrocode} +\def\segment(#1)(#2)#3#4#5#6{% + \begin{tikzpicture}% + \begin{scope} + \clip (#1) rectangle (#2); + \node[scale=\boardscale, + inner sep=0pt, + outer sep=0pt, + anchor=north west, + transform shape]{\includegraphics{\boardfile}}; + \end{scope} + \pgfinterruptboundingbox + \draw(#3,#6)--++( 0.0, 0.3); + \draw(#3,#6)--++(-0.3, 0.0); + \draw(#3,#5)--++( 0.0,-0.3); + \draw(#3,#5)--++(-0.3, 0.0); + \draw(#4,#6)--++( 0.0, 0.3); + \draw(#4,#6)--++( 0.3, 0.0); + \draw(#4,#5)--++( 0.0,-0.3); + \draw(#4,#5)--++( 0.3, 0.0); + \endpgfinterruptboundingbox + \end{tikzpicture}% + \cleardoublepage}% +% \end{macrocode} +% +% +% +% +% \iffalse +%</hex> +% -------------------------------------------------------------------- +% \fi diff --git a/macros/latex/contrib/wargame/source/hex/terrain.dtx b/macros/latex/contrib/wargame/source/hex/terrain.dtx index 42155ca5c9..4c486adf77 100644 --- a/macros/latex/contrib/wargame/source/hex/terrain.dtx +++ b/macros/latex/contrib/wargame/source/hex/terrain.dtx @@ -47,7 +47,7 @@ pic/.default=, image/.default=, code/.default=, - clip/.default, + clip/.default=, } \iffalse \tikzset{ @@ -111,8 +111,9 @@ % \begin{macrocode} \@ifundefined{hex@t@clip}{\let\hex@t@clip\empty}{} \ifx\hex@t@clip\empty\else% + \edef\hex@t@cc{\hex@t@clip}% \def\hex@t@c{} - \foreach \c in \hex@t@clip{% + \foreach \c in \hex@t@cc{% \hex@dbg{5}{Clipping to `\c'} \expandafter\wg@pic\c\@endwg@pic {}{\wg@tmpa,\wg@tmpb}{% save path=\hex@t@tmp}% @@ -132,8 +133,13 @@ %% macros are undefined, define them to be empty \@ifundefined{hex@t@pic}{\let\hex@t@pic\empty}{} \@ifundefined{hex@t@image}{\let\hex@t@image\empty}{} + \@ifundefined{hex@t@code}{\let\hex@t@code\empty}{} + \@ifundefined{hex@t@code}{\let\hex@t@code\empty}{} % \end{macrocode} % +% \begin{macrocode} + \ifx\hex@t@code\empty\else\hex@t@code\fi% +% \end{macrocode} % First we check if we have not got terrain images, but terrain % pictures. If we have that, we process these in turn. Note, the % user can give options to each terrain picture by preceding the @@ -147,7 +153,8 @@ % We have pictures \hex@dbg{5}{Terrain pictures}% \pgfpointorigin\wg@tmpa=\pgf@x\wg@tmpb=\pgf@y% - \wg@pic@all{\hex@t@pic}{}{\the\wg@tmpa,\the\wg@tmpb}{}% + \foreach \i in \hex@t@pic{% + \wg@pic@all{\i}{}{\the\wg@tmpa,\the\wg@tmpb}{}}% \fi% We have pictures. % \end{macrocode} % diff --git a/macros/latex/contrib/wargame/source/hex/terrain/beach.dtx b/macros/latex/contrib/wargame/source/hex/terrain/beach.dtx index 98e990c15c..a6a6905e1a 100644 --- a/macros/latex/contrib/wargame/source/hex/terrain/beach.dtx +++ b/macros/latex/contrib/wargame/source/hex/terrain/beach.dtx @@ -21,10 +21,14 @@ % \end{macrocode} % \end{TikzKey} % -% Now for the actual patterns. We go in the same order as above --- -% i.e, we start with the beach pattern. This is rather long. -% % \begin{TikzKey}{hex/terrain/beach} +% Now for the actual patterns. We go in the same order as above --- +% i.e, we start with the beach pattern. This is rather long. +% +% \begin{center} +% \includegraphics{wargame.beach} +% \end{center} +% % \begin{macrocode} \ifhex@terrain@pic \tikzset{ diff --git a/macros/latex/contrib/wargame/source/hex/terrain/city.dtx b/macros/latex/contrib/wargame/source/hex/terrain/city.dtx index 1d373ea19d..0f5f88eea6 100644 --- a/macros/latex/contrib/wargame/source/hex/terrain/city.dtx +++ b/macros/latex/contrib/wargame/source/hex/terrain/city.dtx @@ -5,6 +5,9 @@ % \begin{TikzKey}{hex/terrain/city} % And finally a city % +% \begin{center} +% \includegraphics{wargame.city} +% \end{center} % % \begin{macrocode} \ifhex@terrain@pic diff --git a/macros/latex/contrib/wargame/source/hex/terrain/light_woods.dtx b/macros/latex/contrib/wargame/source/hex/terrain/light_woods.dtx index ee15f5ce78..ededa87541 100644 --- a/macros/latex/contrib/wargame/source/hex/terrain/light_woods.dtx +++ b/macros/latex/contrib/wargame/source/hex/terrain/light_woods.dtx @@ -19,6 +19,10 @@ % \begin{TikzKey}{hex/terrain/light woods} % Next, we have light woods. % +% \begin{center} +% \includegraphics{wargame.light_woods} +% \end{center} +% % \begin{macrocode} \ifhex@terrain@pic \tikzset{ diff --git a/macros/latex/contrib/wargame/source/hex/terrain/mountains.dtx b/macros/latex/contrib/wargame/source/hex/terrain/mountains.dtx index 04f935bd92..f80b991e27 100644 --- a/macros/latex/contrib/wargame/source/hex/terrain/mountains.dtx +++ b/macros/latex/contrib/wargame/source/hex/terrain/mountains.dtx @@ -21,6 +21,10 @@ % And the mountains pattern. This is the same as the beach pattern, % only filled with a darker brown colour. % +% \begin{center} +% \includegraphics{wargame.mountains} +% \end{center} +% % \begin{macrocode} \ifhex@terrain@pic \tikzset{ diff --git a/macros/latex/contrib/wargame/source/hex/terrain/rough.dtx b/macros/latex/contrib/wargame/source/hex/terrain/rough.dtx index fe716add2f..a5fd0d6a06 100644 --- a/macros/latex/contrib/wargame/source/hex/terrain/rough.dtx +++ b/macros/latex/contrib/wargame/source/hex/terrain/rough.dtx @@ -19,6 +19,10 @@ % \begin{TikzKey}{hex/terrain/rough} % Roughs. Again, a bit long. % +% \begin{center} +% \includegraphics{wargame.rough} +% \end{center} +% % % \begin{macrocode} \ifhex@terrain@pic diff --git a/macros/latex/contrib/wargame/source/hex/terrain/swamp.dtx b/macros/latex/contrib/wargame/source/hex/terrain/swamp.dtx index b361789fa3..57ad7e9e65 100644 --- a/macros/latex/contrib/wargame/source/hex/terrain/swamp.dtx +++ b/macros/latex/contrib/wargame/source/hex/terrain/swamp.dtx @@ -18,6 +18,10 @@ % \begin{TikzKey}{hex/terrain/swamp} % Swamps. This is probably the shortest of the terrain patterns. % +% \begin{center} +% \includegraphics{wargame.swamp} +% \end{center} +% % \begin{macrocode} \ifhex@terrain@pic \tikzset{ diff --git a/macros/latex/contrib/wargame/source/hex/terrain/town.dtx b/macros/latex/contrib/wargame/source/hex/terrain/town.dtx index 1186b54c81..5956583ba6 100644 --- a/macros/latex/contrib/wargame/source/hex/terrain/town.dtx +++ b/macros/latex/contrib/wargame/source/hex/terrain/town.dtx @@ -5,6 +5,10 @@ % \begin{TikzKey}{hex/terrain/town} % A town. % +% \begin{center} +% \includegraphics{wargame.town} +% \end{center} +% % % \begin{macrocode} \ifhex@terrain@pic diff --git a/macros/latex/contrib/wargame/source/hex/terrain/village.dtx b/macros/latex/contrib/wargame/source/hex/terrain/village.dtx index 837b92642c..8aeddb2b9d 100644 --- a/macros/latex/contrib/wargame/source/hex/terrain/village.dtx +++ b/macros/latex/contrib/wargame/source/hex/terrain/village.dtx @@ -9,6 +9,10 @@ % houses, and separate styles for regular and small roads. Note % that we draw using the stroke colour for roads and houses. % +% \begin{center} +% \includegraphics{wargame.village} +% \end{center} +% % \begin{macrocode} \ifhex@terrain@pic \tikzset{ diff --git a/macros/latex/contrib/wargame/source/hex/terrain/woods.dtx b/macros/latex/contrib/wargame/source/hex/terrain/woods.dtx index 9b0d08499b..a8faccddf3 100644 --- a/macros/latex/contrib/wargame/source/hex/terrain/woods.dtx +++ b/macros/latex/contrib/wargame/source/hex/terrain/woods.dtx @@ -19,6 +19,10 @@ % \begin{TikzKey}{hex/terrain/woods} % Regular woods. % +% \begin{center} +% \includegraphics{wargame.woods} +% \end{center} +% % \begin{macrocode} \ifhex@terrain@pic \tikzset{ diff --git a/macros/latex/contrib/wargame/source/hex/towns.dtx b/macros/latex/contrib/wargame/source/hex/towns.dtx index a73c5eed5c..222b5f58da 100644 --- a/macros/latex/contrib/wargame/source/hex/towns.dtx +++ b/macros/latex/contrib/wargame/source/hex/towns.dtx @@ -13,6 +13,7 @@ \tikzset{% hex/town/.style={ scale line widths, + solid, thin, fill=pgfstrokecolor, color=pgfstrokecolor}, @@ -21,7 +22,7 @@ shape=rectangle, above right=.1, color=pgfstrokecolor, - font=\sffamily\normalsize} + font=\sffamily\fontsize{11}{13}\selectfont} } % \end{macrocode} % @@ -46,11 +47,11 @@ % % \begin{macrocode} \tikzset{% - hex/town/village/.pic={\path[fill,pic actions] circle(.1);}, - hex/town/town/.pic={\path[fill,pic actions] circle(.2);}, + hex/town/village/.pic={\path[fill,solid,pic actions] circle(.1);}, + hex/town/town/.pic={\path[fill,solid,pic actions] circle(.2);}, hex/town/city/.pic={% - \path[fill,pic actions] circle(.25); - \path[draw,pic actions] circle(.35);} + \path[fill,solid,pic actions] circle(.25); + \path[draw,solid,pic actions] circle(.35);} } % \end{macrocode} % |