summaryrefslogtreecommitdiff
path: root/macros/luatex/latex/gurps
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
committerNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
commite0c6872cf40896c7be36b11dcc744620f10adf1d (patch)
tree60335e10d2f4354b0674ec22d7b53f0f8abee672 /macros/luatex/latex/gurps
Initial commit
Diffstat (limited to 'macros/luatex/latex/gurps')
-rw-r--r--macros/luatex/latex/gurps/README.md19
-rw-r--r--macros/luatex/latex/gurps/gurps.dtx416
-rw-r--r--macros/luatex/latex/gurps/gurps.lua312
-rw-r--r--macros/luatex/latex/gurps/gurps.pdfbin0 -> 239743 bytes
-rw-r--r--macros/luatex/latex/gurps/gurps_tables.lua112
5 files changed, 859 insertions, 0 deletions
diff --git a/macros/luatex/latex/gurps/README.md b/macros/luatex/latex/gurps/README.md
new file mode 100644
index 0000000000..e3d5897922
--- /dev/null
+++ b/macros/luatex/latex/gurps/README.md
@@ -0,0 +1,19 @@
+| | |
+|-------:|------------------------------------------------------------------
+| gurps:| A LaTeX package for GURPS typesetting |
+| Author:| Nathanael Farley |
+| E-mail:| nasfarley88@gmail.com |
+|License:| Released under the LaTeX Project Public License v1.3c or later |
+| See:| http://www.latex-project.org/lppl.txt |
+
+This package supports typesetting Generic Universal Role Playing System (GURPS) materials. It provides many convenience commands (e.g. `\gurps`, `\SJGamesOnlinePolicy`) as well as limited NPC building capabilities with a character environment.
+
+The package requires the use of LuaLaTeX as several of the internal calculations are in Lua.
+
+----
+
+Disclaimer:
+The material presented here is the original creation of Nathanael Farley, intended for use with the <a href="http://www.sjgames.com/gurps/"><b><i>GURPS</i></b></a> system from <a href="http://www.sjgames.com/">Steve Jackson Games</a>. This material is not official and is not endorsed by Steve Jackson Games.
+
+Notice:
+<a href="http://www.sjgames.com/gurps/"><b><i>GURPS</i></b></a> is a registered trademark of Steve Jackson Games, and is copyrighted by Steve Jackson Games. All rights are reserved by SJ Games. This material is used here in accordance with the SJ Games <a href="http://www.sjgames.com/general/online_policy.html">online policy</a>.
diff --git a/macros/luatex/latex/gurps/gurps.dtx b/macros/luatex/latex/gurps/gurps.dtx
new file mode 100644
index 0000000000..83a77e10c7
--- /dev/null
+++ b/macros/luatex/latex/gurps/gurps.dtx
@@ -0,0 +1,416 @@
+% \iffalse meta-comment
+% vim: textwidth=75
+%<*internal>
+\iffalse
+%</internal>
+%<*readme>
+| | |
+|-------:|------------------------------------------------------------------
+| gurps:| A LaTeX package for GURPS typesetting |
+| Author:| Nathanael Farley |
+| E-mail:| nasfarley88@gmail.com |
+|License:| Released under the LaTeX Project Public License v1.3c or later |
+| See:| http://www.latex-project.org/lppl.txt |
+
+This package supports typesetting Generic Universal Role Playing System (GURPS) materials. It provides many convenience commands (e.g. `\gurps`, `\SJGamesOnlinePolicy`) as well as limited NPC building capabilities with a character environment.
+
+The package requires the use of LuaLaTeX as several of the internal calculations are in Lua.
+
+----
+
+Disclaimer:
+The material presented here is the original creation of Nathanael Farley, intended for use with the <a href="http://www.sjgames.com/gurps/"><b><i>GURPS</i></b></a> system from <a href="http://www.sjgames.com/">Steve Jackson Games</a>. This material is not official and is not endorsed by Steve Jackson Games.
+
+Notice:
+<a href="http://www.sjgames.com/gurps/"><b><i>GURPS</i></b></a> is a registered trademark of Steve Jackson Games, and is copyrighted by Steve Jackson Games. All rights are reserved by SJ Games. This material is used here in accordance with the SJ Games <a href="http://www.sjgames.com/general/online_policy.html">online policy</a>.
+%</readme>
+%<*internal>
+\fi
+\def\nameofplainTeX{plain}
+\ifx\fmtname\nameofplainTeX\else
+ \expandafter\begingroup
+\fi
+%</internal>
+%<*install>
+\input docstrip.tex
+\keepsilent
+\askforoverwritefalse
+\preamble
+-------:| -----------------------------------------------------------------
+ gurps:| A LaTeX package for GURPS typesetting
+ Author:| Nathanael Farley
+ E-mail:| nasfarley88@gmail.com
+License:| Released under the LaTeX Project Public License v1.3c or later
+ See:| http://www.latex-project.org/lppl.txt
+
+\endpreamble
+\postamble
+
+Copyright (C) 2017 by Nathanael Farley <nasfarley88@gmail.com>
+
+This work may be distributed and/or modified under the
+conditions of the LaTeX Project Public License (LPPL), either
+version 1.3c of this license or (at your option) any later
+version. The latest version of this license is in the file:
+
+http://www.latex-project.org/lppl.txt
+
+This work is "maintained" (as per LPPL maintenance status) by
+Nathanael Farley.
+
+This work consists of the file gurps.dtx and a Makefile.
+Running "make" generates the derived files README, gurps.pdf and gurps.sty.
+Running "make inst" installs the files in the user's TeX tree.
+Running "make install" installs the files in the local TeX tree.
+
+\endpostamble
+
+\usedir{tex/latex/gurps}
+\generate{
+ \file{\jobname.sty}{\from{\jobname.dtx}{package}}
+}
+%</install>
+%<install>\endbatchfile
+%<*internal>
+\usedir{source/latex/gurps}
+\generate{
+ \file{\jobname.ins}{\from{\jobname.dtx}{install}}
+}
+\nopreamble\nopostamble
+\usedir{doc/latex/gurps}
+\generate{
+ \file{README.md}{\from{\jobname.dtx}{readme}}
+}
+\ifx\fmtname\nameofplainTeX
+ \expandafter\endbatchfile
+\else
+ \expandafter\endgroup
+\fi
+%</internal>
+% \fi
+%
+% \iffalse
+%<*driver>
+\ProvidesFile{gurps.dtx}
+%</driver>
+%<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
+%<package>\ProvidesPackage{gurps}
+%<*package>
+ [2018/02/14 v0.1.1 A LaTeX package for GURPS typesetting]
+%</package>
+%<*driver>
+\documentclass{ltxdoc}
+\usepackage[a4paper,margin=25mm,left=50mm,nohead]{geometry}
+\usepackage[numbered]{hypdoc}
+\usepackage{\jobname}
+\EnableCrossrefs
+\CodelineIndex
+\RecordChanges
+\begin{document}
+ \DocInput{\jobname.dtx}
+\end{document}
+%</driver>
+% \fi
+%
+% \GetFileInfo{\jobname.dtx}
+% \DoNotIndex{\newcommand,\newenvironment}
+%
+% \title{\textsf{gurps} --- A LaTeX package for GURPS typesetting\thanks{This file
+% describes version \fileversion, last revised \filedate.}
+%}
+%\author{Nathanael Farley\thanks{E-mail: nasfarley88@gmail.com}}
+%\date{Released \filedate}
+%
+%\maketitle
+%
+%\changes{v0.1}{2018/02/13}{First public release}
+%\changes{v0.1.1}{2018/02/14}{Minor changes to CTAN upload}
+%
+% \begin{abstract}
+% \textit{\textbf{GURPS}} is an excellent RPG system. \LaTeX{} is an excellent
+% typesetting system. Together, they make excellent game aids. At least, they
+% can with this package!
+% \end{abstract}
+%
+% \section{Usage}
+%
+% ==== Put descriptive text here. ====
+%
+% \DescribeMacro{\gurps}
+% The SJGames online policy asks that \textbf{\textit{GURPS}} is always bold and
+% italicised, so this command provides the correct
+% formatting.
+%
+% \DescribeEnv{character}
+% Yep. Makes a character
+%
+%\StopEventually{^^A
+% \PrintChanges
+% \PrintIndex
+%}
+%
+% \section{Implementation}
+% Loading required libraries and the lua logic for this class.
+% \begin{macrocode}
+%<*package>
+\RequirePackage{xparse}
+\RequirePackage{xspace}
+\RequirePackage{etex}
+\RequirePackage{luacode}
+
+\RequirePackage{hyperref}
+
+\luadirect{require("gurps.lua")}
+% \end{macrocode}
+% \begin{macro}{\gurps}
+% Steve Jackson Games asks that the name \textbf{\textit{GURPS}} is always in
+% bold and italicised. This macro provides that.
+% \begin{macrocode}
+\NewDocumentCommand{\gurps}{s}{%
+ \IfBooleanTF#1
+ % With star
+ {\href{http://www.sjgames.com/gurps/}{\textbf{\textit{GURPS}}\xspace}}
+ % Without star
+ {\textbf{\textit{GURPS}}\xspace}%
+}
+% \end{macrocode}
+% \end{macro}
+% \begin{macro}{\dice}
+% Notates dice in the \gurps way (e.g. drops the |6| from |d6|) and puts it in %
+% an |\mbox|. First argument number of dice. Second argument is a modifier and
+% optional. E.g.~|\dice{3}[1]|
+% creates \mbox{3d+1}.
+% \begin{macrocode}
+\NewDocumentCommand{\dice}{mO{0}}{%
+ \luadirect{print_dice([[#1]], [[#2]])}%
+}
+% \end{macrocode}
+% \end{macro}
+% \begin{macro}{\SteveJacksonGames}
+% \begin{macrocode}
+\NewDocumentCommand{\SteveJacksonGames}{s}{%
+ \IfBooleanTF#1%
+ % With star
+ {\href{http://www.sjgames.com/}{Steve~Jackson~Games\xspace}}%
+ % Without star
+ {Steve~Jackson~Games\xspace}%
+}
+% \end{macrocode}
+% \end{macro}
+% \begin{macro}{\SJGamesOnlinePolicyDisclaimer}
+% \begin{macrocode}
+\NewDocumentCommand{\SJGamesOnlinePolicyDisclaimer}{}{%
+ The material presented here is my original creation, intended for use with the
+ \gurps* system from \SteveJacksonGames*. This material is not official and is
+ not endorsed by \SteveJacksonGames.
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\SJGamesOnlinePolicyDisclaimer}
+% The disclaimer \emph{almost} as it appears on the online policy. The words
+% `the art' have been removed since by default no art (including logos) are
+% included in \LaTeX{} documents.
+% \begin{macrocode}
+\NewDocumentCommand{\SJGamesOnlinePolicyNotice}{}{%
+ \gurps* is a registered trademark of \SteveJacksonGames, and is copyrighted by
+ \SteveJacksonGames. All rights are reserved by SJ Games. This material is used
+ here in accordance with the SJ Games
+ \href{http://www.sjgames.com/general/online_policy.html}{online policy}.
+}
+% \end{macrocode}
+% \end{macro}
+% \begin{macro}{\SJGamesOnlinePolicyGameAid}
+% This text is required for all game aid's produced for \textbf{\textit{GURPS}} but without an
+% official license. It takes one argument: author name.
+% \begin{macrocode}
+\NewDocumentCommand{\SJGamesOnlinePolicyGameAid}{m}{%
+ \gurps is a trademark of \SteveJacksonGames, and its rules and art are
+ copyrighted by \SteveJacksonGames. All rights are reserved by
+ \SteveJacksonGames. This game aid is the original creation of #1 and
+ is released for free distribution, and not for resale, under the
+ permissions granted in the
+ \href{http://www.sjgames.com/general/online_policy.html}%
+ {\SteveJacksonGames Online Policy}.
+}
+% \end{macrocode}
+% \end{macro}
+
+% \begin{macro}{\ST}
+% Sets the strength of the current character
+% \begin{macrocode}
+\NewDocumentCommand{\ST}{m}{\luadirect{_ARGS.ST = #1}}
+% \end{macrocode}
+% \end{macro}
+
+% \begin{macro}{\DX}
+% Sets the dexterity of the current character
+% \begin{macrocode}
+\NewDocumentCommand{\DX}{m}{\luadirect{_ARGS.DX = #1}}
+% \end{macrocode}
+% \end{macro}
+
+% \begin{macro}{\IQ}
+% Sets the IQ of the current character
+% \begin{macrocode}
+\NewDocumentCommand{\IQ}{m}{\luadirect{_ARGS.IQ = #1}}
+% \end{macrocode}
+% \end{macro}
+
+% \begin{macro}{\HT}
+% Sets the health of the current character
+% \begin{macrocode}
+\NewDocumentCommand{\HT}{m}{\luadirect{_ARGS.HT = #1}}
+% \end{macrocode}
+% \end{macro}
+
+% \begin{macro}{\HP}
+% Sets the HP of the current character
+% \begin{macrocode}
+\NewDocumentCommand{\HP}{m}{\luadirect{_ARGS.HP = #1}}
+% \end{macrocode}
+% \end{macro}
+
+% \begin{macro}{\Per}
+% Sets the perception of the current character
+% \begin{macrocode}
+\NewDocumentCommand{\Per}{m}{\luadirect{_ARGS.Per = #1}}
+% \end{macrocode}
+% \end{macro}
+
+% \begin{macro}{\Will}
+% Sets the will of the current character
+% \begin{macrocode}
+\NewDocumentCommand{\Will}{m}{\luadirect{_ARGS.Will = #1}}
+% \end{macrocode}
+% \end{macro}
+
+% \begin{macro}{\FP}
+% Sets the FP of the current character
+% \begin{macrocode}
+\NewDocumentCommand{\FP}{m}{\luadirect{_ARGS.FP = #1}}
+% \end{macrocode}
+% \end{macro}
+
+% \begin{macro}{\SM}
+% Sets the SM of the current character
+% \begin{macrocode}
+\NewDocumentCommand{\SM}{m}{\luadirect{_ARGS.SM = #1}}
+% \end{macrocode}
+% \end{macro}
+
+% \begin{macro}{\DR}
+% Sets the DR of the current character
+% \begin{macrocode}
+\NewDocumentCommand{\DR}{m}{\luadirect{_ARGS.DR = #1}}
+% \end{macrocode}
+% \end{macro}
+
+% \begin{environment}{character}
+% This environment defines a `character' i.e.~anything with full stats.
+% \begin{macrocode}
+\NewDocumentEnvironment{character}{}{%
+% \end{macrocode}
+% \changes{v1.00a}{2017/12/04}{Added a spurious change log entry to show what a
+% change \emph{within} an environment definition looks like.}
+%
+% The global lua variable |_ARGS| is created and then populated by commands
+% inside the environment.
+% \begin{macrocode}
+\luadirect{_ARGS = {
+ advantages={},
+ disadvantages={},
+ skills={},
+ spells={}
+ }}
+}{%
+% \end{macrocode}
+% At the end of the environment, the character is initialised printed (via lua's
+% |tex.print|).
+% \begin{macrocode}
+ \luadirect{character = create_character(_ARGS)}
+ \luadirect{print_character()}
+}
+% \end{macrocode}
+% \end{environment}
+%
+% \begin{environment}{lens}
+% Like |character|, but it's a lens.
+% \begin{macrocode}
+\newenvironment{lens}[1]{%
+ \luadirect{character = create_character({#1})}%
+}{%
+ \luadirect{print_character_as_lens()}
+}
+% \end{macrocode}
+% \end{environment}
+%
+% \begin{macro}{\advantage}
+% Adds an advantage to a character. NOTE: this only works in a |character| or
+% |lens| environment.
+% \begin{macrocode}
+\NewDocumentCommand{\advantage}{mO{}}{%
+ \luadirect{_ARGS.advantages[ [[\unexpanded{#1}]] ] = trait(#2)}
+}
+% \end{macrocode}
+% \end{macro}
+% \begin{macro}{\disadvantage}
+% Adds a disadvantage to a character. NOTE: this only works in a |character| or
+% |lens| environment.
+% \begin{macrocode}
+\NewDocumentCommand{\disadvantage}{mO{}}{%
+ \luadirect{_ARGS.disadvantages[ [[\unexpanded{#1}]] ] = trait(#2)}
+}
+% \end{macrocode}
+% \end{macro}
+% \begin{macro}{\levelledadvantage}
+% Adds an advantage to a character. NOTE: this only works in a |character| or
+% |lens| environment.
+% \begin{macrocode}
+% TODO finish this!
+\NewDocumentCommand{\levelledadvantage}{mmO{nil}}{%
+ \luadirect{_ARGS.advantages[ [[\unexpanded{#1}]] ] = valued_trait(#2, #3)}
+}
+% \end{macrocode}
+% \end{macro}
+% \begin{macro}{\levelleddisadvantage}
+% Adds a disadvantage to a character. NOTE: this only works in a |character| or
+% |lens| environment.
+% \begin{macrocode}
+\NewDocumentCommand{\levelleddisadvantage}{mmO{nil}}{%
+ \luadirect{_ARGS.disadvantages[ [[\unexpanded{#1}]] ] = valued_trait(#2, #3)}
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\skill}
+% \begin{macrocode}
+\NewDocumentCommand\skill{mom}{%
+ \IfNoValueTF{#2}
+ {\luadirect{_ARGS.skills[ [[\unexpanded{#1}]] ] = {value=#3}}}
+ {%
+ \luadirect{
+ _ARGS.skills[ [[\unexpanded{#1}]] ] = {value=#3, difficulty=[[#2]]}
+ }
+ }
+}
+% \end{macrocode}
+% \end{macro}
+% \begin{macro}{\spell}
+% \begin{macrocode}
+\NewDocumentCommand\spell{mom}{%
+ \IfNoValueTF{#2}
+ {\luadirect{_ARGS.spells[ [[\unexpanded{#1}]] ] = {value=#3}}}
+ {%
+ \luadirect{
+ _ARGS.spells[ [[\unexpanded{#1}]] ] = {value=#3, difficulty=[[#2]]}
+ }
+ }
+}
+% \end{macrocode}
+% \end{macro}
+% \begin{macrocode}
+\endinput
+%</package>
+% \end{macrocode}
+%\Finale
diff --git a/macros/luatex/latex/gurps/gurps.lua b/macros/luatex/latex/gurps/gurps.lua
new file mode 100644
index 0000000000..22273aeb30
--- /dev/null
+++ b/macros/luatex/latex/gurps/gurps.lua
@@ -0,0 +1,312 @@
+require "gurps_tables"
+
+function thrust_or_swing(typ, st)
+ if st < 1 then
+ return "0"
+ end
+
+ if _GTHRUSTSWINGTABLE[typ][st] then
+ return _GTHRUSTSWINGTABLE[typ][st]
+ else
+ return thrust_or_swing(typ, st - 1)
+ end
+end
+
+function thrust(st)
+ return thrust_or_swing("thrust", st)
+end
+
+function swing(st)
+ return thrust_or_swing("swing", st)
+end
+
+function print_dice(dice_no, modifier)
+ tex.sprint([[\mbox{]])
+ tex.sprint(dice_no .. "d")
+
+ -- If `modifier` is a valid number
+
+ local modifier_number = tonumber(modifier)
+ if modifier_number then
+ if modifier_number > 0 then
+ tex.sprint("+" .. modifier_number)
+ elseif modifier_number < 0 then
+ tex.sprint("-" .. modifier_number)
+ -- else, don't print anything
+ end
+ -- elseif `modifier` is non-nil
+ elseif modifier then
+ tex.sprint("+" .. modifier)
+ end
+ tex.sprint("}")
+end
+
+function valued_trait(value, points)
+ return {
+ value=value,
+ points=points or "?"
+ }
+end
+
+function value(value)
+ return {
+ value=value
+ }
+end
+
+function trait(points)
+ return {
+ points=points or "?"
+ }
+end
+
+function base_stat(stat, multiplier, default)
+ default = default or 10
+ stat = stat or default
+ multiplier = multiplier or 10
+ return valued_trait(stat, (stat - default)*multiplier)
+end
+
+-- Creates an attack table.
+function attack(stat, damage, based_on)
+ rettable = {
+ stat=stat or "?",
+ damage=damage or "?",
+ based_on=based_on or "?"
+ }
+
+ -- i.e. if it's based on a real stat and that stat is a skill
+ if based_on ~= "?" and character.skills[based_on] then
+ rettable.adjustment = character.skills[based_on] - stat
+ elseif based_on ~= "?" and character.spells[based_on] then
+ rettable.adjustment = character.spells[based_on] - stat
+ end
+
+ return rettable
+end
+
+function create_character(args)
+ -- Creates a character
+ local args = args or {}
+ local c = {}
+
+ c.pointless_stats = {}
+ c.pointless_stats.DR = value(args.DR or 0)
+ c.pointless_stats.SM = value(args.SM or 0)
+
+ c.base_stats = {
+ ST=base_stat(args.ST, 10 - c.pointless_stats.SM.value),
+ DX=base_stat(args.DX, 20),
+ IQ=base_stat(args.IQ, 20),
+ HT=base_stat(args.HT),
+ }
+
+ -- Gets the value for a base stat
+ function gv(c, key)
+ return c.base_stats[key].value
+ end
+
+ c.pointless_stats.thr = value(thrust(gv(c, "ST")))
+ c.pointless_stats.sw = value(swing(gv(c, "ST")))
+
+ c.base_stats.HP = base_stat(args.HP or gv(c, "ST"), 5, gv(c, "ST"))
+ c.base_stats.Per = base_stat(args.Per or gv(c, "IQ"), 5, gv(c, "IQ"))
+ c.base_stats.Will = base_stat(args.Will or gv(c, "IQ"), 5, gv(c, "IQ"))
+ c.base_stats.FP = base_stat(args.FP or gv(c, "HT"), 5, gv(c, "HT"))
+
+ -- c.advantages = {}
+ -- c.disadvantages = {}
+ c.advantages = args.advantages
+ c.disadvantages = args.disadvantages
+ -- TODO abstract the logic for spells into general skills
+ c.skills = {}
+ for name,obj in pairs(args.skills) do
+ if obj.difficulty then
+ x = split(obj.difficulty)
+ -- TODO fix this to be spell points vv
+ points = calculate_skill_points(c, x[1], x[2], obj.value)
+ c.skills[name] = valued_trait(obj.value, points)
+ else
+ c.skills[name] = valued_trait(obj.value)
+ end
+ end
+ c.spells = {}
+ for name,obj in pairs(args.spells) do
+ if obj.difficulty then
+ x = split(obj.difficulty)
+ -- TODO fix this to be spell points vv
+ points = calculate_skill_points(c, x[1], x[2], obj.value)
+ c.spells[name] = valued_trait(obj.value, points)
+ else
+ c.spells[name] = valued_trait(obj.value)
+ end
+ end
+ c.attacks = {}
+
+ return c
+end
+
+-- character = create_character()
+
+
+function count_points()
+ running_total = 0
+ for i,traits in pairs({"base_stats",
+ "advantages",
+ "disadvantages",
+ "skills",
+ "spells"}) do
+ if character[traits] then
+ for j,v in pairs(character[traits]) do
+ if v.points ~= "?" then
+ running_total = running_total + v.points
+ end
+ end
+ end
+ end
+ return running_total
+end
+
+
+function print_little_section(title, tbl)
+ tex.print([[\paragraph{]] .. title .. [[}]])
+
+ local x = {}
+ for k,v in pairs(tbl) do
+ if v.value == nil then
+ table.insert(x, k .. "[" .. v.points .. "]")
+ elseif v.points == nil then
+ table.insert(x, k .. "~" .. v.value)
+ else
+ table.insert(x, k .. "~" .. v.value .. "[" .. v.points .. "]")
+ end
+ end
+
+ if next(tbl) == nil then
+ table.insert(x, [[\ldots{}]])
+ end
+ tex.print(table.concat(x, ", ") .. ".")
+end
+
+
+base_stats = {
+ "ST", "DX", "IQ", "HT", "HP", "Per", "Will", "FP"
+}
+
+
+function print_character()
+ tex.print([[\subsubsection{Stats (]] .. count_points() .. [[~pt)}]])
+ tex.print([[\paragraph{Base stats}]])
+ local x = {}
+ for i, base_stat in ipairs(base_stats) do
+ local obj = character.base_stats[base_stat]
+ table.insert(
+ x,
+ base_stat .. [[~]] .. obj.value
+ .. "[" .. obj.points .. "]")
+ end
+ tex.print(table.concat(x, ", ") .. ".")
+
+ print_little_section("Other", character.pointless_stats)
+
+ print_little_section("Advantages", character.advantages)
+ print_little_section("Disadvantages", character.disadvantages)
+ print_little_section("Skills", character.skills)
+ if next(character.spells) then
+ print_little_section("Spells", character.spells)
+ end
+end
+
+function print_character_as_lens()
+ tex.print([[\subsubsection{Lens (+]] .. count_points() .. [[~pt)}]])
+ tex.print([[\paragraph{Base stats}]])
+ local x = {}
+ for i, base_stat in ipairs(base_stats) do
+ local obj = character.base_stats[base_stat]
+ if obj.value ~= 10 then
+ table.insert(
+ x,
+ base_stat .. [[~+]] .. obj.value - 10
+ .. "[" .. obj.points .. "]")
+ end
+ end
+ tex.print(table.concat(x, ", ") .. ".")
+
+ if next(character.advantages) ~= nil then
+ print_little_section("Advantages", character.advantages)
+ end
+ if next(character.disadvantages) ~= nil then
+ print_little_section("Disadvantages", character.disadvantages)
+ end
+ if next(character.skills) ~= nil then
+ print_little_section("Skills", character.skills)
+ end
+ if next(character.spells) ~= nil then
+ print_little_section("Spells", character.spells)
+ end
+end
+
+
+-- Creates a new LaTeX command
+--
+-- TODO move this to the dtx file because that's where documentation for LaTeX
+-- files lives
+function print_set_cmd(name, extra_args)
+ extra_args = extra_args or {"nil"}
+ tex.print(
+ string.format(
+ [[\NewDocumentCommand\set%s{m}]]
+ .. [[{\luadirect{character.%s = base_stat(#1, %s)}}]],
+ name,
+ name,
+ table.concat(extra_args, ", ")
+ )
+ )
+end
+
+print_set_cmd("ST")
+print_set_cmd("DX", {"20"})
+print_set_cmd("IQ", {"20"})
+print_set_cmd("HT")
+print_set_cmd("HP", {"5", "character.base_stats.ST.value"})
+print_set_cmd("Per", {"5", "character.base_stats.IQ.value"})
+print_set_cmd("Will", {"5", "character.base_stats.IQ.value"})
+print_set_cmd("FP", {"5", "character.base_stats.HT.value"})
+
+--- Splits string (on / by default)
+function split(s, split_on)
+ local split_on = split_on or [[/]]
+ local rettable = {}
+ for i in string.gmatch(s, "[^" .. split_on .. "]+") do
+ table.insert(rettable, i)
+ end
+ return rettable
+end
+
+
+function calculate_skill_points(character, based_on, difficulty, skill_level)
+ -- TODO rename this variable
+ if difficulty == "Easy" then
+ difficulty_modifier = 0
+ elseif difficulty == "Average" then
+ difficulty_modifier = 1
+ elseif difficulty == "Hard" then
+ difficulty_modifier = 2
+ elseif difficulty == "Very Hard" then
+ difficulty_modifier = 3
+ elseif difficulty == "Wildcard" then
+ return 3*calculate_skill_points(based_on, "Very Hard", skill_level)
+ end
+
+ -- TODO make support for non-base stat based_on values
+ local relative_level = skill_level - character.base_stats[based_on].value
+ if relative_level == (0 - difficulty_modifier) then
+ return 1
+ elseif relative_level == (1 - difficulty_modifier) then
+ return 2
+ elseif relative_level == (2 - difficulty_modifier) then
+ return 4
+ elseif relative_level > (2 - difficulty_modifier) then
+ return (relative_level - 1 + difficulty_modifier) * 4
+ end
+end
diff --git a/macros/luatex/latex/gurps/gurps.pdf b/macros/luatex/latex/gurps/gurps.pdf
new file mode 100644
index 0000000000..0e6159b69f
--- /dev/null
+++ b/macros/luatex/latex/gurps/gurps.pdf
Binary files differ
diff --git a/macros/luatex/latex/gurps/gurps_tables.lua b/macros/luatex/latex/gurps/gurps_tables.lua
new file mode 100644
index 0000000000..56c79b79b0
--- /dev/null
+++ b/macros/luatex/latex/gurps/gurps_tables.lua
@@ -0,0 +1,112 @@
+_GSWINGTABLE = {}
+_GSWINGTABLE[1] = "1d-5"
+_GSWINGTABLE[2] = "1d-5"
+_GSWINGTABLE[3] = "1d-4"
+_GSWINGTABLE[4] = "1d-4"
+_GSWINGTABLE[5] = "1d-3"
+_GSWINGTABLE[6] = "1d-3"
+_GSWINGTABLE[7] = "1d-2"
+_GSWINGTABLE[8] = "1d-2"
+_GSWINGTABLE[9] = "1d-1"
+_GSWINGTABLE[10] = "1d"
+_GSWINGTABLE[11] = "1d+1"
+_GSWINGTABLE[12] = "1d+2"
+_GSWINGTABLE[13] = "2d-1"
+_GSWINGTABLE[14] = "2d"
+_GSWINGTABLE[15] = "2d+1"
+_GSWINGTABLE[16] = "2d+2"
+_GSWINGTABLE[17] = "3d-1"
+_GSWINGTABLE[18] = "3d"
+_GSWINGTABLE[19] = "3d+1"
+_GSWINGTABLE[20] = "3d+2"
+_GSWINGTABLE[21] = "4d-1"
+_GSWINGTABLE[22] = "4d"
+_GSWINGTABLE[23] = "4d+1"
+_GSWINGTABLE[24] = "4d+2"
+_GSWINGTABLE[25] = "5d-1"
+_GSWINGTABLE[26] = "5d"
+_GSWINGTABLE[27] = "5d+1"
+_GSWINGTABLE[28] = "5d+1"
+_GSWINGTABLE[29] = "5d+2"
+_GSWINGTABLE[30] = "5d+2"
+_GSWINGTABLE[31] = "6d-1"
+_GSWINGTABLE[32] = "6d-1"
+_GSWINGTABLE[33] = "6d"
+_GSWINGTABLE[34] = "6d"
+_GSWINGTABLE[35] = "6d+1"
+_GSWINGTABLE[36] = "6d+1"
+_GSWINGTABLE[37] = "6d+2"
+_GSWINGTABLE[38] = "6d+2"
+_GSWINGTABLE[39] = "7d-1"
+_GSWINGTABLE[40] = "7d-1"
+_GSWINGTABLE[45] = "7d+1"
+_GSWINGTABLE[50] = "8d-1"
+_GSWINGTABLE[55] = "8d+1"
+_GSWINGTABLE[60] = "9d"
+_GSWINGTABLE[65] = "9d+2"
+_GSWINGTABLE[70] = "10d"
+_GSWINGTABLE[75] = "10d+2"
+_GSWINGTABLE[80] = "11d"
+_GSWINGTABLE[85] = "11d+2"
+_GSWINGTABLE[90] = "12d"
+_GSWINGTABLE[95] = "12d+2"
+_GSWINGTABLE[100] = "13d"
+
+_GTHRUSTTABLE = {}
+_GTHRUSTTABLE[1] = "1d-6"
+_GTHRUSTTABLE[2] = "1d-6"
+_GTHRUSTTABLE[3] = "1d-5"
+_GTHRUSTTABLE[4] = "1d-5"
+_GTHRUSTTABLE[5] = "1d-4"
+_GTHRUSTTABLE[6] = "1d-4"
+_GTHRUSTTABLE[7] = "1d-3"
+_GTHRUSTTABLE[8] = "1d-3"
+_GTHRUSTTABLE[9] = "1d-2"
+_GTHRUSTTABLE[10] = "1d-2"
+_GTHRUSTTABLE[11] = "1d-1"
+_GTHRUSTTABLE[12] = "1d-1"
+_GTHRUSTTABLE[13] = "1d"
+_GTHRUSTTABLE[14] = "1d"
+_GTHRUSTTABLE[15] = "1d+1"
+_GTHRUSTTABLE[16] = "1d+1"
+_GTHRUSTTABLE[17] = "1d+2"
+_GTHRUSTTABLE[18] = "1d+2"
+_GTHRUSTTABLE[19] = "2d-1"
+_GTHRUSTTABLE[20] = "2d-1"
+_GTHRUSTTABLE[21] = "2d"
+_GTHRUSTTABLE[22] = "2d"
+_GTHRUSTTABLE[23] = "2d+1"
+_GTHRUSTTABLE[24] = "2d+1"
+_GTHRUSTTABLE[25] = "2d+2"
+_GTHRUSTTABLE[26] = "2d+2"
+_GTHRUSTTABLE[27] = "3d-1"
+_GTHRUSTTABLE[28] = "3d-1"
+_GTHRUSTTABLE[29] = "3d"
+_GTHRUSTTABLE[30] = "3d"
+_GTHRUSTTABLE[31] = "3d+1"
+_GTHRUSTTABLE[32] = "3d+1"
+_GTHRUSTTABLE[33] = "3d+2"
+_GTHRUSTTABLE[34] = "3d+2"
+_GTHRUSTTABLE[35] = "4d-1"
+_GTHRUSTTABLE[36] = "4d-1"
+_GTHRUSTTABLE[37] = "4d"
+_GTHRUSTTABLE[38] = "4d"
+_GTHRUSTTABLE[39] = "4d+1"
+_GTHRUSTTABLE[40] = "4d+1"
+_GTHRUSTTABLE[45] = "5d"
+_GTHRUSTTABLE[50] = "5d+2"
+_GTHRUSTTABLE[55] = "6d"
+_GTHRUSTTABLE[60] = "7d-1"
+_GTHRUSTTABLE[65] = "7d+1"
+_GTHRUSTTABLE[70] = "8d"
+_GTHRUSTTABLE[75] = "8d+2"
+_GTHRUSTTABLE[80] = "9d"
+_GTHRUSTTABLE[85] = "9d+2"
+_GTHRUSTTABLE[90] = "10d"
+_GTHRUSTTABLE[95] = "10d+2"
+_GTHRUSTTABLE[100] = "11d"
+
+_GTHRUSTSWINGTABLE = {
+ thrust=_GTHRUSTTABLE,
+ swing=_GSWINGTABLE,
+}