<<nobr>>\n<<set $rand = random(1, 3)>>\n<<set $strength = $trainedTroops[2][1] * $defenseFactor[2][1] + \n\t\t\t\t $trainedTroops[1][1] * $defenseFactor[1][1]>>\n<<set $damage = $strength * $rand>>\n\n<<set $loss = 1 / random(5, 10)>>\n<<set $loss = Math.floor($loss * $health)>>\n\n<<if $loss gte $trainedTroops[1][1]>>\n<<set $diff = $trainedTroops[1][1]>>\n<<set $trainedTroops[1][1] = 0>>\n<<set $loss = $loss - $diff>>\n<<else>>\n<<set $trainedTroops[1][1] = $trainedTroops[1][1] - $loss>>\n<<endif>>\n\n<<if $loss gt 0>>\n<<set $trainedTroops[2][1] = $trainedTroops[2][1] - $loss>>\n<<endif>>\n\n<<set $health = $health - $damage>>\n<<endnobr>>The main bulk of your troops rallies and prepares a counter-assault. <<if $health lt 15>>The <<print $threat>> is close to death. <<else if $health lt 50>>The <<print $threat>> is weakening noticeably. <<endif>>\n\n<<if $loss gt 0 or $diff gt 0>>Your troops have suffered some losses.<<endif>>\n\n[[Defend]].
<<if $attackCountdown lte 0>>\s\nThe time for planning and training is over. [[You are under attack|Attack!]]. \n<<else>>Fearless leader, how do you wish to proceed? \n\n* [[Recruit]] more unicorns. \n* [[Train]] your charges. \n* [[Survey]] your troops and assess their readiness. <<endif>>
/% Place your story's setup code in this passage.\nAny macros in this passage will be run before the Start passage (or any passage you wish to Test Play) is run. %/\n<<set $totalTroops = 0>>\n<<set $trainedTroops = [ [0, 0], [1, 0], [2, 0], [3, 0] ]>>\n<<set $attackCountdown = 40>>\n<<set $maxFound = 6>>\n<<set $maxTrained = 5>>\n<<set $maxLevel = 3>>\n<<set $trainingLevels = [1, 1, 2, 2, 2, 2, 3]>>\n<<set $decrement = 5>>\n\n<<set $levels = [ [0, "untrained"],\n\t\t\t\t [1, "training"],\n\t\t\t\t [2, "fully-trained"],\n\t\t\t\t [3, "master-trained"] ]>>\n\n<<set $defenseFactor = [ [0, 0.5],\n\t\t\t\t\t\t [1, 1],\n\t\t\t\t\t\t [2, 3],\n\t\t\t\t\t\t [3, 5] ]>>\n\n<<set $enemies = ["dire-wolf", "manticore", "evil witch", "big game hunter", "minotaur", "flesh-eating snail", "giant rabbit", "harpy", "evil fairy queen", "giant scorpion"]>>
<<nobr>>\n<<set $elite = $trainedTroops[3][1] * $defenseFactor[3][1]>>\n<<set $main = $trainedTroops[2][1] * $defenseFactor[2][1] + \n$trainedTroops[1][1] * $defenseFactor[1][1]>>\n<<set $charge = $trainedTroops[0][1] * $defenseFactor[0][1]>>\n\n<<set $newTotal = $trainedTroops[0][1] + $trainedTroops[1][1] + $trainedTroops[2][1] + $trainedTroops[3][1]>>\n<<set $survived = $newTotal / $totalTroops>>\n<<endnobr>><<if $health gt 0 and $newTotal gt 0>>Mount your defense! \n\n<<if $elite gt 0>>* Send your [[elite forces|Elite]] on a surgical strike. <<else>>* You have no elite troops. <<endif>>\s\n<<if $main gt 0>>* Mobilize the [[main troops|Main]] for a counter-strike. <<else>>* Your main troops have been exhausted. <<endif>>\s\n<<if $charge gt 0>>* Order a [[desperate charge|Charge]] of your untrained troops. <<else>>* You have no untrained troops. <<endif>>\s\n<<if $newTotal lte 0>>Your unicorn army has been totally wiped out. The <<print $threat>> has won. <<endif>>\s\n<<else if $health lte 0>>''Victory!'' The <<print $threat>> has been defeated! <<print Math.ceil($survived * 100)>>% of your unicorn troops have survived the battle. \n<<else>>The last of your troops are dead. Your unicorn army has been wiped out by the <<print $threat>>. <<endif>>
<<nobr>>\n<<set $found = random(2, $maxFound)>>\n<<set $totalTroops = $totalTroops + $found>>\n<<set $naive = $trainedTroops[0][1]>>\n<<set $trainedTroops[0][1] = $naive + $found>>\n\n<<set $rand = random(1, $decrement)>>\n<<set $attackCountdown = $attackCountdown - $rand>>\n<<endnobr>>The dangers of the forest are many, and a unicorn alone is almost defenseless. With that in mind you take to the deep woods to round up any wild unicorns you see, and bring them back to safety with you. \n\nYou've rounded up <<print $found>> vulnerable unicorns. <<if $naive gt 0>>They have joined the <<print $naive>> naive, untrained unicorns you have yet to train. <<endif>>\n\n[[Return|The unicorn army]].
!Unicorn Wars\n!!an epic tale of valor and heroism\n\n[[Begin|The gentle unicorn]].
<<nobr>>\n<<set $rand = random(1, 3)>>\n<<set $strength = $trainedTroops[0][1] * $defenseFactor[0][1]>>\n<<set $damage = $strength * $rand>>\n\n<<set $loss = 1 / random(3, 5)>>\n<<set $loss = Math.floor($loss * $health)>>\n\n<<if $loss gt $trainedTroops[0][1]>>\n<<set $loss = $trainedTroops[0][1]>>\n<<endif>>\n\n<<set $health = $health - $damage>>\n\n<<set $trainedTroops[0][1] = $trainedTroops[0][1] - $loss>>\n<<endnobr>>A mass of untrained unicorns charge at the <<print $threat>> ferociously, but with little training or organization. <<if $health lt 15>>The <<print $threat>> is close to death. <<else if $health lt 50>>The <<print $threat>> is weakening noticeably. <<endif>>\n\n<<if $loss lt 1>>You have lost no troops. <<else>>Your untrained troops have suffered expected losses from the mad charge. <<endif>>\n\n[[Defend]].
<<nobr>>\n<<set $level = either($trainingLevels)>>\n<<set $trained = random(1, $maxTrained)>>\n<<set $before = $trainedTroops[$level - 1][1]>>\n\n<<if $trained gt $before>>\n<<set $trained to $before>>\n<<endif>>\n\n<<set $trainedTroops[$level][1] = $trainedTroops[$level][1] + $trained>>\n<<set $trainedTroops[$level - 1][1] = $trainedTroops[$level - 1][1] - $trained>>\n\n<<if $trained eq 0 or $before eq 0>>\n<<set $min = $trainedTroops[0][1]>>\n<<set $max = $trainedTroops[0][1]>>\n\n<<if $min gt 2>>\n<<set $min = 2>>\n<<endif>>\n<<if $max gt 8>>\n<<set $max = 8>>\n<<endif>>\n\n<<set $basic = random($min, $max)>>\n<<set $trainedTroops[0][1] = $trainedTroops[0][1] - $basic>>\n<<set $trainedTroops[1][1] = $trainedTroops[1][1] + $basic>>\n<<else>>\n<<set $basic = 0>>\n<<endif>>\n\n<<set $rand = random(1, $decrement)>>\n<<set $attackCountdown = $attackCountdown - $rand>>\n<<endnobr>><<if $trained gt 0>>Thanks to your rigorous training regimen, <<print $trained>> formerly <<print $levels[$level - 1][1]>> unicorn <<if $trained gt 1>>troops are<<else>>is<<endif>> now <<print $levels[$level][1]>>. <<endif>><<if $basic gt 0>><<print $basic>> naive unicorns have received basic training. <<endif>>Well done. \n\n[[Return|The unicorn army]].
Your unicorn army is <<print $totalTroops>> strong. \n\n<<print $trainedTroops[0][1]>> troops remain untrained. \n\n<<nobr>>\n<<set $danger = $attackCountdown / $decrement>>\n<<set $defense = $trainedTroops[0][1] * $defenseFactor[0][1] + \n\t\t\t\t $trainedTroops[1][1] * $defenseFactor[1][1] + \n\t\t\t\t $trainedTroops[2][1] * $defenseFactor[2][1] + \n\t\t\t\t $trainedTroops[3][1] * $defenseFactor[3][1]>>\n<<endnobr>>Alert level is <<print $danger>>. Defense readiness factor is <<print $defense>>. \n\n[[Return|The unicorn army]].
/* Your story will use the CSS in this passage to style the page.\nGive this passage more tags, and it will only affect passages with those tags.\nExample selectors: */\n\nbody {\n\t/* This affects the entire page */\n\tbackground-color: #bf9;\n\tcolor: #110;\n\tfont-family: Corbel, Arial, sans-serif;\n\t\n}\n.passage {\n\t/* This only affects passages */\n\tfont-size: 11pt;\n\tcolor: #030;\n}\n.passage a {\n\t/* This affects passage links */\n\tcolor: #c90;\n\t\n}\n.passage a:hover {\n\t/* This affects links while the cursor is over them */\n\tcolor: #f60;\n\t\n}
Unicorn Wars
a game by Hazel\n(a defender of unicorn-kind)
<<nobr>>\n<<set $threat = either($enemies)>>\n<<set $health = 100>>\n<<endnobr>>Attack! Attack! \n\nYou are under attack by a hostile <<print $threat>>. Can your unicorn army successfully defend themselves? You've trained them as best you can, and now they are prepared to be tested in the field of battle. \n\n[[Defend]].
You have been chosen for a very difficult and very important job. Indeed, the safety and well-being of all unicorn-kind may well depend on your actions. Your mission (should you choose to accept it) is to gather the endangered unicorns, protect them against their natural predators, and train them to defend themselves. \n\nYou are now a Defender of Unicorns. \n\n[[Good luck|The unicorn army]].
<<nobr>>\n<<set $rand = random(1, 3)>>\n<<set $strength = $trainedTroops[3][1] * $defenseFactor[3][1]>>\n<<set $damage = $strength * $rand>>\n\n<<set $loss = 1 / random(10, 15)>>\n<<set $loss = Math.floor($loss * $health)>>\n\n<<if $loss gt $trainedTroops[3][1]>>\n<<set $loss = $trainedTroops[3][1]>>\n<<endif>>\n\n<<set $health = $health - $damage>>\n\n<<set $trainedTroops[3][1] = $trainedTroops[3][1] - $loss>>\n<<endnobr>>Your master-trained cavalry execute a percision attack and weaken your enemy. <<if $health lt 15>>The <<print $threat>> is close to death. <<else if $health lt 50>>The <<print $threat>> is weakening noticeably. <<endif>>\n\n<<if $loss lt 1>>You have lost no troops. <<else>>You suffered the loss of <<print $loss>> elite troops. <<if $trainedTroops[3][1] gt 0>>Only <<print $trainedTroops[3][1]>> remain. <<else>>No troops remain. <<endif>><<endif>>\n\n[[Defend]].
The majestic unicorn, rarest of all rare beasts, is a gentle and mystical animal. Despite its sharp, pointy horn, the unicorn is known to be non-violent and harmless. \n\nBut there are dangers in the world and the unicorn has many natural enemies. \n\nThat's where [[you|Defender of unicorns]] come in.