| 1 |
% \section{VASSAL module} |
| 2 |
% \label{sec:vassal} |
| 3 |
% |
| 4 |
% As already mentioned several times in this tutorial, we can use the |
| 5 |
% definitions of maps, counters, and charts to generate a VASSAL |
| 6 |
% module. |
| 7 |
% |
| 8 |
% \begin{quote} |
| 9 |
% VASSAL\footnote{\url{https://vassalengine.org}} is a |
| 10 |
% cross-platform\footnote{It is written in Java, meaning it runs |
| 11 |
% almost everywhere, except on iOS and Android} tool for playing |
| 12 |
% wargames against other humans or solitaire. One can do |
| 13 |
% Play-By-E-Mail (PBEM) or online. |
| 14 |
% \end{quote} |
| 15 |
% |
| 16 |
% The trick is to prepare a separate \LaTeX{} document, say |
| 17 |
% \texttt{export.tex} as in this tutorial, which exports the images as |
| 18 |
% single pages. Then, the Python script \texttt{wgexport.py} |
| 19 |
% distributed with the \textsf{wargame} package picks up this output |
| 20 |
% (\texttt{export.pdf} and \texttt{export.json}) and generates a draft |
| 21 |
% VASSAL module. |
| 22 |
% |
| 23 |
% In addition, you can supply a Python script, say \texttt{patch.py}, |
| 24 |
% which will be run on the draft module so that you fix things up in |
| 25 |
% the VASSAL module. In this way, your VASSAL module will likely need |
| 26 |
% very little hand editing (if at all), and will be robust against |
| 27 |
% changes in the \LaTeX{} code\footnote{Assuming you keep your Python |
| 28 |
% \texttt{patch.py} script up to date.}. This of course requires a |
| 29 |
% bit of familiarity with Python, which is time well spent. |
| 30 |
% |
| 31 |
% Let us get into it. |
| 32 |
% |
| 33 |
% \subsection{The \texttt{export.tex} file}. |
| 34 |
% \label{sec:export:tex} |
| 35 |
% |
| 36 |
% This file will output all the images to a PDF, |
| 37 |
% \meta{export}\texttt{.pdf} along with meta information to a |
| 38 |
% JSON\footnote{JavaScript Object Notation} file |
| 39 |
% \meta{export}\texttt{.json}. This is relatively simple to do. |
| 40 |
% |
| 41 |
% We need to use the document class \texttt{wgexport}, so lets go a |
| 42 |
% head and load that. |
| 43 |
% |
| 44 |
% \begin{macrocode} |
| 45 |
\documentclass[11pt]{wgexport} |
| 46 |
% \end{macrocode} |
| 47 |
% |
| 48 |
% Make sure you give the right font size as argument. |
| 49 |
% |
| 50 |
% This is where it pays off that we put all our definitions of |
| 51 |
% counters, board, charts, etc. into a separate package. To import |
| 52 |
% these, we simply use that package here\footnote{If we hadn't made |
| 53 |
% that package, we would have to repeat the definitions in some |
| 54 |
% way. Very error prone}. So we load the package and start our |
| 55 |
% document. |
| 56 |
% |
| 57 |
% \begin{macrocode} |
| 58 |
\usepackage{game} |
| 59 |
\begin{document} |
| 60 |
% \end{macrocode} |
| 61 |
% |
| 62 |
% Now the body of the document will simply consist of a list of |
| 63 |
% images, one for each side of each counter, the board, charts, and so |
| 64 |
% on. We need to put everything into the environment |
| 65 |
% \texttt{imagelist} which will keep track of our meta data. |
| 66 |
% |
| 67 |
% \begin{macrocode} |
| 68 |
\begin{imagelist} |
| 69 |
% \end{macrocode} |
| 70 |
% |
| 71 |
% So far so good. The first thing we will output are the counters. |
| 72 |
% For that we will use the macro \verb+\doublechitimages+ (if we had |
| 73 |
% single sided counters, we would use \verb+\chitimages+). This macro |
| 74 |
% takes two arguments: The list of counter definitions and the faction |
| 75 |
% of the chits. Let's go ahead and make those for factions A and B, |
| 76 |
% and the special faction ``Markers'' which will only be the game turn |
| 77 |
% counter. |
| 78 |
% |
| 79 |
% \begin{macrocode} |
| 80 |
\doublechitimages[A][chit drop shadows]{\alla} |
| 81 |
\doublechitimages[B][chit drop shadows]{\allb} |
| 82 |
\doublechitimages[Markers][chit drop shadows]{{game turn chit}} |
| 83 |
% \end{macrocode} |
| 84 |
% |
| 85 |
% Again, the macros we made for the counters comes in handy. Note |
| 86 |
% that we have used it twice so far: For the OOBs and here for the |
| 87 |
% VASSAL module. We will, in fact, use them one more time to create |
| 88 |
% the counter sheet. |
| 89 |
% |
| 90 |
% To automatically make ``battle markers'' --- markers that identify |
| 91 |
% individual battles by placing a numbered marker on top of the |
| 92 |
% combatants, we can use the macro \verb+battlemarkers+. It takes one |
| 93 |
% argument, which is the number of unique markers to make and add. |
| 94 |
% The markers are round yellow circles with a number in |
| 95 |
% them\footnote{This can of course be customised as everything else |
| 96 |
% can.}. |
| 97 |
% |
| 98 |
% \begin{macrocode} |
| 99 |
\tikzset{} |
| 100 |
\battlemarkers[marker drop shadows]{12} |
| 101 |
\tikzset{every battle marker/.style={}} |
| 102 |
% \end{macrocode} |
| 103 |
% |
| 104 |
% Furthermore, we can add ``odds'' and battle result markers. Odds |
| 105 |
% markers can be placed via the battle markers context menu, and then |
| 106 |
% later be replaced by result markers via the context menu of the odds |
| 107 |
% markers. This is done via the macros \verb+\oddsmarkers+ and |
| 108 |
% \verb+\resultmarkers+. Both macros accept a list of options (odds |
| 109 |
% and results, respectively) with a possible background colour to use |
| 110 |
% in the markers. |
| 111 |
% |
| 112 |
% \begin{macrocode} |
| 113 |
\oddsmarkers[marker drop shadows]{% |
| 114 |
1:3/red!25!white,% |
| 115 |
1:2/red!15!white,% |
| 116 |
1:1/orange!15!white,% |
| 117 |
2:1/white,% |
| 118 |
3:1/green!15!white,% |
| 119 |
4:1/green!25!white} |
| 120 |
\resultmarkers[marker drop shadows]{ |
| 121 |
AE/red!50!white, |
| 122 |
AR/red!25!white, |
| 123 |
EX/white, |
| 124 |
DR/green!10!white, |
| 125 |
DE/green!25!white} |
| 126 |
% \end{macrocode} |
| 127 |
% |
| 128 |
% By default, odds markers must be placed ``by-hand'', but via the |
| 129 |
% VASSAL preferences it is possible to calculate the odds and show |
| 130 |
% them when the battle is declared. By default, this calculation will |
| 131 |
% only be concerned with the combat factors of the involved units, and |
| 132 |
% features such as terrain is ignored. However, with a bit of Python |
| 133 |
% skill, one can flesh out the implementation of the game rules in the |
| 134 |
% optional patch (Python) script. We will not do that here, as a it |
| 135 |
% is a little beyond the scope of this tutorial. |
| 136 |
% |
| 137 |
% Right, so that made our counter images and the associated meta |
| 138 |
% data. Next thing is to add our board. For that, we use the |
| 139 |
% environment \texttt{boardimage}. Inside that environment we must |
| 140 |
% draw the board. The environment takes one optional argument which |
| 141 |
% classifies the board. Meaningful classifications are \texttt{board} |
| 142 |
% (default) and \texttt{oob} for OOBs. The first mandatory argument |
| 143 |
% is the name of the board (more or less free form text, except any of |
| 144 |
% ``\texttt{./\textbackslash '"}'' should not be used. The second |
| 145 |
% mandatory argument is a sub-category, and is mainly reserved for |
| 146 |
% future use. |
| 147 |
% |
| 148 |
% \begin{macrocode} |
| 149 |
\begin{boardimage}{Board}{} |
| 150 |
\begin{board} |
| 151 |
\end{board} |
| 152 |
\end{boardimage} |
| 153 |
% \end{macrocode} |
| 154 |
% |
| 155 |
% We will make another board image for our OOB, since that component |
| 156 |
% should hold counters in VASSAL. We pass the optional argument |
| 157 |
% \texttt{oob} in this case. |
| 158 |
% |
| 159 |
% \begin{macrocode} |
| 160 |
\begin{boardimage}[oob]{OOB}{}% |
| 161 |
\fulloob |
| 162 |
\end{boardimage} |
| 163 |
% \end{macrocode} |
| 164 |
% |
| 165 |
% We have two charts that we would also like to be put in: The CRT and |
| 166 |
% the TEC. These \emph{must} be put into \Tikz{} pictures, and we |
| 167 |
% precede those with the macro \verb+\info+. This macro takes three |
| 168 |
% arguments: The name of the next image, the category, and |
| 169 |
% sub-category. Again, the name is more or less free form, and the |
| 170 |
% category in some sense dictates how it will present in the VASSAL |
| 171 |
% module. For charts we should use the category \texttt{chart}. The |
| 172 |
% sub-category isn't really used at this point. |
| 173 |
% |
| 174 |
% \begin{macrocode} |
| 175 |
\info{CRT}{chart}{} |
| 176 |
\begin{tikzpicture} |
| 177 |
\node{\crt}; |
| 178 |
\end{tikzpicture} |
| 179 |
% |
| 180 |
\info{TEC}{chart}{} |
| 181 |
\begin{tikzpicture} |
| 182 |
\node{\tec}; |
| 183 |
\end{tikzpicture} |
| 184 |
% \end{macrocode} |
| 185 |
% |
| 186 |
% We also want background images for our pools of eliminated units in |
| 187 |
% VASSAL. This will be enlarged version of main headquarter unit of |
| 188 |
% each faction, overlayed with a white semi-transparent background. |
| 189 |
% |
| 190 |
% \begin{macrocode} |
| 191 |
\info{A}{pool}{} |
| 192 |
\begin{tikzpicture}[scale=7] |
| 193 |
\chit[a hq]; |
| 194 |
\fill[white,opacity=.5](-.6,-.6)rectangle++(1.2,1.2); |
| 195 |
\end{tikzpicture} |
| 196 |
\info{B}{pool}{} |
| 197 |
\begin{tikzpicture}[scale=7] |
| 198 |
\chit[b hq]; |
| 199 |
\fill[white,opacity=.5](-.6,-.6)rectangle++(1.2,1.2); |
| 200 |
\end{tikzpicture} |
| 201 |
% \end{macrocode} |
| 202 |
% |
| 203 |
% We can add splash page image. We have not defined such an image in |
| 204 |
% the \texttt{game} package, but we could have, so we will make it |
| 205 |
% here. Again, it should be a \Tikz{} picture. For this, we need to |
| 206 |
% use the category \texttt{front}. |
| 207 |
% |
| 208 |
% \begin{macrocode} |
| 209 |
\info{Splash}{front}{} |
| 210 |
\begin{tikzpicture} |
| 211 |
\node[board frame,title, |
| 212 |
minimum width=5cm,minimum height=5cm] |
| 213 |
{A Game}; |
| 214 |
\end{tikzpicture} |
| 215 |
% \end{macrocode} |
| 216 |
% |
| 217 |
% We could continue to add more if we wanted to. Basically anything |
| 218 |
% can be added. For example, one might want custom button icons or |
| 219 |
% the like. We will add a few such icons here, mainly to show how |
| 220 |
% the \texttt{patch.py} script works. |
| 221 |
% |
| 222 |
% The \textsf{wgexport.cls} class provides a number of icons we may |
| 223 |
% use for this. These are |
| 224 |
% |
| 225 |
% \begin{center} |
| 226 |
% \begin{tikzpicture} |
| 227 |
% \pic {flip icon}; |
| 228 |
% \pic at (2.0,0) {restore icon}; |
| 229 |
% \pic at (3.5,0) {eliminate icon}; |
| 230 |
% \pic at (5.0,0) {pool icon}; |
| 231 |
% \pic at (6.5,0) {oob icon={black}{black}}; |
| 232 |
% \end{tikzpicture} |
| 233 |
% \end{center} |
| 234 |
% |
| 235 |
% |
| 236 |
% We will add these as pictures to our export PDF. First, the image |
| 237 |
% for the pool of units. |
| 238 |
% |
| 239 |
% \begin{macrocode} |
| 240 |
\info{pool-icon}{icon}{} |
| 241 |
\begin{tikzpicture}[transform shape,scale=.4] |
| 242 |
\pic{pool icon}; |
| 243 |
\end{tikzpicture} |
| 244 |
% \end{macrocode} |
| 245 |
% |
| 246 |
% The category \texttt{icon} has no special meaning. |
| 247 |
% |
| 248 |
% We also want to add a custom icon for the OOB button. VASSAL has a |
| 249 |
% button icon for the piece inventory which is really quite |
| 250 |
% appropriate, but alas it is already in use, so we will make our |
| 251 |
% own. Here, we use the \TikZ{} picture \texttt{oob icon} provided by |
| 252 |
% \textsf{wgexport}. This picture needs two arguments: the left hand |
| 253 |
% and right hand sides fill colours. We will use our background |
| 254 |
% colours. |
| 255 |
% |
| 256 |
% \begin{macrocode} |
| 257 |
\info{oob-icon}{icon}{} |
| 258 |
\begin{tikzpicture}[transform shape,scale=.4] |
| 259 |
\pic{oob icon={a-bg}{b-bg}}; |
| 260 |
\end{tikzpicture} |
| 261 |
% \end{macrocode} |
| 262 |
% |
| 263 |
% Normally the \texttt{wgexport.py} script uses the \emph{undo} image |
| 264 |
% for the flip button. However, that may be a bit confusing, so we |
| 265 |
% will use a custom image for that. We will use the pictures provided |
| 266 |
% by \textsf{wgexport}. |
| 267 |
% |
| 268 |
% |
| 269 |
% \begin{macrocode} |
| 270 |
\info{flip-icon}{icon}{} |
| 271 |
\begin{tikzpicture}[transform shape,scale=.4] |
| 272 |
\pic{flip icon}; |
| 273 |
\end{tikzpicture} |
| 274 |
% |
| 275 |
\info{eliminate-icon}{icon}{} |
| 276 |
\begin{tikzpicture}[transform shape,scale=.4] |
| 277 |
\pic{eliminate icon}; |
| 278 |
\end{tikzpicture} |
| 279 |
% |
| 280 |
\info{restore-icon}{icon}{} |
| 281 |
\begin{tikzpicture}[transform shape,scale=.4] |
| 282 |
\pic{restore icon}; |
| 283 |
\end{tikzpicture} |
| 284 |
% \end{macrocode} |
| 285 |
% |
| 286 |
% \begin{macrocode} |
| 287 |
\end{imagelist} |
| 288 |
\end{document} |
| 289 |
% \end{macrocode} |
| 290 |
% |
| 291 |
% \subsection{Make the draft module} |
| 292 |
% |
| 293 |
% We run \LaTeX{} on the above \texttt{export.tex} file (the source of |
| 294 |
% this section) to generate \texttt{export.pdf} and |
| 295 |
% \texttt{export.json}. We then process these with the |
| 296 |
% \texttt{wgexport.py} Python script to get the draft VASSAL module |
| 297 |
% \texttt{Draft.vmod}. |
| 298 |
% |
| 299 |
% \begin{verbatim} |
| 300 |
% `kpsewhich wgexport.py` export.pdf export.json |
| 301 |
% \end{verbatim} |
| 302 |
% |
| 303 |
% The utility \texttt{kpsewhich}\footnotemark{\TeX{}Live and similar |
| 304 |
% \TeX{} distributions.} will report the location of a file in the |
| 305 |
% \TeX{} installation tree(s). Note that the \texttt{`} above are |
| 306 |
% what is typically called `back-ticks' (i.e., what you typically put |
| 307 |
% as the leading character of scare-crows in \LaTeX{}). This is of |
| 308 |
% course Un*x-like syntax. For other OSs, consult your \TeX{} |
| 309 |
% distribution's documentation for how to find files in the \TeX{} |
| 310 |
% installation. |
| 311 |
% |
| 312 |
% You can open the module in the VASSAL editor and see what was |
| 313 |
% generated. On the board, all areas marked with the \texttt{zone |
| 314 |
% scope} (or \texttt{zone path}) should be defined as zones. In the |
| 315 |
% OOB, we should have two zones, one for the A faction and one for the |
| 316 |
% B faction. We should also have three groups of counters --- one |
| 317 |
% for each faction and one for ``Markers''. Finally, we should have a |
| 318 |
% window with tabs, one for each defined chart. |
| 319 |
% |
| 320 |
% We can add the rules to the module. So suppose the rules are in |
| 321 |
% \texttt{game.pdf}, then we can do |
| 322 |
% |
| 323 |
% \begin{verbatim} |
| 324 |
% `kpsewhich wgexport.py` export.pdf export.json \ |
| 325 |
% -r game.pdf -o Game.vmod |
| 326 |
% \end{verbatim} |
| 327 |
% |
| 328 |
% to add the rules to the ``Help'' menu. Other information is added |
| 329 |
% to that menu too, such as key-bindings and a short note on how the |
| 330 |
% module was generated. Of course, you should also see the splash |
| 331 |
% image that we defined. The option \texttt{-o}~\meta{filename} |
| 332 |
% writes the module to \meta{filename} rather than the default |
| 333 |
% \texttt{Draft.vmod}. |
| 334 |
% |
| 335 |
% We define the version of the module by passing the option |
| 336 |
% \texttt{-v}~\meta{version} to the Python script. By default, the |
| 337 |
% version is set to \texttt{draft}, and a note on the draft is added |
| 338 |
% to the module and the grids are drawn. Any other version string |
| 339 |
% will suppress these. |
| 340 |
% |
| 341 |
% Also, the default module name is \texttt{Draft} and a similar |
| 342 |
% description is likewise the default. We can change this by passing |
| 343 |
% the options \texttt{-t}~\meta{title} and |
| 344 |
% \texttt{-d}~\meta{description}. Note, you may want to quote the |
| 345 |
% arguments if they contain spaces or the like. Thus, to make a more |
| 346 |
% complete module, we would do something like |
| 347 |
% |
| 348 |
% \begin{verbatim} |
| 349 |
% `kpsewhich wgexport.py` export.pdf export.json \ |
| 350 |
% -r game.pdf -o Game.vmod \ |
| 351 |
% -t "LaTeX Wargame tutorial" \ |
| 352 |
% -d "Example of using wargame to make a module" \ |
| 353 |
% -v 0.1 |
| 354 |
% \end{verbatim} |
| 355 |
% |
| 356 |
% Note that you typically need to quote (\texttt{"}) longer strings |
| 357 |
% that contain spaces and other special characters. |
| 358 |
% |
| 359 |
% \subsection{Going the extra mile} |
| 360 |
% \label{sec:vassal:patch} |
| 361 |
% |
| 362 |
% We will take one more step on the VASSAL module, and then we will |
| 363 |
% get back to the Print'n'Play version of the game. We can provide |
| 364 |
% the \texttt{wgexport.py} script with an additional Python script that |
| 365 |
% can tweak the VASSAL module any way we like. We can for example |
| 366 |
% move counters into their starting positions, to the OOB, adjust |
| 367 |
% grids, add more materials, and so on. It is only your imagination, |
| 368 |
% and Python programming skills, that sets the limits on what you can |
| 369 |
% do. |
| 370 |
% |
| 371 |
% Here we will make a simple \texttt{patch.py} Python script which |
| 372 |
% does very little. The \textsf{wargame} package, |
| 373 |
% \textsf{wgexport} class, and \texttt{wgexport.py} script has already |
| 374 |
% done the heavy work for us. Not least be because we have taken care |
| 375 |
% to add in \texttt{zone} styles where needed. |
| 376 |
% |
| 377 |
% We will put all the counters on the OOB chart, and adjust some grids |
| 378 |
% - most notably the OOB and turn track grids. Other than that, we |
| 379 |
% will not do much. |
| 380 |
% |
| 381 |
% \begin{verbatim} |
| 382 |
% `kpsewhich wgexport.py` export.pdf export.json \ |
| 383 |
% -r game.pdf -o Game.vmod |
| 384 |
% -t "LaTeX Wargame tutorial" \ |
| 385 |
% -d "Example of using wargame to make a module" \ |
| 386 |
% -v 0.1 -p patch.py |
| 387 |
% \end{verbatim} |
| 388 |
% |
| 389 |
% Now for the script: |
| 390 |
% |
| 391 |
% \begin{verbatim} |
| 392 |
% # --- We may need to import the export module --- |
| 393 |
% # |
| 394 |
% # from wgexport import * |
| 395 |
% |
| 396 |
% def patch(build,data,vmod,verbose=False,**kwargs): |
| 397 |
% # --- Get the game --- |
| 398 |
% game = build.getGame() |
| 399 |
% |
| 400 |
% # --- Get the maps --- |
| 401 |
% maps = game.getMaps() |
| 402 |
% |
| 403 |
% # --- Get the main board --- |
| 404 |
% board = maps['Board'] |
| 405 |
% |
| 406 |
% # --- Get the mass keys --- |
| 407 |
% mkeys = board.getMassKeys() |
| 408 |
% mkeys['Eliminate']['icon'] = 'eliminiate-icon.png' |
| 409 |
% mkeys['Flip'] ['icon'] = 'flip-icon.png' |
| 410 |
% |
| 411 |
% # --- Get the dead-pool map --- |
| 412 |
% pool = maps['DeadMap'] |
| 413 |
% pool['icon'] = 'pool-icon.png' |
| 414 |
% pool.getMassKeys()['Restore']['icon'] = 'restore-icon.png' |
| 415 |
% |
| 416 |
% # --- Get the OOB map --- |
| 417 |
% oob = game.getChartWindows()['OOBs'] |
| 418 |
% oob['icon'] = 'oob-icon.png' |
| 419 |
% |
| 420 |
% |
| 421 |
% # |
| 422 |
% # EOF |
| 423 |
% # |
| 424 |
% \end{verbatim} |
| 425 |
% |
| 426 |
% In the \texttt{patch.py} script we can use all the functionality |
| 427 |
% provided by \texttt{wgexport.py}. Elements are XML elements that we |
| 428 |
% apply \texttt{xml.dom.minidom} operations on. |
| 429 |
% |
| 430 |
% Note, if we need to use classes, etc.\ from \texttt{wgexport.py}, |
| 431 |
% then we ought to import that module into our patch script, as shown |
| 432 |
% in the top comment above. In the example patch script we do not |
| 433 |
% need that, so we leave it out. |
| 434 |
% |
| 435 |
% One can do quite complicated things in VASSAL, which can be set-up |
| 436 |
% in the patch script. By default, the \texttt{wgexport} script sets |
| 437 |
% up the pieces and boards, and if one has defined regions with |
| 438 |
% specific piece names, then the script will likewise place the pieces |
| 439 |
% there (as with our \texttt{game turn} example above). |
| 440 |
% |
| 441 |
% One can, for example, setup the module so that the game turn marker |
| 442 |
% automatically flips or progresses when the turn track widget reach |
| 443 |
% specific points. One can in principle also set it up so that when a |
| 444 |
% specific turn or phase is reach, then pieces are moved from the OOB |
| 445 |
% to the board. The more one can do like that, the more the game is |
| 446 |
% automated. |
| 447 |
% |
| 448 |
% \iffalse |
| 449 |
% Local Variables: |
| 450 |
% mode: docTeX |
| 451 |
% TeX-master: "game.tex" |
| 452 |
% End: |
| 453 |
% \fi |