Chainmail Mercenary Troops
Implements Mercenary Troops algorithm on page 19 of Chainmail by Gygax & Perren.
by krusader74
HTML
<form onsubmit="return compute();">
<fieldset>
<legend><i>Chainmail</i> Mercenary Troops, p. 19</legend>
<input id="submit" type="submit" value="Before each turn a die must be rolled to see what they will do.">
<br><i>N.B.</i>Once engaged in melee it is not necessary to check mercenaries until after the melee is concluded.
</fieldset>
<fieldset>
<legend>Results</legend>
<div id="Results"></div>
</fieldset>
<form>
CSS
html{
font:1em/1.5 Georgia, serif;
padding:5%;
background-color:#fff;
color:#333;
}
JavaScript
function d6 () {
return Math.floor((Math.random()*6)+1);
}
function results () {
var FirstDie = d6();
if ( FirstDie < 0 ) { return "error"; }
if ( FirstDie == 1 ) { return "Mercenaries merely stand still this turn, doing absolutely nothing (except defending themselves if attacked)"; }
if ( FirstDie >= 2 && FirstDie <= 5 ) { return "Mercenaries carry out orders normally this turn"; }
if ( FirstDie == 6 ) {
var SecondDie = d6();
if ( SecondDie < 0 ) { return "error"; }
if ( SecondDie == 1 ) { return "More pay! Stand, no attacking or movement"; }
if ( SecondDie == 2 ) { return "March off board (things aren't going well at home, they say)"; }
if ( SecondDie == 3 ) { return "Bribed! March to join the enemy (as soon as they reach the enemy lines they turn and may attack you)"; }
if ( SecondDie >= 4 && SecondDie <= 6 ) { return "Carry out orders normally far the next three moves, no die checks required during that time. (You're really a winning personality)"; }
if ( SecondDie > 6 ) { return "error"; }
}
if ( FirstDie > 6 ) { return "error"; }
}
function compute () {
document.getElementById("Results").textContent = results();
return false;
}