\ProvidesPackage{config/arms}
%%%%% Weapons

% Weapon entries do two things.
% When used in creatures, they raise stats.
% When used in the  weapons chart, they display stats.

\newcounter{weaponBonus}

\newcommand\weapon[6][]{%
  % The weapon's bonus to hit is equal to its length + weight / 2.
  \setcounter{weaponBonus}{#3}%
  \ifnum#5>0%
    \addtocounter{weaponBonus}{#5}%
  \fi%
  \roundUp{weaponBonus}%
  \setcounter{damage}{#4}%
  \ifnum#5>0%
    \addtocounter{damage}{#5}%
  \fi%
  \roundUp{damage}%
  \setcounter{heft}{#3}%
  \addtocounter{heft}{#5}%
  \roundUp{heft}%
  \ifnum\value{heft}<1%
    \setcounter{heft}{1}%
  \fi%
  \setcounter{weight}{#5}%
  \setcounter{cost}{#6}%
  #1%
  \iftoggle{creatureBox}{%
    \addtocounter{att}{\value{weaponBonus}}%
    #2\ignorespaces%
  }{%
    #1%
    #2 &%
    \ifnum\value{weaponBonus}>0 +\fi%
    \arabic{weaponBonus} &%
    \ifnum\value{damage}>0 +\fi\arabic{damage}%
    & \arabic{heft} &%
    \arabic{weight}%
    \iftoggle{examplecharacter}{}{% Example characters have all the weapon stats except cost, so we only need cost for the weapon charts in the core book.
      &%
      \ifnum#6<1\else%
        \ifnum\value{cost}>200%
          \divide\value{cost} by 50\addtocounter{cost}{0}%
          \arabic{cost} sp%
        \else%
          \arabic{cost} cp%
        \fi%
      \fi%
    }%
    \\%
  }%
}

% Shields work much like weapons, except that their Bonus is high, their initiative cost is low, but their attack is poor.

\newcommand\shield[3][]{
  \setcounter{shieldBonus}{#3}
  \addtocounter{shieldBonus}{2}
  \setcounter{shieldWeight}{#3}
  \setcounter{shieldInit}{#3}
  \stepcounter{shieldInit}
  \setcounter{cost}{87}
  #1 
  \iftoggle{creatureBox}%
    {#2 shield (+\arabic{shieldBonus}/ \arabic{shieldInit})}{
      #2 Shield &
      +\arabic{shieldBonus} &
      \arabic{shieldInit} &
      \arabic{shieldWeight} &

      \multiply\value{cost} by 8
      \multiply\value{cost} by \value{shieldBonus}
      \ifnum\value{cost}>200
        \divide\value{cost} by 100
        \arabic{cost} sp
      \else
        \arabic{cost} cp
      \fi
      \\
    }%
}

% Use this 'weapon entry' command to place items in the weapons table, like this:
%\weapon{Name}%
%{Bonus}
%{Dam}
%{Wt.} + Init
%{Cost}
%{Knacks}

\newcommand{\boulder}{\weapon[\addtocounter{heft}{2}]{Boulder}{0}{0}{6}{0}}
\newcommand{\chair}{\weapon[\addtocounter{weaponBonus}{-1}]{Chair}{1}{0}{2}{250}}
\newcommand{\club}{\weapon[\addtocounter{damage}{-1}]{Club}{1}{0}{2}{8}}
\newcommand{\cudgel}{\weapon[\addtocounter{damage}{-1}]{Cudgel}{0}{0}{1}{6}}
\newcommand{\Dagger}{\weapon{Dagger}{0}{2}{-3}{70}}
\newcommand{\firepoker}{\weapon[\addtocounter{damage}{-1}]{Firepoker}{1}{0}{1}{90}}
\newcommand{\giantsword}{\weapon{Giant Sword}{3}{2}{4}{3200}}
\newcommand{\greataxe}{\weapon{Great Axe}{2}{2}{4}{1600}}
\newcommand{\greatsword}{\weapon{Greatsword}{2}{3}{3}{2200}}
\newcommand{\greatclub}{\weapon[\addtocounter{damage}{-1}]{Great Club}{4}{0}{5}{10}}
\newcommand{\javelin}{\weapon{Javelin}{2}{1}{0}{880}}
\newcommand{\knife}{\weapon{Knife}{0}{1}{-4}{50}}
\newcommand{\Log}{\weapon[\addtocounter{damage}{-3}]{Log}{-1}{0}{0}{2}}
\newcommand{\rapier}{\weapon{Rapier}{2}{3}{-1}{2500}}
\newcommand{\largerock}{\weapon[\addtocounter{weight}{3}]{Rock (large)}{0}{0}{3}{0}}
\newcommand{\longsword}{\weapon{Longsword}{2}{3}{1}{2200}}
\newcommand{\maul}{\weapon{Maul}{1}{0}{3}{2200}}
\newcommand{\poleaxe}{\weapon{Poleaxe}{4}{1}{4}{2400}}
\newcommand{\quarterstaff}{\weapon{Quarterstaff}{4}{0}{1}{30}}
\newcommand{\rock}{\weapon[\addtocounter{heft}{1}]{Rock}{-1}{0}{1}{0}}
\newcommand{\shortsword}{\weapon{Shortsword}{1}{3}{0}{1500}}
\newcommand{\skillet}{\weapon[\addtocounter{heft}{1}]{Frying Pan}{1}{0}{1}{80}}
\newcommand{\spear}{\weapon{Spear}{4}{1}{1}{300}}
\newcommand{\stick}{\weapon{Stick}{1}{0}{-1}{1}}
\newcommand{\whip}{\weapon[\addtocounter{damage}{-1}]{Whip}{1}{0}{0}{30}}
\newcommand{\warhammer}{\weapon{Warhammer}{2}{0}{3}{30}}
\newcommand{\woodaxe}{\weapon[\addtocounter{heft}{1}]{Wood Axe}{2}{2}{2}{300}}

% SHIELDS
\newcommand{\longbow}{Longbow}
\newcommand{\bucklar}{\shield{Bucklar}{0}}
\newcommand{\roundshield}{\shield{Round}{1}}
\newcommand{\kiteshield}{\shield{Kite}{2}}

% ARMOUR

%% For perfect armour, stick \perfect Armour in the additional notes category of a \person (#9).

\newcommand{\perfectArmour}{\gdef\armourtype{(Perfect)}}

\newcommand{\partialelvish}{partial leather armour%
	\ifnumcomp{\value{dr}}{>}{2}%
	{\addtocounter{dr}{1}}%
	{\divide\value{dr} by 2 \addtocounter{dr}{2}}%
}

\newcommand{\partialleather}{partial leather armour%
	\ifnumcomp{\value{dr}}{>}{3}%
	{\addtocounter{dr}{2}}%
	{\divide\value{dr} by 2 \addtocounter{dr}{3}}%
}

\newcommand{\completeleather}{full leather armour\gdef\armourtype{C}%
	\ifnumcomp{\value{dr}}{>}{3}%
	{\addtocounter{dr}{2}}%
	{\divide\value{dr} by 2 \addtocounter{dr}{3}}%
}

\newcommand{\partialchain}{partial chainmail%
	\ifnumcomp{\value{dr}}{>}{4}%
	{\addtocounter{dr}{2}}%
	{\divide\value{dr} by 2 \addtocounter{dr}{4}}%
}

\newcommand{\completechain}{complete chain armour\gdef\armourtype{C}%
	\ifnumcomp{\value{dr}}{>}{4}%
	{\addtocounter{dr}{2}}%
	{\divide\value{dr} by 2 \addtocounter{dr}{4}}%
}

\newcommand{\partialplate}{partial plate armour%
	\ifnumcomp{\value{dr}}{>}{5}%
	{\addtocounter{dr}{3}}%
	{\divide\value{dr} by 2 \addtocounter{dr}{5}}%
}

\newcommand{\completeplate}{complete plate armour\gdef\armourtype{C}%
	\ifnumcomp{\value{dr}}{>}{5}%
	{\addtocounter{dr}{3}}%
	{\divide\value{dr} by 2 \addtocounter{dr}{5}}%
}