The monster environment

LaTeX_logodnd

As I commented, I am working on a Dungeons & Dragons (D&D) \LaTeX class to write small adventures.

Objective

The monster environment should deal with creating the corresponding table and all that it is necessary. A monster has a set of attributes (common to all monsters), and a set of powers different to each monster. In D&D 4e this is typically presented in a table, which I think is the best possible presentation.

Typical d&d 4e monster stats table.

Typical d&d 4e monster stats table.

Stats generated with the LaTeX class

Stats generated with the LaTeX class (There is a small error).

One of my main ideas is to pack a lot of text together, this is bad for good reading, but nice to use less paper. For similar reasons (money), I will only use grayscale.

The dnd class is a double column environment, so the table is defined to fill the whole line width. On a single column document it would look too wide.

Design

I separe the basic and required values for a monster to fight: Defenses, speed, Initiative, Perception… from its attacks, alignments, stats, equipment… The first two sections of the table are almost enough to run a simple monster.

A monster is a table with two columns. I just need commands and environments to define this table.

\begin{tabular}[lr]
% lots of stuff here
\end{tabular}

I decide to use an environment ddmonster defined to start and end a table.

\newenvironment{ddmonster}[1][]
{begin the table here}
{close the table here at the end}

The required arguments will be set when using the environment. Those are HP, defenses, vision, name, level, xp etc..

The attacks, stats, equip and sections are just commands:

  • \ddm{X}Section. Where {X} represents the section
  • \ddmAction{X}. Where {X} represents what acction More on this on another post
  • \ddmStats[8] 6 stats, level and comments
  • \ddmAlignLang[2] Alignment and Language
  • \ddmEquip

I think that with those commands we are ready to create any monster.

Implementing

== The ddmonster environment

The environment requires a list of basic parameters (check xkeyval and the 9 arguments). Then, it starts a table and closes it.

I use some specific \LaTeX libraries for that:

First of all, I define with xkeyval which arguments I want to use and initialize a default value. in github

\define@cmdkey      [DMK] {ddm}     {name}      {}
\define@cmdkey      [DMK] {ddm}     {keywords}  {}
\define@cmdkey      [DMK] {ddm}     {role}      {}
\define@cmdkey      [DMK] {ddm}     {HP}        {}
\define@cmdkey      [DMK] {ddm}     {lvl}       {}
\define@cmdkey      [DMK] {ddm}     {xp}        {}
\define@cmdkey      [DMK] {ddm}     {initiative}{}
\define@cmdkey      [DMK] {ddm}     {perception}{}
\define@cmdkey      [DMK] {ddm}     {AC}        {}
\define@cmdkey      [DMK] {ddm}     {Fort}      {}
\define@cmdkey      [DMK] {ddm}     {Refl}      {}
\define@cmdkey      [DMK] {ddm}     {Will}      {}
\define@cmdkey      [DMK] {ddm}     {speed}     {}
\define@cmdkey      [DMK] {ddm}     {AP}        {}
\define@cmdkey      [DMK] {ddm}     {save}      {}
\define@cmdkey      [DMK] {ddm}     {vision}    {}
\define@cmdkey      [DMK] {ddm}     {immune}    {}
\define@cmdkey      [DMK] {ddm}     {resist}    {}
\define@cmdkey      [DMK] {ddm}     {vulnerable}{}

\define@boolkey     [DMK] {ddm}     {elite}[false]{}
\define@boolkey     [DMK] {ddm}     {solo}[false]{}

\define@boolkey     [DMK] {ddm}     {simmune}[false]{}
\define@boolkey     [DMK] {ddm}     {sresist}[false]{}
\define@boolkey     [DMK] {ddm}     {svulnerable}[false]{}

\presetkeys     [DMK] {ddm} {name         = name undefined,
                             keywords     = keywords ,
                             role         = Brute ,
                             HP           = 1,
                             lvl          = 1,
                             xp           = 1,
                             initiative   = 0,
                             perception   = 0,
                             AC           = 10,
                             Fort         = 10,
                             Refl         = 10,
                             Will         = 10,
                             speed        = 5,
                             AP           = 0,
                             save         = 0,
                             vision       = ,
                             immune       = ,
                             resist       = ,
                             vulnerable   = ,
                                           }{}

Some of those could be defined by a choicekey (the roles are defined by D&D 4e), but I prefer to leave it just as text so I can write whatever I want.

elite and solo are not roles but extras that a monster may have. It can be an elite monster, a solo monster, or a elite solo monster from hell. That is why I decided to use booleans.

[I HATE THIS]
There are 3 more booleans (and more may be added). I had big trouble working with conditionals inside the table. My original idea was that if you don’t define immune, resist or vulnerable the table simply won’t add them.
That proved to be horribly non-intuitive to implement and I could not make it.
That is why there are 3 flags simmune, sresist, svulnerable (s stands for show). By default won’t add anything, if you want to show the immunities of the monster just turn it on.
[/I HATE THIS]

You may have realized that hp has two values (HP and HP/2), but only one parameter. I will calculate the HP/2 directly on \LaTeX with fp.

Having defined the keys, We can define the newenvironment:

\newenvironment{ddmonster}[1][]{
    \setkeys[DMK]{ddm}{#1}

    \begin{scriptsize}
    \begin{tabular}{lr}

    \toprule
    %More stuff coming
}
{
   \bottomrule
   \end{tabular}
   \end{scriptsize}
   \vspace{5pt}
}

The monster is defined with scriptsize font. Less space and perfectly readable.

We can find two types of rows. The two column rows and rows that span two columns. For example, for the name, role and level.

    \rowcolor[gray]{0.8}
    {\small \cmdDMK@ddm@name} & {\small \cmdDMK@ddm@role ,  lvl \cmdDMK@ddm@lvl}\\

Most of the rows are two columns wide. But for example, the immunities may contain a longer list, so I define it as multiple columns.

\multicolumn{2}{p{0.9\linewidth}}{\textbf{Immune} \cmdDMK@ddm@immune}\\

When I multicolumn I am expecting a lot of text. That is why I am setting a maximum width as 0.9\linewidth. If there is a long list or a long sentence it will just wrap it.

For the small calculations I use fp. This is for floating point, but I already used it in the past so I feel comfortable with it

\FPeval{\bloodied}{trunc(\cmdDMK@ddm@HP/2,0)}%
\textbf{HP} {\cmdDMK@ddm@HP}/{\bloodied} %other stuff follows

With FPeval we calculate a value and store it into a macro bloodied. Trunc to 0 to avoid printing decimals.

These are the two only types of lines that I am using. Here follows the full code for defining this environment. You can also check in github, but in github there is also some language conditionals so it’s not as easy to read.

\newenvironment{ddmonster}[1][]{
    \setkeys[DMK]{ddm}{#1}

    \begin{scriptsize}
    \begin{tabular}{lr}

    \toprule

    %First Row contains the Name + role and level
    \rowcolor[gray]{0.8}
    {\small \cmdDMK@ddm@name} & {\small \cmdDMK@ddm@role ,  lvl \cmdDMK@ddm@lvl}\\

    %Second Row contains the keywords, if its Solo or Elite. And the role + xp
    \rowcolor[gray]{0.8}
    \ifDMK@ddm@solo
        \cmdDMK@ddm@keywords & Solo (\cmdDMK@ddm@xp xp) \\
    \else
        \ifDMK@ddm@elite
            \cmdDMK@ddm@keywords & Elite (\cmdDMK@ddm@xp xp) \\
        \else
            \cmdDMK@ddm@keywords & (\cmdDMK@ddm@xp xp)\\
        \fi
    \fi

    %Separe the top definition from the Defenses and HP
    \midrule

    %Row with HP and Initiative
    \FPeval{\bloodied}{trunc(\cmdDMK@ddm@HP/2,0)}%
    \textbf{HP} {\cmdDMK@ddm@HP}/{\bloodied}
    &
    \textbf{Initiative} +{\cmdDMK@ddm@initiative} \\

    %Row with Defenses and Perceptions

    \textbf{AC}     \cmdDMK@ddm@AC,
    \textbf{Fort}   \cmdDMK@ddm@Fort,
    \textbf{Refx}   \cmdDMK@ddm@Refl,
    \textbf{Will}    \cmdDMK@ddm@Will
    &
    \textbf{Perception} +\cmdDMK@ddm@perception \\

    %Row with Speed, Saves and AP
    %TODO! Would like to print AP and Save conditionally

    \textbf{Speed} \cmdDMK@ddm@speed,
    \textbf{Save} +\cmdDMK@ddm@save,
    \textbf{AP} +\cmdDMK@ddm@AP
    &
    vision: \cmdDMK@ddm@vision
    \\

    %Immunities, resistances and vulnerabilities
    \ifDMK@ddm@simmune
        \multicolumn{2}{p{0.9\linewidth}}{\textbf{Immune} \cmdDMK@ddm@immune}\\
    \else
    \fi

    \ifDMK@ddm@sresist
        \multicolumn{2}{p{0.9\linewidth}}{\textbf{Resist} \cmdDMK@ddm@resist}\\
    \else
    \fi

    \ifDMK@ddm@svulnerable
        \multicolumn{2}{p{0.9\linewidth}}{\textbf{Vulnerable} \cmdDMK@ddm@vulnerable}\\
    \else
    \fi

    %HERE FINISHES THE BASIC ROWS. From here the user may use other constructs
    % to fill the monster
    % \ddmStandardSection \ddmExtraSection \ddmAuraSection \ddmAction \ddmReaction
    % \ddmEquip
}
{
    %FINISH MONSTER TABLE
    \bottomrule
    \end{tabular}
    \end{scriptsize}
    \vspace{5pt}
}

The vargouille so far

We are armed to define a monster that does nothing more than flying and recieving hits.

\begin{ddmonster}
    [
        name = Vargouille, role = Controller, lvl=2,
        keywords = small immortal magical beast, xp=125,
        HP=38, initiative=2,
        AC=16, Fort=15, Refl=14, Will=14, perception=7,
        speed=2 (fly 6), vision=Darkvision,
        %resist=10 fire,     sresist=true
        %immune=poison,      simmune=true
        %vulnerable=10 fire, svulnerable=true
        %solo = true, elite = true
        %save=0, AP=0,
    ]
\end{ddmonster}

Monster definition basic

Monster definition basic

To be continued

In this post I explained how to create a new environment ddmonster. This gives DM’s the option to write their monsters in a \LaTeX environment. Or to other people to have a hint on how to create tables :-P.

This is far from done but I think that the post is long enough. I will describe how to finish this in a future post.

References

D&D 4E conversion wikia ⇒GO
LaTeX booktabs ⇒GO
LaTeX colortbl ⇒GO
LaTeX fp ⇒GO
LaTeX xkeyval ⇒GO

Advertisements

3 Comments

Filed under code, documents, tips

3 responses to “The monster environment

  1. Pingback: The monster comes back | Castells

  2. Jack

    This is fabulous! Thank you so much for sharing. I’m going for D&D 5th edition so it’ll need a bit of tweaking before it meets my needs but it’ll be SO much easier than starting the whole thing from scratch!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s