Debian Codegraph @

texmf-dist/source/latex/wargame/hex/paths.dtx

raw
1 % \iffalse
2 % --------------------------------------------------------------------
3 %<*hex>
4 % \fi
5 %
6 % \subsubsection{Edges, borders, roads, rivers, and so on}
7 %
8 % Styles of drawing edges, borders, rivers, roads, and railroads.
9 %
10 % \begin{macrocode}
11 % A decoration to extract outline of a path
12 \pgfdeclaredecoration{outline}{init}
13 {%
14 \state{init}[next state=tick,width=0pt]{
15 \xdef\outlinerev{}}
16 \state{tick}[%
17 width=+\pgfdecorationsegmentlength]%
18 {
19 \pgfpathlineto{\pgfpointadd{\pgfpointorigin}{
20 \pgfpointpolar{\pgfdecorationsegmentangle}{
21 +\pgfdecorationsegmentamplitude}}}
22 \pgf@xa=\pgf@x
23 \pgf@ya=\pgf@y
24 \message{^^J\the\pgf@x,\the\pgf@y}
25 \pgfpointadd{\pgfpointorigin}{
26 \pgfpointpolar{-\pgfdecorationsegmentangle}{
27 \pgfdecorationsegmentamplitude}}
28 \pgfpointtransformed{\pgfpoint{\pgf@x}{\pgf@y}}%
29 \message{^^J\the\pgf@x,\the\pgf@y}
30 \xdef\outlinerev{\the\pgf@x/\the\pgf@y,\outlinerev}
31 \pgf@x=\pgf@xa
32 \pgf@y=\pgf@ya
33 }%
34 \state{final}
35 {
36 \pgfpathlineto{\pgfpointdecoratedpathlast}
37 \foreach \x/\y in \outlinerev{
38 \ifx\x\empty\else
39 \ifx\y\empty\else
40 \pgf@xa=\x
41 \pgf@ya=\y
42 \pgf@nlt@lineto{\pgf@xa}{\pgf@ya}
43 \fi
44 \fi
45 }
46 }%
47 }%
48 % \end{macrocode}
49 %
50 % A decoration to make a fortification line
51 %
52 % \begin{macrocode}
53 \pgfdeclaredecoration{fortification}{initial}
54 {
55 \state{initial}[width=4\pgflinewidth]
56 {
57 \pgfpathlineto{\pgfpoint{2\pgflinewidth}{0}}
58 \pgfpathlineto{\pgfpoint{2\pgflinewidth}{2\pgflinewidth}}
59 \pgfpathlineto{\pgfpoint{4\pgflinewidth}{2\pgflinewidth}}
60 \pgfpathlineto{\pgfpoint{4\pgflinewidth}{0}}
61 }
62 \state{final}
63 {
64 \pgfpathlineto{\pgfpointdecoratedpathlast}
65 }
66 }
67 % \end{macrocode}
68 %
69 % Roads, railroads, rivers, borders.
70 %
71 % \begin{macrocode}
72 \tikzset{
73 hex/road/.style={
74 rounded corners=3\pgflinewidth,% .25cm,
75 color=black,
76 transform shape,
77 scale line widths,
78 thick,
79 every hex road/.try,
80 },
81 hex/railroad/.style={
82 %scale line widths,
83 rounded corners=.25cm,
84 color=gray!50!black,
85 transform shape,
86 every hex railroad/.try,
87 postaction={draw,decorate},
88 decoration={ticks,
89 segment length=9\pgflinewidth,
90 amplitude=3\pgflinewidth,%.1cm
91 }
92 },
93 hex/river/.style={
94 color=blue,
95 scale line widths,
96 scale rounded corners,
97 line width=3pt,
98 transform shape,
99 every hex river/.try,
100 decorate,
101 decoration={random steps,
102 segment length=3\pgflinewidth,
103 amplitude=1.5\pgflinewidth,
104 pre=lineto,
105 post=lineto,
106 pre length=.5\pgflinewidth,
107 post length=.5\pgflinewidth},
108 rounded corners=.75\pgflinewidth},
109 hex/border/.style={
110 color=gray,
111 dashed,
112 transform shape,
113 scale line widths,
114 very thick,
115 rounded corners=3\pgflinewidth,
116 every hex border/.try
117 },
118 %
119 % Fortification line
120 %
121 hex/fortified line/.style={
122 draw=brown!50!black,
123 scale line widths,
124 line width=2pt,
125 every hex fortification line/.try,
126 decoration={fortification,raise=-2\pgflinewidth},
127 decorate},
128 % every river/.style={},
129 % every road/.style={},
130 % every railroad/.style={},
131 % every border/.style={},
132 }
133 % \end{macrocode}
134 %
135 % \begin{Macro}{\road,\railroad,\river,\border}
136 %
137 % \begin{macrocode}
138 \def\road{%
139 %\hex@dbg{3}{Road}
140 \@ifnextchar[{\road@}{\road@[]}%]
141 }
142 \def\road@[#1]{\draw[hex/road,every hex road/.try,#1]}
143 \def\railroad{%
144 %\hex@dbg{3}{Rail road}
145 \@ifnextchar[{\railroad@}{\railroad@[]}%]
146 }
147 \def\railroad@[#1]{\draw[hex/railroad,every hex railroad/.try,#1]}
148 \def\river{%
149 %\hex@dbg{3}{River}
150 \@ifnextchar[{\river@}{\river@[]}%]
151 }
152 \def\river@[#1]{\draw[hex/river,#1]}
153 \def\border{%
154 \hex@dbg{3}{Border}
155 \@ifnextchar[{\border@}{\border@[]}%]
156 }
157 \def\border@[#1]{\draw[hex/border,every hex border/.try,#1]}
158 \def\fortifiedline{%
159 \@ifnextchar[{\fortifiedline@}{\fortifiedline@[]}%]
160 }%
161 \def\fortifiedline@[#1]{%
162 \draw[hex/fortified line,every hex fortified line/.try,#1]}
163 % \end{macrocode}
164 % \end{Macro}
165 %
166 %
167 % \iffalse
168 % --------------------------------------------------------------------
169 % \fi
170 %
171 % \subsubsection{Other paths}
172 %
173 % \begin{Macro}{\shiftScalePath}
174 % Shifts and scales a path and defines a macro to contain the path
175 %
176 % \begin{Syntax}
177 % \cs{shiftScalePath}\marg{macro}\marg{relative-coordinates}
178 % \end{Syntax}
179 %
180 % where \meta{relative-coordinates} is a comma separated list of
181 % relative coordinates (to the lower-left and upper-right corners)
182 %
183 % \begin{Syntax}
184 % \meta{x}/\meta{y}
185 % \end{Syntax}
186 %
187 % Note, this requires that \cs{boardXmin},\cs{boardYmin} and
188 % \cs{boardXmax},\cs{boardYmax} is defined. This can be done using
189 % the \cs{boardframe} macro.
190 %
191 % \begin{macrocode}
192 \def\shiftScalePath#1#2{%
193 \let\tmp@path\@undefined%
194 \foreach \x/\y in {#2}{%
195 \pgfmathparse{\x*\boardW+\boardXmin}\xdef\tmp@x{\pgfmathresult}%
196 \pgfmathparse{\y*\boardH+\boardYmin}\xdef\tmp@y{\pgfmathresult}%
197 \@ifundefined{tmp@path}{\def\tmp@path{}}{\xdef\tmp@path{\tmp@path--}}%
198 \xdef\tmp@path{\tmp@path(\tmp@x,\tmp@y)}}%
199 \expandafter\xdef\csname #1\endcsname{\tmp@path}}
200 % \end{macrocode}
201 % \end{Macro}
202 %
203 % \iffalse
204 % --------------------------------------------------------------------
205 % \fi
206 %
207 % \subsubsection{Move, attacks, retreats from hex to hex}
208 %
209 % \begin{Macro}{\hex@getscale}
210 %
211 % Get current scaling factor.
212 %
213 % \begin{macrocode}
214 \def\hex@getscale#1{%
215 \begingroup
216 \pgfgettransformentries{%
217 \scaleA}{%
218 \scaleB}{%
219 \scaleC}{%
220 \scaleD}{%
221 \whatevs}{%
222 \whatevs}%
223 \pgfmathsetmacro{#1}{sqrt(abs(\scaleA*\scaleD-\scaleB*\scaleC))}%
224 \expandafter
225 \endgroup
226 \expandafter\def\expandafter#1\expandafter{#1}%
227 }
228 % \end{macrocode}
229 % \end{Macro}
230 %
231 % Key to get the scale
232 %
233 % \begin{macrocode}
234 \tikzset{%
235 hex/get scale/.code={
236 \hex@getscale{\hex@scale}},
237 }
238 % \end{macrocode}
239 %
240 % Style for moves. Use like
241 %
242 % \begin{Syntax}
243 % \cs{path}[move] \meta{coordinates};
244 % \end{Syntax}
245 %
246 % \begin{macrocode}
247 \tikzset{%
248 % Argument is colour
249 hex/move/.style={
250 hex/get scale,
251 decorate,
252 decoration={
253 markings,
254 mark=between positions 0 and 1 step 0.75*\hex@scale*\hex@dy with {
255 \node [single arrow,
256 single arrow head extend=.1*\hex@scale*\hex@dy,
257 fill=#1,
258 inner sep=0.05*\hex@scale*\hex@dy,
259 minimum width=0.02*\hex@scale*\hex@dy,
260 minimum height=\hex@scale*\hex@dy/2,
261 transform shape]{};
262 }
263 },
264 },
265 % \end{macrocode}
266 %
267 % A short move style
268 %
269 % \begin{Syntax}
270 % \cs{path}[short move] \meta{coordinates};
271 % \end{Syntax}
272 %
273 %
274 % \begin{macrocode}
275 % Argument is colour
276 hex/short move/.style={
277 hex/get scale,
278 decorate,
279 decoration={
280 markings,
281 mark=between positions 0 and 1 step 0.5*\hex@scale*\hex@dy with {
282 \node [single arrow,
283 single arrow head extend=.1*\hex@scale*\hex@dy,
284 fill=#1,
285 inner sep=0.05*\hex@scale*\hex@dy,
286 minimum width=0.02*\hex@scale*\hex@dy,
287 minimum height=\hex@scale*\hex@dy/3,
288 transform shape]{};
289 }
290 },
291 },
292 % \end{macrocode}
293 %
294 % A short move style
295 %
296 % \begin{Syntax}
297 % \cs{path}[long move] \meta{coordinates};
298 % \end{Syntax}
299 %
300 %
301 % \begin{macrocode}
302 % Argument is colour
303 hex/long move/.style={
304 hex/get scale,
305 transform shape,
306 decorate,
307 decoration={
308 markings,
309 mark=between positions 0 and -.7*\hex@scale*\hex@dy
310 step 2*\hex@scale*\hex@dy with {
311 \node [single arrow,
312 single arrow head extend=3pt,
313 fill=#1,
314 anchor=west,
315 inner sep=\hex@scale*.25mm,
316 outer sep=.3*\hex@scale*\hex@dy,
317 minimum width=0.02*\hex@scale*\hex@dy,
318 minimum height=1.4*\hex@scale*\hex@dy,
319 transform shape]{};
320 }
321 },
322 },
323 % \end{macrocode}
324 %
325 % A short move style
326 %
327 % \begin{Syntax}
328 % \cs{path}[move with start] \meta{coordinates};
329 % \end{Syntax}
330 %
331 %
332 % \begin{macrocode}
333 % Argument is colour
334 hex/move with start/.style={
335 hex/get scale,
336 decorate,
337 decoration={
338 markings,
339 mark=at position 0 with {
340 \node [inner sep=0,
341 circle,
342 minimum size=\hex@scale*5mm,
343 fill=#1,
344 transform shape] {};},
345 mark=between positions 0 and 1 step 0.75*\hex@scale*\hex@dy with {
346 \node [single arrow,
347 single arrow head extend=.1*\hex@scale*\hex@dy,
348 fill=#1,
349 inner sep=0.05*\hex@scale*\hex@dy,
350 minimum width=0.02*\hex@scale*\hex@dy,
351 minimum height=\hex@scale*\hex@dy/2,
352 transform shape]{};
353 }
354 },
355 },
356 % Default fill colour is black
357 hex/move/.default=black,
358 hex/move with start/.default=black,
359 hex/short move/.default=black,
360 hex/long move/.default=black,
361 % Arguments are draw and fill color
362 % \end{macrocode}
363 %
364 % A move cost style
365 %
366 % \begin{Syntax}
367 % \cs{path}[move] ...(coordinate)node[hex/move cost]{} ...;
368 % \end{Syntax}
369 %
370 % \begin{macrocode}
371 hex/move cost/.style 2 args={
372 minimum size=1mm,
373 inner sep=0.1mm,
374 circle,
375 fill=#2,
376 transform shape,
377 text=#1,
378 font=\sffamily\bfseries\fontsize{14.4}{17}\selectfont},
379 hex/move cost/.default={black}{none},
380 % Argument is fill colour
381 % \end{macrocode}
382 %
383 % A short line style for retreates, advances, and so on
384 %
385 % \begin{Syntax}
386 % \cs{path}[short line] (start)--(end);
387 % \end{Syntax}
388 %
389 % \begin{macrocode}
390 hex/short line/.style={%
391 hex/get scale,
392 inherit options/.code={\csname tikz@options\endcsname},
393 inherit options,
394 decorate,
395 decoration={
396 markings,
397 mark=between positions \hex@scale*\hex@dy
398 and 1 step 2*\hex@scale*\hex@dy with {
399 \node [single arrow,draw=black,fill=#1,
400 single arrow head extend=\hex@scale*3pt,
401 inner sep=1mm,
402 minimum width=0.75*\hex@scale*\hex@dy,
403 minimum height=\hex@scale*\hex@dy,
404 transform shape]{};
405 }
406 },
407 },
408 % \end{macrocode}
409 %
410 % An attack indication style
411 %
412 % \begin{Syntax}
413 % \cs{path}[attack] (start)--(end);
414 % \end{Syntax}
415 %
416 % \begin{macrocode}
417 % Argument is fill color
418 hex/attack/.style={
419 hex/get scale,
420 inherit options/.code={\csname tikz@options\endcsname},
421 inherit options,
422 decorate,
423 decoration={
424 markings,
425 mark=between positions \hex@scale*\hex@dy
426 and 1 step 2*\hex@scale*\hex@dy with {
427 \node [regular polygon,
428 fill=#1,
429 draw=#1,
430 regular polygon sides=3,
431 inner sep=0,
432 minimum size=0.75*\hex@scale*\hex@dy,
433 rotate=-90,
434 transform shape]{};
435 }
436 },
437 },
438 % \end{macrocode}
439 %
440 % Short hands
441 %
442 % \begin{Syntax}
443 % \cs{path}[attack] (start)--(end);
444 % \end{Syntax}
445 %
446 % \begin{macrocode}
447 % Default colour is red for attachs
448 hex/attack/.default=red!70!black,
449 %%
450 hex/retreat/.style={hex/short line=#1},
451 hex/retreat/.default=white,
452 %%
453 hex/advance/.style={hex/short line=#1},
454 hex/advance/.default={green!70!black},
455 }
456 % \end{macrocode}
457 % \iffalse
458 %</hex>
459 % --------------------------------------------------------------------
460 % \fi