| 1 |
% \iffalse |
| 2 |
% -------------------------------------------------------------------- |
| 3 |
%<*hex> |
| 4 |
% \fi |
| 5 |
% |
| 6 |
% \subsubsection{Terrain} |
| 7 |
% \label{sec:impl:hex:terrain} |
| 8 |
% |
| 9 |
% With the above main routine for making hexes, we turn to decorating |
| 10 |
% a hex with a terrain. |
| 11 |
% |
| 12 |
% \begin{HexKey*}{hex/terrain/image, |
| 13 |
% hex/terrain/pic, |
| 14 |
% hex/terrain/code, |
| 15 |
% hex/terrain/clip} |
| 16 |
% |
| 17 |
% We make the namespace \spec{/hex/terrain} to hold the |
| 18 |
% specific terrain keys. Keys used by terrain identifiers are |
| 19 |
% |
| 20 |
% \begin{tabular}{|l|p{.7\linewidth}|} |
| 21 |
% \hline |
| 22 |
% \rowcolor{headbg} |
| 23 |
% {\color{headfg}\textbf{Name}} |
| 24 |
% & {\color{headfg}\textbf{Description}}\\ |
| 25 |
% \hline |
| 26 |
% \spec{image} & Terrain tile image\\ |
| 27 |
% \spec{pic} & Terrain \TikZ{} \spec{pic}ture\\ |
| 28 |
% \spec{code} & Arbitary \TikZ{} code\\ |
| 29 |
% \spec{clip} & \TikZ{} path to clip terrain\\ |
| 30 |
% \hline |
| 31 |
% \end{tabular} |
| 32 |
% |
| 33 |
% Now, we have the keys we'll need for selecting the terrain. These |
| 34 |
% live in the namespace \spec{/hex/terrain}, and we can select |
| 35 |
% between \spec{pic}tures or \spec{image}s (external graphics files) |
| 36 |
% for making the terrain. We define some short hands to easily |
| 37 |
% select the common terrains. |
| 38 |
% |
| 39 |
% \begin{macrocode} |
| 40 |
\newif\if@hex@t@rot\@hex@t@rotfalse% |
| 41 |
\tikzset{% |
| 42 |
/hex/terrain/.search also={/tikz},% |
| 43 |
/hex/terrain/.cd,% |
| 44 |
pic/.store in=\hex@t@pic,% |
| 45 |
image/.store in=\hex@t@image,% |
| 46 |
code/.store in=\hex@t@code,% |
| 47 |
clip/.store in=\hex@t@clip,% |
| 48 |
random rotation/.is if=@hex@t@rot, |
| 49 |
rotate/.store in=\hex@t@s@angle, |
| 50 |
pic/.default=, |
| 51 |
image/.default=, |
| 52 |
code/.default=, |
| 53 |
clip/.default=, |
| 54 |
rotate/.default=, |
| 55 |
} |
| 56 |
\iffalse |
| 57 |
\tikzset{ |
| 58 |
/hex/terrain/.cd,% |
| 59 |
beach/.style={pic=hex/terrain/beach}, |
| 60 |
fields/.style={pic=hex/terrain/fields}, |
| 61 |
speckle/.style={pic=hex/terrain/speckle}, |
| 62 |
light woods/.style={pic=hex/terrain/light woods}, |
| 63 |
woods/.style={pic=hex/terrain/woods}, |
| 64 |
swamp/.style={pic=hex/terrain/swamp}, |
| 65 |
rough/.style={pic=hex/terrain/rough}, |
| 66 |
mountains/.style={pic=hex/terrain/mountains}, |
| 67 |
village/.style={pic=hex/terrain/village}, |
| 68 |
town/.style={pic=hex/terrain/town}, |
| 69 |
city/.style={pic=hex/terrain/city}, |
| 70 |
} |
| 71 |
\else |
| 72 |
\tikzset{ |
| 73 |
/hex/terrain/.cd,% |
| 74 |
beach/.style={image=wargame.beach}, |
| 75 |
fields/.style={image=wargame.fields}, |
| 76 |
speckle/.style={image=wargame.speckle}, |
| 77 |
light woods/.style={image=wargame.light_woods}, |
| 78 |
woods/.style={image=wargame.woods}, |
| 79 |
swamp/.style={image=wargame.swamp}, |
| 80 |
rough/.style={image=wargame.rough}, |
| 81 |
mountains/.style={image=wargame.mountains}, |
| 82 |
village/.style={image=wargame.village}, |
| 83 |
town/.style={image=wargame.town}, |
| 84 |
city/.style={image=wargame.city}, |
| 85 |
} |
| 86 |
\fi |
| 87 |
% \end{macrocode} |
| 88 |
% \end{HexKey*} |
| 89 |
% |
| 90 |
% |
| 91 |
% Before we go on, we define the macro that actually generates the |
| 92 |
% terrain of a hex. |
| 93 |
% |
| 94 |
% \begin{Macro}{\hex@do@terrain} |
| 95 |
% If we do have a terrain specified, we start a new scope, this time |
| 96 |
% to clip the terrain by the clipping path specified by |
| 97 |
% \spec{hex=\{terrain=\{clip=...\}\}}. The first thing into the new |
| 98 |
% scope is to process the keys specified in |
| 99 |
% \spec{hex=\{terrain=...\}}. This will set the terrain and the |
| 100 |
% clipping of the terrain. |
| 101 |
% |
| 102 |
% \begin{macrocode} |
| 103 |
\def\hex@do@terrain{% |
| 104 |
\hex@dbg{5}{Terrain: \meaning\hex@terrain}% |
| 105 |
\edef\hex@t@tmp{[/hex/terrain/.cd,\hex@terrain]}% |
| 106 |
\expandafter\scope\hex@t@tmp% Scope for terrain clipping. |
| 107 |
\hex@dbg{5}{Terrain: |
| 108 |
^^J pic: \meaning\hex@t@pic |
| 109 |
^^J image: \meaning\hex@t@image |
| 110 |
^^J code: \meaning\hex@t@code |
| 111 |
^^J clip: \meaning\hex@t@clip} |
| 112 |
% \end{macrocode} |
| 113 |
% |
| 114 |
% We check to see if we have any clipping \spec{pic}tures. If so, we |
| 115 |
% process these in turn and append the soft path to a macro. Once |
| 116 |
% this is done, we use the soft path as a clipping path for the rest |
| 117 |
% of the (terrain) scope. |
| 118 |
% |
| 119 |
% \begin{macrocode} |
| 120 |
\@ifundefined{hex@t@clip}{\let\hex@t@clip\empty}{} |
| 121 |
\ifx\hex@t@clip\empty\else% |
| 122 |
\edef\hex@t@cc{\hex@t@clip}% |
| 123 |
\def\hex@t@c{} |
| 124 |
\foreach \c in \hex@t@cc{% |
| 125 |
\hex@dbg{5}{Clipping to `\c'} |
| 126 |
\expandafter\wg@pic\c\@endwg@pic {}{\wg@tmpa,\wg@tmpb}{% |
| 127 |
save path=\hex@t@tmp}% |
| 128 |
\wg@addto@macro\hex@t@c\hex@t@tmp % Append to clippping |
| 129 |
}% |
| 130 |
\pgfsyssoftpath@setcurrentpath{\hex@t@c}% Set path |
| 131 |
\clip;% Clip to the path |
| 132 |
\fi % End of clipping terrain |
| 133 |
% \end{macrocode} |
| 134 |
% |
| 135 |
% We're new ready to make the terrain. First, we check to see if the |
| 136 |
% relevant storage macros are undefined and if so, \cs{let} them to |
| 137 |
% \cs{empty} so that we can deal more easily with the various cases. |
| 138 |
% |
| 139 |
% \begin{macrocode} |
| 140 |
%% Now switch between how to draw the terrain. If some of the |
| 141 |
%% macros are undefined, define them to be empty |
| 142 |
\@ifundefined{hex@t@pic}{\let\hex@t@pic\empty}{} |
| 143 |
\@ifundefined{hex@t@image}{\let\hex@t@image\empty}{} |
| 144 |
\@ifundefined{hex@t@code}{\let\hex@t@code\empty}{} |
| 145 |
\@ifundefined{hex@t@code}{\let\hex@t@code\empty}{} |
| 146 |
% \end{macrocode} |
| 147 |
% |
| 148 |
% Possible make rotation. We define a scope and rotate within that. |
| 149 |
% |
| 150 |
% \begin{macrocode} |
| 151 |
\def\hex@t@angle{0}% |
| 152 |
\if@hex@t@rot% |
| 153 |
\pgfmathrandominteger{\hex@t@angle}{0}{5} |
| 154 |
\pgfmathparse{int(60*\hex@t@angle)}\edef\hex@t@angle{\pgfmathresult}% |
| 155 |
\else% |
| 156 |
\@ifundefined{hex@t@s@angle}{}{ |
| 157 |
\ifx\hex@t@s@angle\@empty% |
| 158 |
\else% |
| 159 |
\edef\hex@t@angle{\hex@t@s@angle}% |
| 160 |
\fi}% |
| 161 |
\fi% |
| 162 |
\hex@dbg{5}{Will rotate terrain by `\hex@t@angle'}% |
| 163 |
% \end{macrocode} |
| 164 |
% |
| 165 |
% If we have specified code for the terrain, then execute that. |
| 166 |
% |
| 167 |
% \begin{macrocode} |
| 168 |
\scope[rotate=\hex@t@angle]% |
| 169 |
\ifx\hex@t@code\empty\else\hex@t@code\fi% |
| 170 |
\endscope% End rotate code |
| 171 |
% \end{macrocode} |
| 172 |
% First we check if we have not got terrain images, but terrain |
| 173 |
% pictures. If we have that, we process these in turn. Note, the |
| 174 |
% user can give options to each terrain picture by preceding the |
| 175 |
% \spec{pic}ture name with \oarg{options}. |
| 176 |
% |
| 177 |
% \begin{macrocode} |
| 178 |
% If we have no image, check if we have pictures. |
| 179 |
\ifx\hex@t@image\empty% |
| 180 |
\hex@dbg{8}{No terrain images}% |
| 181 |
\ifx\hex@t@pic\empty\else% |
| 182 |
% We have pictures |
| 183 |
\hex@dbg{5}{Terrain pictures}% |
| 184 |
\pgfpointorigin\wg@tmpa=\pgf@x\wg@tmpb=\pgf@y% |
| 185 |
\foreach \i in \hex@t@pic{% |
| 186 |
\wg@pic@all{\i}{}{\the\wg@tmpa,\the\wg@tmpb}{% |
| 187 |
rotate=\hex@t@angle, |
| 188 |
transform shape}}% |
| 189 |
\fi% We have pictures. |
| 190 |
% \end{macrocode} |
| 191 |
% |
| 192 |
% |
| 193 |
% If the user specified images rather than \spec{pic}tures, then we |
| 194 |
% process these in turn. Again, the user can specify options to each |
| 195 |
% terrain image by preceding the image file name with \oarg{options}. |
| 196 |
% |
| 197 |
% \begin{macrocode} |
| 198 |
\else % We have images |
| 199 |
\hex@dbg{5}{Terrain images}% |
| 200 |
\pgfpointorigin\wg@tmpa=\pgf@x\wg@tmpb=\pgf@y% |
| 201 |
\foreach \i in \hex@t@image{% |
| 202 |
\hex@dbg{10}{Terrain image: `\meaning\i'} |
| 203 |
\expandafter\wg@node{% |
| 204 |
\includegraphics[width=2cm]{\i}}\@endwg@node % |
| 205 |
{}{\wg@tmpa,\wg@tmpb}{% |
| 206 |
rotate=\hex@t@angle,% |
| 207 |
shape=rectangle,% |
| 208 |
anchor=center,% |
| 209 |
transform shape,% |
| 210 |
draw=none}% |
| 211 |
} |
| 212 |
\fi% |
| 213 |
\endscope% End of terrain scope |
| 214 |
}% End of terrain |
| 215 |
% \end{macrocode} |
| 216 |
% \end{Macro} |
| 217 |
% |
| 218 |
% |
| 219 |
% |
| 220 |
% |
| 221 |
|
| 222 |
% |
| 223 |
% Next, we define some example clippings of the terrain images. |
| 224 |
% Specifcally, we make clippings to sextants. We do this by first |
| 225 |
% defining a macro. |
| 226 |
% |
| 227 |
% \begin{Macro}{\hex@make@sextants} |
| 228 |
% |
| 229 |
% When executed this macro will generate some paths that will clip |
| 230 |
% to sextants. The first argument is the inner radius of the |
| 231 |
% sextant and the second argument is the (possible empty) prefix to |
| 232 |
% put in front of the \spec{sextant} name. |
| 233 |
% |
| 234 |
% \begin{macrocode} |
| 235 |
\def\hex@x@r{.7} |
| 236 |
\def\hex@make@sextants#1#2{% |
| 237 |
\tikzset{% |
| 238 |
pics/hex/#2sextant/.is choice, |
| 239 |
pics/hex/#2sextant/north east/.style={ |
| 240 |
code={ |
| 241 |
\path[pic actions]( 0:1)--( 60:1)--( 60:#1)--( 0:#1)--cycle;}}, |
| 242 |
pics/hex/#2sextant/north/.style={ |
| 243 |
code={ |
| 244 |
\path[pic actions]( 60:1)--(120:1)--(120:#1)--( 60:#1)--cycle;}}, |
| 245 |
pics/hex/#2sextant/north west/.style={ |
| 246 |
code={ |
| 247 |
\path[pic actions](120:1)--(180:1)--(180:#1)--(120:#1)--cycle;}}, |
| 248 |
pics/hex/#2sextant/south west/.style={ |
| 249 |
code={ |
| 250 |
\path[pic actions](180:1)--(240:1)--(240:#1)--(180:#1)--cycle;}}, |
| 251 |
pics/hex/#2sextant/south/.style={ |
| 252 |
code={ |
| 253 |
\path[pic actions](240:1)--(300:1)--(300:#1)--(240:#1)--cycle;}}, |
| 254 |
pics/hex/#2sextant/south east/.style={ |
| 255 |
code={ |
| 256 |
\path[pic actions](300:1)--(360:1)--(360:#1)--(300:#1)--cycle;}}, |
| 257 |
pics/hex/#2sextant/center/.style={ |
| 258 |
code={ |
| 259 |
\path[pic actions] |
| 260 |
(0:#1)-- |
| 261 |
(60:#1)-- |
| 262 |
(120:#1)-- |
| 263 |
(180:#1)-- |
| 264 |
(240:#1)-- |
| 265 |
(300:#1)--cycle;}}, |
| 266 |
pics/hex/#2sextant/NE/.style=hex/#2sextant/north east, |
| 267 |
pics/hex/#2sextant/NE/.style=hex/#2sextant/north east, |
| 268 |
pics/hex/#2sextant/N/.style=hex/#2sextant/north, |
| 269 |
pics/hex/#2sextant/NW/.style=hex/#2sextant/north west, |
| 270 |
pics/hex/#2sextant/SW/.style=hex/#2sextant/south west, |
| 271 |
pics/hex/#2sextant/S/.style=hex/#2sextant/south, |
| 272 |
pics/hex/#2sextant/SE/.style=hex/#2sextant/south east, |
| 273 |
pics/hex/#2sextant/C/.style=hex/#2sextant/center, |
| 274 |
}% |
| 275 |
} |
| 276 |
% \end{macrocode} |
| 277 |
% \end{Macro} |
| 278 |
% |
| 279 |
% \begin{macrocode} |
| 280 |
\hex@make@sextants{.7}{} |
| 281 |
\hex@make@sextants{.3}{large } |
| 282 |
\hex@make@sextants{0}{full } |
| 283 |
% \end{macrocode} |
| 284 |
% \iffalse |
| 285 |
%</hex> |
| 286 |
% -------------------------------------------------------------------- |
| 287 |
% \fi |