Monday, August 14, 2017

Converting Lone Wolf to Twine and SugarCube - Part 5 - More Equipment


    First things first, let's just go ahead and make a variable for every item. Yeah, it's going to be a long list, but it's pretty straightforward to do (and we're not going to add any new items during the game). That's going to be a bunch of variables, so I'm going to make a new Passage “Initialize” to dump it all in. That will be the starting Passage (for this test, and would be in the game too) from which we'll go to the "Inventory Tracker" we were starting at. Here's the “Initialize” code...

::Initialize
This is just a starting point for our story, the blahblahblah place where we can set all our variables.

[[Check your inventory->Inventory Tracker]]

/* Belt Pouch slot, max 50 */
<<set $Gold = 0>>

/* Head slot, max 1 */
<<set $Helmet = 0>>

/* Body slot, max 1 */
<<set $Armor = 0>>

/* Hand slot, max 2 */
<<set $Daggers = 0>>
<<set $Spears = 0>>
<<set $Maces = 0>>
<<set $ShortSwords = 0>>
<<set $Warhammers = 0>>
<<set $Swords = 0>>
<<set $Axes = 0>>
<<set $Quarterstaffs = 0>>
<<set $Broadswords = 0>>

/* Backpack slot, max 8 */
<<set $Meals = 0>>
<<set $HealthPotions = 0>>
<<set $MealOfLaumspur = 0>>
<<set $StrengthPotion = 0>>



    Doesn't look like much, since everything is happening behind the scenes. Speaking of which, if you look in the code you'll notice I put some HTML comments to remind me about how the items are grouped and the max numbers...

/* Belt Pouch slot, max 50 */
<<set $Gold = 0>>
 
/* Head slot, max 1 */
<<set $Helmet = 0>>
 
/* Body slot, max 1 */
<<set $Armor = 0>>


    Comments are good. What makes perfect sense today could become a blur in a week, or after a bunch of code revisions. So it's not a bad idea to make notes for yourself, or others if you want to share your work (which I'm going to with this when I'm done).
    Looking at it, I also have 16 items, counting “gold” as one item - which isn't too bad. The code for handling gold is pretty much done I think, so I'm part-way there. There are some additional items (maybe another 6-8) but they are ‘special items’ that don't take up any inventory space - so not going to worry about them right now.
    Okay, so let's move on to the Inventory Tracker and show the player what they are carrying around.


     Makes a pretty ugly list when you print it all, doesn't it? :) Let's make that a bit neater... (come to think of it, you do start with an item or two)

::Inventory Tracker
<<nobr>>Your Belt Pouch has $Gold Gold Crowns.

<br><br>You are wearing-
<br>The green tunic and cloak of a Kai initiate.
<<if $Helmet > 0>><br>A Helmet.<</if>>
<<if $Armor > 0>><br>A Chainmail Waistcoat.<</if>>

<br><br>You are carrying-
<<if $Daggers > 0>><br>A Dagger<</if>>
<<if $Spears > 0>><br>A Spear<</if>>
<<if $Maces > 0>><br>A Mace<</if>>
<<if $ShortSwords > 0>><br>A Short Sword<</if>>
<<if $Warhammers > 0>><br>A Warhammer<</if>>
<<if $Swords > 0>><br>A Sword<</if>>
<<if $Axes > 0>><br>An Axe<</if>>
<<if $Quarterstaffs > 0>><br>A Quarterstaff<</if>>
<<if $Broadswords > 0>><br>A Broadsword<</if>>

<br><br>Your Backpack has-
<<if $Meals > 0>><br>$Meals Meals<</if>>
<<if $HealthPotions > 0>><br>$HealthPotions Health Potions<</if>>
<<if $MealOfLaumspur > 0>><br>$MealOfLaumspur Meals Of Laumspur<</if>>
<<if $StrengthPotion > 0>><br>$StrengthPotion Strength Potions<</if>>
<</nobr>>

Let's go [[Find Stuff]]

  

    A bunch of <<if>>s to see what you have, a general <<nobr>> with each item having it's own <br> to get the spacing looking good, and we have a decent inventory list. Let's move on to actually picking up stuff.
    According to the book, you went out to chop wood when your monastery was attacked. After you rush back you search and find one item, chosen at random. So let's generate a random item and figure out how to equip it while staying within our limits.

    After a lot of playing around with things, here's where I am...


    Okay, so I added the random item picker to this page, and left the gold that was there. Here's the code...

::Find Stuff
Your home has been destroyed and your friends killed.  You will need supplies to get your revenge.

Searching the wreckage-
<<set $newgold = random (0,9)>><<include [[Change Gold]]>>

And a buried item...
<<nobr>><<set $burieditem = random (0, 9)>>
<<if $burieditem == 0>><<set $founditem = ["Broadsword", 1]>><<print "A Broadsword">><</if>>
<<if $burieditem == 1>><<set $founditem = ["Sword", 1]>><<print "A Sword">><</if>>
<<if $burieditem == 2>><<set $founditem = ["Helmet", 1]>><<print "A Helmet">><</if>>
<<if $burieditem == 3>><<set $founditem = ["Meals", 2]>><<print "2 Meals">><</if>>
<<if $burieditem == 4>><<set $founditem = ["Armor", 1]>><<print "A Chainmail Waistcoat">><</if>>
<<if $burieditem == 5>><<set $founditem = ["Mace", 1]>><<print "A Mace">><</if>>
<<if $burieditem == 6>><<set $founditem = ["Health Potion", 1]>><<print "A Healing Potion">><</if>>
<<if $burieditem == 7>><<set $founditem = ["Quarterstaff", 1]>><<print "A Quarterstaff">><</if>>
<<if $burieditem == 8>><<set $founditem = ["Spear", 1]>><<print "A Spear">><</if>>
<<if $burieditem == 9>><<set $founditem = ["Gold", 12]>><<print "12 Gold Crowns">><</if>><</nobr>>
[[Pick up the item->Change Item]]


Now that you have some money, let's [[Go to the Store->Store]]


    Like I did with the “Change Gold” Passage (also on this page) I want to make one external Passage that I can call from anywhere to equip an item (this is a lot of code after all, really don't want to have to re-type for each Passage it appears in). So I did a simple <<random>> to get the found item. Then, since you can find more than 1 of an item, I put the item name and quantity into an array <<set $founditem = ["Sword", 1]>> so I would know how many I was dealing with. Which makes $founditem[0] “Sword” and $founditem[1] “1”, because arrays start at 0. For weapons and armor that doesn't matter, you only need 1 so I actually ignore if you try to pick up more than 1 at a time (which works for this story, but might not work for other types of games).
    Now, I want to make this an <<include>> so that “Change Gold” and “Change Item” both exist within the Passage that calls them - but for now I left it as a separate Passage so that I could bounce back-and-forth between them, picking up more and more items and making sure everything worked (code and test). Which it eventually did - I had a ton of names and spaces and plural-or-not-plural variable names to correct. Also, I copied the code to increase gold from the “Change Gold” Passage, that way I have two ways to get gold if I need (a small duplication). Also, some items took Hand or Backpack slots, which are shared across different items (all weapons go in Hands, potions and meals share Backpack) - so I decided to just make two new variables, $CountHands and $CountBackpack, so I know how many of each the player has (and was easier than trying to iterate through all the types of items to add them up).

    Here's the code for the “Change Item” Passage...

<<switch $founditem[0]>>

<<case "Gold">>
You pick up $founditem[1] Gold Crowns,
<<set $Gold = $Gold + $founditem[1]>>
<<if $Gold > 50>>
<<set $Gold = 50>>
 but your Belt Pouch only holds 50 Gold Crowns,
<</if>>
 you now have $Gold Gold Crowns.

<<case "Helmet">>
<<if $Helmet > 0>>You are already wearing a helmet!
<<else>>
<<set $Helmet = 1>>You put on the Helmet.
<</if>>

<<case "Armor">>
<<if $Armor > 0>>You are already wearing armor!
<<else>>
<<set $Armor = 1>>You put on the Chainmail Waistcoat.
<</if>>

<<case "Dagger">>
<<if $CountHands >= 2>>Your hands are full!
<<elseif $Daggers > 0>>You already have a Dagger!
<<else>>
<<set $Daggers = 1>>You pick up the Dagger.<<set $CountHands++>>
<</if>>

<<case "Spear">>
<<if $CountHands >= 2>>Your hands are full!
<<elseif $Spears > 0>>You already have a Spear!
<<else>>
<<set $Spears = 1>>You pick up the Spear.<<set $CountHands++>>
<</if>>

<<case "Mace">>
<<if $CountHands >= 2>>Your hands are full!
<<elseif $Maces > 0>>You already have a Mace!
<<else>>
<<set $Maces = 1>>You pick up the Mace.<<set $CountHands++>>
<</if>>

<<case "Short Sword">>
<<if $CountHands >= 2>>Your hands are full!
<<elseif $ShortSwords > 0>>You already have a Short Sword!
<<else>>
<<set $ShortSwords = 1>>You pick up the Short Sword.<<set $CountHands++>>
<</if>>

<<case "Warhammer">>
<<if $CountHands >= 2>>Your hands are full!
<<elseif $Warhammers > 0>>You already have a Warhammer!
<<else>>
<<set $Warhammers = 1>>You pick up the Warhammer.<<set $CountHands++>>
<</if>>

<<case "Sword">>
<<if $CountHands >= 2>>Your hands are full!
<<elseif $Swords > 0>>You already have a Sword!
<<else>>
<<set $Swords = 1>>You pick up the Sword.<<set $CountHands++>>
<</if>>

<<case "Axe">>
<<if $CountHands >= 2>>Your hands are full!
<<elseif $Axes > 0>>You already have an Axe!
<<else>>
<<set $Axes = 1>>You pick up the Axe.<<set $CountHands++>>
<</if>>

<<case "Quarterstaff">>
<<if $CountHands >= 2>>Your hands are full!
<<elseif $Quarterstaffs > 0>>You already have a Quarterstaff!
<<else>>
<<set $Quarterstaffs = 1>>You pick up the Quarterstaff.<<set $CountHands++>>
<</if>>

<<case "Broadsword">>
<<if $CountHands >= 2>>Your hands are full!
<<elseif $Broadswords > 0>>You already have a Broadsword!
<<else>>
<<set $Broadswords = 1>>You pick up the Broadsword.<<set $CountHands++>>
<</if>>

<<case "Meals">>
<<if $CountBackpack >= 8>>Your Backpack is full!
<<elseif ($founditem[1] + $CountBackpack) > 8>>You don't have room for that many items!
<<else>>
<<set $Meals = $Meals + $founditem[1]>>You now have $Meals Meals.<<set $CountBackpack = ($CountBackpack + $founditem[1])>>
<</if>>

<<case "Health Potion">>
<<if $CountBackpack >= 8>>Your Backpack is full!
<<elseif ($founditem[1] + $CountBackpack) > 8>>You don't have room for that many items!
<<else>>
<<set $HealthPotions = $HealthPotions + $founditem[1]>>You now have $HealthPotions Health Potions.<<set $CountBackpack = ($CountBackpack + $founditem[1])>>
<</if>>

<<case "Meal Of Laumspur">>
<<if $CountBackpack >= 8>>Your Backpack is full!
<<elseif ($founditem[1] + $CountBackpack) > 8>>You don't have room for that many items!
<<else>>
<<set $MealOfLaumspur = $MealOfLaumspur + $founditem[1]>>You now have $MealOfLaumspur Meals Of Laumspur.<<set $CountBackpack = ($CountBackpack + $founditem[1])>>
<</if>>

<<case "Strength Potion">>
<<if $CountBackpack >= 8>>Your Backpack is full!
<<elseif ($founditem[1] + $CountBackpack) > 8>>You don't have room for that many items!
<<else>>
<<set $StrengthPotion = $StrengthPotion + $founditem[1]>>You now have $StrengthPotion Strength Potions.<<set $CountBackpack = ($CountBackpack + $founditem[1])>>
<</if>>

<</switch>>

<<return "Go Back">>

Debug Code- Inventory Dump

<<nobr>>Your Belt Pouch has $Gold Gold Crowns.

<br><br>You are wearing-
<br>The green tunic and cloak of a Kai initiate.
<<if $Helmet > 0>><br>A Helmet.<</if>>
<<if $Armor > 0>><br>A Chainmail Waistcoat.<</if>>

<br><br>You are carrying-
<<if $Daggers > 0>><br>A Dagger<</if>>
<<if $Spears > 0>><br>A Spear<</if>>
<<if $Maces > 0>><br>A Mace<</if>>
<<if $ShortSwords > 0>><br>A Short Sword<</if>>
<<if $Warhammers > 0>><br>A Warhammer<</if>>
<<if $Swords > 0>><br>A Sword<</if>>
<<if $Axes > 0>><br>An Axe<</if>>
<<if $Quarterstaffs > 0>><br>A Quarterstaff<</if>>
<<if $Broadswords > 0>><br>A Broadsword<</if>>

<br><br>Your Backpack has-
<<if $Meals > 0>><br>$Meals Meals<</if>>
<<if $HealthPotions > 0>><br>$HealthPotions Health Potions<</if>>
<<if $MealOfLaumspur > 0>><br>$MealOfLaumspur Meals Of Laumspur<</if>>
<<if $StrengthPotion > 0>><br>$StrengthPotion Strength Potions<</if>>
<</nobr>>


    Oh yeah, you'll also notice I copied the code to list the player's inventory so that I could check for errors...




    So one of the primary things I needed to do with this Passage was make sure the player didn't try to equip too many of the same items...


    Which I did in a few steps.

    The Gold already had it's check in the code I copied from “Change Gold”, easy.

    Helmets and Armor were easy, if you had one you didn't need another one, so I just checked to see if you had any in your inventory <<if $Helmet > 0>>You are already wearing a helmet!

    Weapons you could have 2 of, so I needed to check how many you already had:

<<if $CountHands >= 2>>Your hands are full!
You already have two weapons, you don't have room for any more...

<<elseif $Daggers > 0>>You already have a Dagger!
Even if you had room for a weapon, if you already have a dagger you don't need another one...

<<else>>
<<set $Daggers = 1>>You pick up the Dagger.<<set $CountHands++>>

So if you've got room and don't already have one, then you pick it up, and increase the counter for your hands/weapons total.

Backpack items worked the same way, check for how many free spaces you have...
<<if $CountBackpack >= 8>>Your Backpack is full!

<<elseif ($founditem[1] + $CountBackpack) > 8>>You don't have room for that many items!
And if you have room put them in your backpack and increase the ‘container counter’ by the number you picked up.

<<else>>
<<set $Meals = $Meals + $founditem[1]>>You now have $Meals Meals.<<set $CountBackpack = ($CountBackpack + $founditem[1])>>


    Now, one thing wrong with this: if you find 2 Meals but only have room for one, it won't let you pick up just one - so I'll have to fix that. Also, some items do something when you pick them up/ have them - like weapons, if you have one it increases your Combat Skill. I need to set those effects here, when the item is picked up, or I need to check for it every time it's necessary. So I could put the code in the Combat section I'm working on next? Which sounds good to me actually, I could total up all the factors related to combat just before it starts. The only problem is that the player won't see the effect an item has on his stats except for Combat, so he couldn't just pull up the sheet and check it out... hmmm... I have to think about this. Most other items will just sit in the inventory until they get used by a Passage, so I don't need to worry about them. I do need to be able to drop or swap out items though... So no rest for the wicked, time to work on some more code before I can call the Inventory section done.

    Dropping items is easy, just subtract from their count. Swapping items is trickier, so that was the first thing I decided to tackle. Let me show you what I came up with...

<<case "Dagger">>
<<if $CountHands >= 2>>
<<if $Daggers == 0>>Your hands are full!
<<elseif $Daggers == 2>>You already have two Daggers, your hands are full!
<<elseif $Daggers == 1>>You already have a Dagger! Do you want to drop your other weapon and have 2 Daggers instead?
<<linkreplace " Yes">><<set $Daggers = 2>><<if $Spears == 1>><<set $Spears = 0>><<elseif $Maces == 1>><<set $Maces = 0>>
<<elseif $ShortSwords == 1>><<set $ShortSwords = 0>><<elseif $Warhammers == 1>><<set $Warhammers = 0>><<elseif $Swords == 1>><<set $Swords = 0>><<elseif $Axes === 1>><<set $Axes = 0>><<elseif $Quarterstaffs == 1>><<set $Quarterstaffs = 0>>
<<elseif $Broadswords == 1>><<set $Broadswords = 0>><</if>> You now have 2 Daggers.<</linkreplace>>
<<linkreplace " No">>You leave the item.<</linkreplace>><</if>>
<<elseif $CountHands == 1>>
<<if $Daggers == 1>>You already have a Dagger, do you want to pick up a spare?
<<linkreplace " Yes">><<set $Daggers = 2>>You now have 2 Daggers.<<set $CountHands++>><</linkreplace>>
<<linkreplace " No">>You leave the item.<</linkreplace>><</if>>
<<else>>
<<set $Daggers = 1>>You pick up the Dagger.<<set $CountHands++>>
<</if>>


    So this was about an hour, maybe hour-and-half, of writing, testing, fixing, testing, fixing, changing the testing, removing a section, testing, fixing, testing, fixing, moving one section to another spot, testing, fixing, removing a section, testing, testing, realizing I should have left that last section alone, testing, fixing, it finally seems toactually work, thank the good spirits!

    Let me walk you through what I should have done instead.

    Difficulty really seems to come down to 2 parts: difficulty in understanding and difficulty in tracking. Learning this HTML/ CSS/ JavaScript/ Twine/ SugarCube stuff is “difficult to understand.” It's not like casual writing, thinking or speaking. You need a new language and new ways of thinking. "Difficult to track" is like trying to memorize a phone book, all the names and numbers and address are everyday English, but there are so many of them to remember. Coding a project like this also has a lot of “difficult to track” associated with it, but that kind of difficulty is at least a little easier to deal with by it's nature. What am I talking about? Something I remembered (too late) I had heard of called “pseudocode.”
    The idea behind “pseudocode” is to organize your thoughts by writing what you need to happen in plain English, but English that kind of reflects the code you'll need to write. It tackles the “difficult to track” first by getting your thoughts organized, then you fill in the blanks with real code and deal with the “difficult to understand” part one step at a time, while now seeing how each step has to fit together to make the whole.
    One more thing and I'll explain - “Occam's Razor” is an idea that, generally speaking, the simplest potential answer is the right one. It says to look for simple answers before complicated ones. I think if there was an “Occam's Programming Theory” it would be start with the easiest thing to check for and then get more complicated.

    Okay, I jumped in to trying to program the difficulties of the situation instead of thinking through what I needed to happen. I'm trying to write code to let you swap out one item for another, and I'm adding it to the code for picking up items (since for the most part my inventory isn't going to change very often, there are only a relative few Passages that have items to pick up). So I'm going to use a technique from before and write some HTML comments, but structure them along with what I'm trying to do - and use spaces to organize the smaller steps within the big steps. Something like this...

/* pick up new item */
I'm assuming the player wants the item, they had to click on the link to pick it up, so I'm not asking if they want to pick it up or not

/* check what kind of container it goes in */

/* check space in that container */

/* check if you already have item */

/* ask to swap items */
Yes //swap items
No //exit


    That's a pretty basic outline, I'm going to need some details to refine it. Going from the top down my existing code, my Gold, Helmet and Armor don't need to swap. The first place the player might need to swap items in with the Hands/ Weapons, and the first weapon is the Dagger - so I'm going to start thinking/ coding with that...

/* pick up new item */
I'm assuming the player wants the item, they had to click on the link to pick it up, so I'm not asking if they want to pick it up or not

/* check what kind of container it goes in */
Weapons go in the Hands container, max 2

/* check space in that container */
How many hands are free?

/* Do you have 2 hands free */
Pick up the item (no swapping or thinking required)

/* Do you have 1 hand free */
/* check if you already have item */
/* if not */
Pick up the item

/* if you do */
Ask if you want an extra
Yes //pick up items
No //exit

/* Do you have 0 free hands */
/* check if you already have 2 of the item */
If you do, you're already full //exit

/* check if you already have 1 of the item */
/* ask to swap items */
Yes //swap items
No //exit

/* check if you already have 0 of the item */
/* ask to swap items */
Yes
/* what items do you have? */
/* which item do you want to drop/swap? */
No //exit


     It makes for a moderately-sized flowchart, sometimes simple things are more complicated than they look :) Let me walk through this and point out my thinking:

/* pick up new item */
/* check what kind of container it goes in */
/* check space in that container */


    So you want an item, what is it and where does it go? I've got the ‘what is it’ and ‘where’ parts already written in my code to pick the item up (in the variable that gets passed and then the big <<switch>> sorting by items).

/* Do you have 2 hands free */
/* Do you have 1 hand free */
/* Do you have 0 free hands */


    How many hands you have open says weather you'll need to swap anything or not (since you don't need to swap if you have free space, you just pick up, which is the code I already have written).

/* Do you have 2 hands free */
Pick up the item (no swapping or thinking required)


    This is the easiest, you don't currently have anything so you pick the item up.

/* Do you have 1 hand free */
    Okay, so you do have something already, is it the same item you want to pick up or not?

/* check if you already have item */
/* if not */
Pick up the item

    No, well then you have space, so pick up the item.

/* if you do */
Ask if you want an extra
Yes //pick up item
No //exit

    If yes, well, you don't get much benefit from having 2 of the same weapon in this game (another game might be a different story), so do you want to pick it up? Now, looking over the story again while working on this stuff I reminded myself that there are a few Passages where you can lose some or all of your Weapons and/or Backpack items - so it might, in a few cases, be helpful to have 2 of the same weapon that you're proficient in using (if you took the Weaponskill to begin with). Should I mention that to the player? Well, the book doesn't, so no, but if this was my own game I'd debate saying that. (also if there were stores to sell stuff (which you can't in this game) there would be another reason having spare items could be useful)

/* Do you have 0 free hands */
    Okay, so you're holding all the items you can, so you'll have to swap something, right?

/* check if you already have 2 of the item */
If you do, you're already full //exit

    Thinking about it, well, no - if you have 2 of the same item you have the item and a spare and no room for yet another, so there's noting to do here

/* check if you already have 1 of the item */
/* ask to swap items */
Yes //swap items
No //exit

    Here we need to ask, like above, if you really want to drop your other item to have a spare of the one you're picking up

/* check if you already have 0 of the item */
/* ask to swap items */
Yes
/* what items do you have? */
/* which item do you want to drop/swap? */
No //exit

    And finally, if you're full but don't have any of the item you're picking up, then we need to ask what existing item you want to drop to make room for the new one.

    It's a modestly-sized ‘flowchart’ and it did take a little while to think through and write out - but I can tell you that I would have avoided several errors from last night if I had done this first (and if you look at the code I posted, you'll notice I completely missed the last thing- if you had 2 weapons, but none of the one you want, so which to drop/swap). Being new to all this I kind of want to just jump in and start doing something, and while that does teach - it teaches painfully. All the re-writes, error-tracking, and research add up. There have been a few points where I felt like giving up on the whole project. Thinking things through like this helps me stay organized, should help me do fewer re-writes, and makes the whole thing feel a little easier to understand. Now that I have my flowchart, I just have to start writing code one line at a time until it's filled in.
    Mind you, I don't want to flowchart too big - if I tried to outline the whole game/ mechanics this way I'd likely have something so big it would be more confusing than helpful; once things have been broken into semi-manageable chunks this really helps.

    Okay, so now that I have an outline, let's start adding coding this thing...

<<case "Dagger">>
<<nobr>>
<<if $CountHands == 0>>
    <<set $Daggers = 1>>You pick up the Dagger.<<set $CountHands++>>

<<elseif $CountHands == 1>>
<<if $Daggers == 0>>
  <<set $Daggers = 1>>You pick up the Dagger.<<set $CountHands++>>

<<elseif $Daggers == 1>>You already have a Dagger, do you want to pick up a spare?
        <<linkreplace " Yes">><<set $Daggers = 2>>You now have 2 Daggers.<<set $CountHands++>><</linkreplace>>
        <<linkreplace " No">>You leave the item.<</linkreplace>>
  <</if>>

<<elseif $CountHands >= 2>>
    <<if $Daggers == 2>>You already have two Daggers, your hands are full!

  <<elseif $Daggers == 1>>
      You already have a Dagger! Do you want to drop your other weapon and have 2 Daggers instead?
  <<linkreplace " Yes">>
  <<set $Daggers = 2>>
  <<if $Spears == 1>><<set $Spears = 0>>
  <<elseif $Maces == 1>><<set $Maces = 0>>
  <<elseif $ShortSwords == 1>><<set $ShortSwords = 0>>
  <<elseif $Warhammers == 1>><<set $Warhammers = 0>>
  <<elseif $Swords == 1>><<set $Swords = 0>>
  <<elseif $Axes == 1>><<set $Axes = 0>>
  <<elseif $Quarterstaffs == 1>><<set $Quarterstaffs = 0>>
  <<elseif $Broadswords == 1>><<set $Broadswords = 0>>
  <</if>>
  You now have 2 Daggers.<</linkreplace>>
  <<linkreplace " No">>You leave the item.<</linkreplace>>

  <<elseif $Daggers == 0>>
  What item do you want to drop to make room for the Dagger?
  <<if $Spears == 1>>
  <<linkreplace " the Spear">><<set $Spears = 0>><<set $Daggers = 1>>You drop your Spear and gain a Dagger.<</linkreplace>><</if>>

  <<if $Maces == 1>>
    <<linkreplace " the Mace">><<set $Maces = 0>><<set $Daggers = 1>>You drop your Mace and gain a Dagger.<</linkreplace>><</if>>

  <<if $ShortSwords == 1>>
    <<linkreplace " the Short Sword">><<set $ShortSwords = 0>><<set $Daggers = 1>>You drop your Short Sword and gain a Dagger.<</linkreplace>><</if>>

  <<if $Warhammers == 1>>
    <<linkreplace " the Warhammer">><<set $Warhammers = 0>><<set $Daggers = 1>>You drop your Warhammer and gain a Dagger.<</linkreplace>><</if>>

  <<if $Swords == 1>>
    <<linkreplace " the Sword">><<set $Swords = 0>><<set $Daggers = 1>>You drop your Sword and gain a Dagger.<</linkreplace>><</if>>

  <<if $Axes == 1>>
    <<linkreplace " the Axe">><<set $Axes = 0>><<set $Daggers = 1>>You drop your Axe and gain a Dagger.<</linkreplace>><</if>>

  <<if $Quarterstaffs == 1>>
    <<linkreplace " the Quarterstaff">><<set $Quarterstaffs = 0>><<set $Daggers = 1>>You drop your Quarterstaff and gain a Dagger.<</linkreplace>><</if>>

  <<if $Broadswords == 1>>
    <<linkreplace " the Broadsword">><<set $Broadswords = 0>><<set $Daggers = 1>>You drop your Broadsword and gain a Dagger.<</linkreplace>><</if>>

        <<linkreplace " None">>You leave your items unchanged.<</linkreplace>>
<</if>>
<</if>><</nobr>>


    Okay, I removed all the comments once I had the code that went to that section (there was enough code that the comments started making it hard to read everything). I really should have coded a section, tested it, moved on to the next section - but of course I didn't. I just wrote the whole thing and made some extra Passages to test it. That did work, but the less code to debug at once the better.

<<case "Dagger">>
<<nobr>>
<<if $CountHands == 0>>
<<set $Daggers = 1>>You pick up the Dagger.<<set $CountHands++>>

<<elseif $CountHands == 1>>
<<if $Daggers == 0>>
<<set $Daggers = 1>>You pick up the Dagger.<<set $CountHands++>>

<<elseif $Daggers == 1>>You already have a Dagger, do you want to pick up a spare?
<<linkreplace " Yes">><<set $Daggers = 2>>You now have 2 Daggers.<<set $CountHands++>><</linkreplace>>
<<linkreplace " No">>You leave the item.<</linkreplace>>
<</if>>


    So the above section is the easy stuff, you just pick up the Dagger, you get asked once if you want the spare. Notice that I have to remember the <<set $CountHands++>>, I'm adding a weapon so I need to remember to increase that tracker.
    Also, when comparing something with <<if>> you use TWO equals signs “==”, (two letters in “if”, two “==”) boy did I have to fix that a lot. (still do, someday I'll remember :)

<<elseif $CountHands >= 2>>
<<if $Daggers == 2>>You already have two Daggers, your hands are full!


    Again, easy

<<elseif $Daggers == 1>>
You already have a Dagger! Do you want to drop your other weapon and have 2 Daggers instead?
<<linkreplace " Yes">>
<<set $Daggers = 2>>
<<if $Spears == 1>><<set $Spears = 0>>
<<elseif $Maces == 1>><<set $Maces = 0>>
<<elseif $ShortSwords == 1>><<set $ShortSwords = 0>>
<<elseif $Warhammers == 1>><<set $Warhammers = 0>>
<<elseif $Swords == 1>><<set $Swords = 0>>
<<elseif $Axes == 1>><<set $Axes = 0>>
<<elseif $Quarterstaffs == 1>><<set $Quarterstaffs = 0>>
<<elseif $Broadswords == 1>><<set $Broadswords = 0>>
<</if>>
You now have 2 Daggers.<</linkreplace>>
<<linkreplace " No">>You leave the item.<</linkreplace>>


    Okay, here you have one Dagger and one other item, you're picking up a dagger. You decide you must have it, so I go through and set every other item's count to 0 with an <<if / elseif>> series. I DON'T increase $CountHands because here I am swapping items, not taking up a new ‘hand.’

<<elseif $Daggers == 0>>

What item do you want to drop to make room for the Dagger?
<<if $Spears == 1>><<linkreplace " the Spear">><<set $Spears = 0>><<set $Daggers = 1>>You drop your Spear and gain a Dagger.<</linkreplace>><</if>>
<<if $Maces == 1>><<linkreplace " the Mace">><<set $Maces = 0>><<set $Daggers = 1>>You drop your Mace and gain a Dagger.<</linkreplace>><</if>>
<<if $ShortSwords == 1>><<linkreplace " the Short Sword">><<set $ShortSwords = 0>><<set $Daggers = 1>>You drop your Short Sword and gain a Dagger.<</linkreplace>><</if>>
<<if $Warhammers == 1>><<linkreplace " the Warhammer">><<set $Warhammers = 0>><<set $Daggers = 1>>You drop your Warhammer and gain a Dagger.<</linkreplace>><</if>>
<<if $Swords == 1>><<linkreplace " the Sword">><<set $Swords = 0>><<set $Daggers = 1>>You drop your Sword and gain a Dagger.<</linkreplace>><</if>>
<<if $Axes == 1>><<linkreplace " the Axe">><<set $Axes = 0>><<set $Daggers = 1>>You drop your Axe and gain a Dagger.<</linkreplace>><</if>>
<<if $Quarterstaffs == 1>><<linkreplace " the Quarterstaff">><<set $Quarterstaffs = 0>><<set $Daggers = 1>>You drop your Quarterstaff and gain a Dagger.<</linkreplace>><</if>>
<<if $Broadswords == 1>><<linkreplace " the Broadsword">><<set $Broadswords = 0>><<set $Daggers = 1>>You drop your Broadsword and gain a Dagger.<</linkreplace>><</if>>


    Here comes the really fun part, you currently have 2 other weapons and you want to swap one for a dagger. So I need a bunch of <<if>>s to check what that other weapon is, then set it's count to 0 and the dagger to 1. First time I wrote this, I copied the code from above to do the weapon check - which was a mistake. Above I did an<<if - elseif>> series, but that whole series exits at the first true condition. Here I need to return 2 values/ changes, so each <<if>> has to be it's own thing. Again, I'm swapping items so I don't increase $CountHands.

    It looks so simple, it gave me so many headaches :(

    Okay, so now I can pick up and swap a dagger. Just a dagger. Now, I need to copy-and-paste this for each weapon and change all the variables to be the correct ones. Not really hard, but going to be tedious. Still, I've got some time. And I'm going to have to find a better way to do this, eventually...
After the great-copying-and-pasting I need to do basically the same thing for Backpack Items, though the code is going to be completely different of course.

Two quick side-notes...
I love how the code I started with (6 lines):

<<case "Mace">>
<<if $CountHands >= 2>>Your hands are full!
<<elseif $Maces > 0>>You already have a Mace!
<<else>>
<<set $Maces = 1>>You pick up the Mace.<<set $CountHands++>>
<</if>>


Has turned into (57 lines):

<<case "Mace">>
<<nobr>>
<<if $CountHands == 0>>
<<set $Maces = 1>>You pick up the Mace.<<set $CountHands++>>
<<elseif $CountHands == 1>>
<<if $Maces == 0>>
<<set $Maces = 1>>You pick up the Mace.<<set $CountHands++>>
<<elseif $Maces == 1>>You already have a Mace, do you want to pick up a spare?
<<linkreplace " Yes">><<set $Maces = 2>>You now have 2 Maces.<<set $CountHands++>><</linkreplace>>
<<linkreplace " No">>You leave the item.<</linkreplace>>
<</if>>
<<elseif $CountHands >= 2>>
<<if $Maces == 2>>You already have two Maces, your hands are full!
<<elseif $Maces == 1>>
You already have a Mace! Do you want to drop your other weapon and have 2 Maces instead?
<<linkreplace " Yes">>
<<set $Maces = 2>>
<<if $Daggers == 1>><<set $Daggers = 0>>
<<elseif $Spears == 1>><<set $Spears = 0>>
<<elseif $ShortSwords == 1>><<set $ShortSwords = 0>>
<<elseif $Warhammers == 1>><<set $Warhammers = 0>>
<<elseif $Swords == 1>><<set $Swords = 0>>
<<elseif $Axes == 1>><<set $Axes = 0>>
<<elseif $Quarterstaffs == 1>><<set $Quarterstaffs = 0>>
<<elseif $Broadswords == 1>><<set $Broadswords = 0>>
<</if>>
You now have 2 Maces.<</linkreplace>>
<<linkreplace " No">>You leave the item.<</linkreplace>>
<<elseif $Maces == 0>>
What item do you want to drop to make room for the Mace?
<<if $Daggers == 1>>
<<linkreplace " the Dagger">><<set $Daggers = 0>><<set $Maces = 1>>You drop your Dagger and gain a Mace.<</linkreplace>><</if>>
<<if $Spears == 1>>
<<linkreplace " the Spear">><<set $Spears = 0>><<set $Maces = 1>>You drop your Spear and gain a Mace.<</linkreplace>><</if>>
<<if $ShortSwords == 1>>
<<linkreplace " the Short Sword">><<set $ShortSwords = 0>><<set $Maces = 1>>You drop your Short Sword and gain a Mace.<</linkreplace>><</if>>
<<if $Warhammers == 1>>
<<linkreplace " the Warhammer">><<set $Warhammers = 0>><<set $Maces = 1>>You drop your Warhammer and gain a Mace.<</linkreplace>><</if>>
<<if $Swords == 1>>
<<linkreplace " the Sword">><<set $Swords = 0>><<set $Maces = 1>>You drop your Sword and gain a Mace.<</linkreplace>><</if>>
<<if $Axes == 1>>
<<linkreplace " the Axe">><<set $Axes = 0>><<set $Maces = 1>>You drop your Axe and gain a Mace.<</linkreplace>><</if>>
<<if $Quarterstaffs == 1>>
<<linkreplace " the Quarterstaff">><<set $Quarterstaffs = 0>><<set $Maces = 1>>You drop your Quarterstaff and gain a Mace.<</linkreplace>><</if>>
<<if $Broadswords == 1>>
<<linkreplace " the Broadsword">><<set $Broadswords = 0>><<set $Maces = 1>>You drop your Broadsword and gain a Mace.<</linkreplace>><</if>>
<<linkreplace " None">>You leave your items unchanged.<</linkreplace>>
<</if>>
<</if>><</nobr>>


    Second, the great-copying-and-pasting is going a lot easier by using a program called Notepad++. The 'find and replace' feature is making it a lot easier to convert the Dagger code into the other weapons.
    Notepad++ is a text editor designed for writing code.  You can open multiple files in the same program, good for tracking scattered code, it does "syntax highlighting" when it colors key words, which can help you see where you're missing or mis-spelling something, and it has a ton of other features.  I had been working in Twine itself to write all my code, but these last sections have gotten so big it's been a lot easier to work in Notepad++ instead.  Here's a screenshot...




Combat Capabilities 3 - Defining the capabilities


    The last time I worked on my "combat capabilities" idea it went a little off the rails.  Thinking on it some more, I really need to nail down better definitions of what each capability is supposed to do - and then figure out why that might be a better idea than "I hit it with my axe."  So, what are the capabilities?

⦁    Striking
⦁    Protecting
⦁    Grappling
⦁    Skirmishing
⦁    Buff/ Aid/ Assist
⦁    Spoiler/ Debuff
⦁    Ranged/ Archer/ Artillery
⦁    Leader/ Teamwork
⦁    Strategist/ Tactician
⦁    Controller

    I really need some better names too, so let's see if we can tighten up this list...

Strike
    Well, let's go ahead and start from "I hit it with my axe" :)  This is an easy and straightforward capability, doing damage to your opponent.  It's kind of the default that all others are measured by.

Defend
    Not getting hit is 'default action #2.'  Staying alive is always a good thing.  This is not just for oneself though, we need to remember that you can defend allies as well ('every Spartan protects his ally from the neck to the knee' - or whatever the exact line is from 300).  This is the weakest of the capabilities in a way, because it doesn't really do anything, it tries to prevent something.   Which is not glamorous, but may be essential depending on the circumstances.

Grapple
    So while the action of grappling is defined as 'putting your hands on a foe' I have thought of the effect as being to decrease every capability your foe has.  Your foe is trying to attack with his sword and shield, you move to grapple him, now he is going to have a hard time swinging that sword or blocking with that shield since you're right in his face; grabbing his shield, blocking his sword swings, and generally being a nuisance.
    Grapple seems to really be a "set up" capability - you are interfering with the foe's ability to act in order to set them up for another action, like a Strike (grab and hit/ bear-hug/ choke), Interfere (joint lock an arm, Interfering with the foe's ability to use that limb), Position (grab and throw) or Control (grab and punch them with their own fist ["stop hitting yourself']).  It doesn't seem like something you would do for it's own sake.

Position
    One definition I've seen of "tactics" is "having the right assets in the right place at the right time."  Position is about being at that right place, and also in the right state.  Being thrown to the ground is Position, so is kneeling for more stability and a better shot.  Creeping around the edge of the battlefield to backstab - or climbing up the giant's pant-leg to stab them somewhere vital - both Position.  This capability is for when you're not in the right place to do what you want to do.

Assist
    Helping someone else is like Defend, it's not really glamorous but it may be necessary.  This capability really comes into its own if there are things that are impossible to do alone.  If the monster has an AC/defense that is too high for any character to hit on their own, then you need to gang-up on it with some 'Assist's - which could be invaluable for "Solo or Boss" monsters that are meant to take on the whole party single-handedly.  All the Boss' stats may be too high for any one PC to effect or negate, so they need to team up to survive.  Does this need to be a separate capability or can you say that you can add half/ all of your capability to an ally who's doing the same action?  That's a good question.

Interfere
    Interfere is the flip-side of Assist.  While Assist increases an Ally, Interfere decreases a foe.  The difference is in targeting.  Assist helps one ally, but Interfere helps all allies.  You Assist one friend with a Strike, giving them a better chance to hit.  But if you Interfere with the foe's AC/ defense then you help every ally's Strike.
    So why Assist when you can Interfere?  Well, there would have to be a reason.  It seems logical that Interfere would be harder to do, cost more resources or have a lower chance of success.  It's also an argument for making Assist a 'default' action and Interfere a capability that would need to be bought somehow.

Bombard
    Melee and Ranged combat are similar at heart, but have enough different circumstantial modifiers that I think they need to be categorized separately - so Bombard is basically Strike but at range ("I shoot it with my bow").  This brings things like cover and 'shooting into a crowd' into play, which don't really apply to a strike.

Lead
    In my mind Lead is kind of a hybrid of Assist and Interfere.  The idea was that a player can start by using a Lead/ Leader action on one foe, that action would place a pool of points on that foe - then, any ally who acted after the leader can draw from that pool to increase any action.  So the Leader 'tags' Thug #1 with 4 points.  The next PC draws 2 points to increase her Strike, leaving 2 points on the foe.  Then the following PC draws the last 2 points to increase a Defend, which removes all the bonus points on that foe.  The benefit obviously is flexibility, Assist and Interfere are both targeted to something specific, you Assist a Strike or Interfere with Defend, while Lead lets each ally do whatever they need the most.

Read
    This capability is one that I want to include the most but have the hardest time figuring out how to do right.  Read is all about seeing what's coming.  Knowing how you foe is going to act, which should give you a big tactical upper-hand since you can then plan for how to best defend against or counter the foe's actions.  The devil for this is in the details, how much can you see and when can you see it - and then what exactly can you do about it?  But I have to admit I have always had a soft spot for the "smart guy" - the fighter who uses brains over brawn to win - so I really want to make this a cool option that does not seem to exist much in most games.

Control
    Moving in-between two foes then ducking so they shoot each other, using a spell of telekinesis to pull a shield out of a foe's hand, or a throwing a tanglefoot bag to lock a foe in place - all these are Control.  Either controlling a foe's actions, their target for an action, or denying them a choice of action.  This is one of the hardest capabilities because it can be the most powerful and the hardest to justify in the game world.  But it can create some really cool 'cinematic' moments and advanced tactics.


    One thing about this system is that it's focused on what happens to the target/ enemies/ other players.  Some "tactical" systems are built around the acting player - like "Power Attack" that gives the acting player a bonus to damage for a penalty to hit.  That kind of player-focus is what I want to get away from with this system, which is why the abilities are described and categorized the way they are.  I want each player to be focused on how her actions are effecting the group and the fight as a whole.
    These definitions give me a better way to look at actions, in a general sense.  Let's take that Tanglefoot Bag.  It is a ranged weapon, so it's a Bombard action to use.  If you target a foe's body the goop spreads all over them, sticking and hindering their actions (Grapple), if you target the foe's legs it locks them in place (Control, cannot Position).  This example also shows how different capabilities can interact - the Tanglefoot bag gives any character who can make a Bombard action/ capability the option to do a Grapple or Control - thus expanding their tactical space.  The old D&D 4th edition idea of "Marking" for the fighter could be something like: you can make a Strike, and apply that die roll as a Lead to that foe (or an Interfere (Strike) to any ally other than you).  Backstab = make a Position roll, and next turn add it to a Strike against an opponent you can flank that is vulnerable to critical hits.

    A big part of tactical combat is in setting up what is and is not possible, or likely.  If every opponent can be hit, why not always Strike?  If every attack can be defended, why not always Defend?  But if you mix it up - the Dragon's scales are too thick to penetrate with any of your weapons, now what?  Well, can we Assist/ Interfere to get the 'target number' within the possible range?  Can I Position to climb on it's back and stab it behind the ear? (I think it was the Dragon Age anime movie that had that move)  The Giant is swinging a tree-trunk bigger than you, you cannot Defend against it if it hits.  Well, can I Position to get out of the way, or Position + Bombard to "kite" it, back-pedaling and shooting?  Can the mage Control the Giant with telekinesis to make it's swings miss? (or Interfere/ Strike on the giant)  Can the Archer make a ranged attack to disarm it? (Control)  Can the party leader call out when it's going to attack, helping me dart in and out of range to stab it? (Lead or maybe even Read, or both)
    This is nothing new of course - good fights always take into account the tactical options of the combatants and the terrain; but I think that having a more explicit, clear system - like the capabilities descriptions and the combat capabilities map - would help both players and GMs to devise new strategies and interesting encounters.  Again, the idea is to expose the underpinnings that are really already in most games, just buried under the weight of individual ability descriptions (and sometimes buried under a mountain of numbers, stats and calculations).

    Here's a crazy scenario, off the top of my head:
    The party faces a dragon, and the leader Reads that the dragon's Defend is too high for any single player to overcome.  The players confer.  What, asks one fighter, if I stab it as hard as I can with my sword - and then the other fighter hits my sword with his two-handed great-hammer to drive it into the dragon?  The GM thinks, okay, I'll let you roll to Assist the second fighter's Strike - but you're now going to be disarmed.  They hit the dragon for some damage.  Well, says the thief, I can climb on it's back (Position) but it'll take me some time to find a soft spot to strike.  Hey, says the mage, what if I use my telekinesis to move the fighter's sword already in the dragon, to cause it pain.  Okay, says the GM, the mage can spend the spell slot and Interfere with the dragon trying to throw off the thief.  Or wait, says the mage, if the dragon's got a bit of metal in him, can I target that with my lightning bolt spell to bypass it's Defend?  Hey, says the thief, wait until I'm off it's back before you electrocute it will you!  The GM thinks about that...

    Anyways, just a random thing that popped into my head while I was writing this.  I will have to keep working on this idea...

Friday, August 11, 2017

Converting Lone Wolf to Twine and SugarCube - Part 4 - Dealing with Equipment



     Our discipline array was pretty simple, just a few things to set and keep track of, none of which are going to change over the course of the game. Equipment is going to be a lot harder. There are multiple equipment slots, different items that do different things, and the player is going to pick up, put down, and use them at random intervals. I'm not actually looking forward to this part...

     Here are the rules from the book:

Equipment


You are dressed in the green tunic and cloak of a Kai initiate. You have little with you to arm yourself for survival.
All you possess is an Axe (note under Weapons on your Action Chart) and a Backpack containing 1 Meal (note under Meals on your Action Chart). Hanging from your waist is a leather pouch containing Gold Crowns. To find out how many, pick a number from the Random Number Table. This number equals the number of Gold Crowns you possess at the start of the adventure. (Note the number in the Belt Pouch section of the Action Chart.)
You discover amongst the smoking ruins of the monastery, a Map of Sommerlund (note under Special Items on the Action Chart) showing the capital city of Holmgard and the land of Durenor, far to the east. You place the Map inside your tunic for safety.
You also find one of the following:

• 1 = Sword (Weapons)
• 2 = Helmet (Special Items). This adds 2 ENDURANCE points to your total.
• 3 = Two Meals (Meals)
• 4 = Chainmail Waistcoat (Special Items). This adds 4 ENDURANCE points to your total.
• 5 = Mace (Weapons)
• 6 = Healing Potion (Backpack Item). This can restore 4 ENDURANCE points to your total, when swallowed after combat. You only have enough for one dose.
• 7 = Quarterstaff (Weapons)
• 8 = Spear (Weapons)
• 9 = 12 Gold Crowns (Belt Pouch)
• 0 = Broadsword (Weapons)

To discover which of the above you find, you must pick a number from the Random Number Table and find the corresponding article on the list. Note this on your Action Chart, under the heading given in brackets, and make a note of any effect it may have on your ENDURANCE points.

How to Carry Equipment


Now that you have your equipment, the following list shows you how it is carried. You don’t need to make notes but you can refer back to this list in the course of your adventure.
• 1 = Sword—carried in the hand.
• 2 = Helmet—worn on the head.
• 3 = Food—placed in the Backpack.
• 4 = Chainmail Waistcoat—worn on the body.
• 5 = Mace—carried in the hand.
• 6 = Healing Potion—carried in the Backpack.
• 7 = Quarterstaff—carried in the hand.
• 8 = Spear—carried in the hand.
• 9 = Gold Crowns—carried in the Belt Pouch.
• 0 = Broadsword—carried in the hand.

How Much Can You Carry?


• Weapons - The maximum number of weapons that you may carry is two.
• Backpack Items - These must be stored in your Backpack. Because space is limited, you may only keep a maximum of eight articles, including Meals, in your Backpack at any one time.
• Special Items - Special Items are not carried in the Backpack. When you discover a Special Item, you will be told how to carry it.
• Gold Crowns - These are always carried in the Belt Pouch. It will hold a maximum of fifty crowns.
• Food - Food is carried in your Backpack. Each Meal counts as one item.
• Any item that may be of use and can be picked up on your adventure and entered on your Action Chart is given capital letters in the text. Unless you are told it is a Special Item, carry it in your Backpack.

How to Use Your Equipment


Weapons
Weapons aid you in combat. If you have the Kai Discipline of Weaponskill and the correct weapon, it adds 2 points to your COMBAT SKILL. If you enter a combat with no weapons, deduct 4 points from your COMBAT SKILL and fight with your bare hands. If you find a weapon during the adventure, you may pick it up and use it. (Remember you can only carry two Weapons at once.) You may only use one Weapon at a time in combat.

Backpack Items
During your travels you will discover various useful items which you may wish to keep. (Remember you can only carry eight items in your Backpack at once.) You may exchange or discard them at any point when you are not involved in combat.Special ItemsEach Special Item has a particular purpose or effect. You may be told this when the item is discovered, or it may be revealed to you as the adventure progresses.

Gold Crowns
The local currency is the Crown, which is a small gold coin. Gold Crowns can be used on your adventure to pay for transport, food, or even as a bribe! Many of the creatures that you will encounter possess Gold Crowns, or have them hidden in their lairs. Whenever you kill a creature, you may take any Gold Crowns that it has and put them in your Belt Pouch.

Food
You will need to eat regularly during your adventure. If you do not have any food when you are instructed to eat a Meal, you will lose 3 ENDURANCE points. If you have chosen the Kai Discipline of Hunting as one of your five skills, you will not need to tick off a Meal when instructed to eat.

Healing Potion
This can restore 4 ENDURANCE points to your total when swallowed after combat. There is only enough for one dose. If you discover any other potions during the adventure, you will be told then of their effect. All Healing Potions are Backpack Items.



     The biggest problem is that there are so many ways to do inventory. I'm going to try to come up with a few different systems, so I can show you guys what's possible, and so I can find what feels the best/ easiest to me.

     Let's start with one of the simplest to track, money.
     You start with a belt pouch that holds your Gold Crowns. It starts with a random number between 0 and 9. It can hold a maximum of 50.

    One way I came up with to do the gold involved including another passage. I'm going to write this in a way I've seen before - since this code goes across multiple Passages, I'm putting the Passage titles after “::” and then the code for that Passage. (ex, ::Passage1 code ::Passage 2 code ::etc ::etc) - I believe it's called 'Twee notation'...

::Inventory Tracker
<<set $Gold = 0>>
Let's go [[Find Stuff]]

::Find Stuff
<<set $newgold = random (1,10)>><<include [[Change Gold]]>>

::Change Gold
<<nobr>>
<<linkreplace "You see $newgold Gold Crowns.">>
You pick up $newgold Gold Crowns,
<<set $Gold = $Gold + $newgold>>
<<if $Gold > 50>>
<<set $Gold = 50>>
 but your Belt Pouch only holds 50 Gold Crowns,
<</if>>
 you now have $Gold Gold Crowns.
<</linkreplace>>
<</nobr>>


     So we tell the player that there is money to be had...


     When they click on that, they pick up the money and we tell them their new total...


     But the limit is 50, so we let them know if they go over that and drop any extra...



     This is one way to do inventory, as well as other stuff, by using a Passage to store the code and then calling that Passage when needed. In this case we define our gold in the "Inventory Tracker" Passage, this is going to be the one place we put everything the player is carrying (once we finish adding everything else). From there we go to another Passage, which would be somewhere in the story but for the moment is a test area titled “Find Stuff.” Then we have something neat, instead of writing the code to add to the player's gold, we include another Passage. “Change Gold” is a Passage that just has the mechanics of handling the gold, we set a variable of how much gold to add and it does all the rest. That way, instead of re-writing the code to add gold in every Passage, we just set our variable and reference the “Change gold” (heh, did you see that, I mixed the cases in that last title - which would be an error, I should have said “Change Gold”) Passage. That will cut down on the amount of typing we have to do.
     Speaking on cutting down typing, re-reading the SugarCube documentation (yet again, I will say that I think Harlowe has the better online reference - but I'm committed to SugarCube at this point) made me hit myself realizing there is the <<linkreplace>> macro. Since that does everything my clumsy <span><<click>><<replace>> macros were doing, in fewer characters, I'm going to start being smart and using that instead (again, you're riding along on my learning process).
So, in the “Change Gold” Passage we're taking the variable for how much gold to add, adding it, but our belt pouch does have a maximum of 50, so we we're checking to make sure we don't go above that, and then telling the player how much new gold they have. Easy. Well, okay - this works to add gold, but what if we need the character to spend it or to lose it? We'll have to fiddle with things for that.
     Let's go with the idea of losing gold, there is no way to buy anything in the book (and that's a bit more complicated, we'll tackle it next). So we could make another Passage just for losing gold, but it's easier to keep this one and just check if the $newgold value is positive or negative. If it's negative we'll change our description text a little, and since you can't go below 0 gold we'll set that as a bottom-limit. Code looks like this:

::Change Gold
<<nobr>>
<<if $newgold >= 0>>

<<linkreplace "You see $newgold Gold Crowns.">>
You pick up $newgold Gold Crowns,
<<set $Gold = $Gold + $newgold>>
<<if $Gold > 50>>
<<set $Gold = 50>>
 but your Belt Pouch only holds 50 Gold Crowns,
<</if>>
 you now have $Gold Gold Crowns.
<</linkreplace>>

<<else>>

<<linkreplace "You lose $newgold Gold Crowns.">>
You have lost $newgold Gold Crowns,
<<set $Gold = $Gold + $newgold>>
<<if $Gold < 0>><<set $Gold = 0>><</if>>
 you now have $Gold Gold Crowns.
<</linkreplace>>

<</if>>
<</nobr>>


Oh no, losing money...


New total...


If we lose big-Vegas-style...


We still can't go below 0 (no debt allowed in this fantasy world)...


     How do you get rid of the minus sign from the $newgold variable text when you lose gold? I don't know, a quick check didn't turn up any easy answers - so frankly I'm going to ignore it for now. This all looks simple for you guys reading along (I'd imagine), and I'm sure it really is easy if you know what you're doing - but this is a chore for me (already been down a couple of dead-ends while working on this section, I tinker a lot while I work on this). I'm going to stay focused on getting the numbers to work right and I'll come back to this in my final presentation cleanup.

     Okay, we don't need it for the book, but how would you buy something? In essence this is the same basic system, take your gold and subtract the price. You also have to add another variable, for the thing you're buying, and you have to check to make sure you have enough money to buy it in the first place.
     Could we use this same Passage? Well...I think we could. We could add another variable, $IsBuying, and change the code a little (like add another if-block to check the price and give you the item) and I think that would work. This sounds like it would be better in it's own Passage though,so let's make a new one and play with some code.

     Okay, well you usually buy things from the store, so let's make a Store Passage. It's possible to ask the player how many items they want to buy and get them in bulk, but it's easier to have one “Buy Item” Passage that goes back-and-forth to the "Store" Passage (I think). Buying only one thing is boring, so let's add Health Potions and Swords to our inventory...

New code for the Inventory Tracker and find Stuff Passages.

::Inventory Tracker
<<set $Gold = 0>>
<<set $HealthPotions = 0>>
<<set $Swords = 0>>

You are currently carrying:

$Gold Gold Crowns.
$HealthPotions Health Potions
$Swords Swords


Let's go [[Find Stuff]]

::Find Stuff
<<set $newgold = 20>><<include [[Change Gold]]>>

Now that you have some money, let's [[Go to the Store->Store]]





We have our code to get gold, which we'll re-use and add the link to the store.



And we're going to need some money to spend at the store...



So we arrive at the store. First, here's the code block for this Passage.

::Store
You are at the store.
You have $Gold Gold Crowns.
You have-
$HealthPotions Health Potions.
$Swords Swords.

The store has the following for sale-
Health Potion - 5 Gold Crowns (heals 4 Endurance)
Sword - 10 Gold Crowns (increases Combat Skill if proficient)


[[Buy a Health Potion->Buy Item][$buyitem = "Health Potion"]]
[[Buy a Sword->Buy Item][$buyitem = "Sword"]]


     So, we show the player his inventory at the top, then we have the list of things to buy and prices and game effects. Then the links to buy items. Now, this is another one of those places where there are lots of different ways to do the same thing. What I'm going to do here is pass a variable that says what item the player is buying, then go to a “Buy Item” Passage. That Passage will check the item, buy it, then come back to the shop, which will update the inventory at the top.



So, our “Buy Item” Passage.

::Buy Item
<<switch $buyitem>>
<<case "Health Potion">>
<<if $Gold - 5 < 0>>
You do not have enough Gold Crowns to afford a Health Potion.
<<else>>
<<set $Gold = $Gold - 5>>
<<set $HealthPotions++>>
You buy a Health Potion for 5 Gold Crowns.
You now have $Gold Gold Crowns.
You now have $HealthPotions Health Potions.
<</if>>
<<case "Sword">>
<<if $Gold - 10 < 0>>
You do not have enough Gold Crowns to afford a Sword.
<<else>>
<<set $Gold = $Gold - 10>>
<<set $Swords++>>
You buy a Sword for 10 Gold Crowns.
You now have $Gold Gold Crowns.
You now have $Swords Swords.
<</if>>
<</switch>>

<<return "Back to shopping">>


     We're going to use a new macro, <<switch>>; which looks at a variable and does different things depending on that variable's value. We could do the same thing with a bunch of nested <<if>> macros, but this is easier and quicker to type. So we'll look at our $buyitem variable and determine what item it is, how much it costs, and update our inventory with it. Since this is all in one Passage, again we can call it from anywhere - but it does mean every merchant will sell things for the same prices (though we can have them sell different items). I'm okay with that for right now; trying to make a more dynamic system that could handle any item and price combo did not work out too well - so I'll take what I've got and make a note to research this further down the road :)









And, of course, if we can't afford something it'll tell us...


     Well, we're getting the beginning of an inventory system here. We have money, can gain and lose money, and we can shop for different items. Not too bad, not too bad at all. But, of course, what we need is quite a bit more complicated than that :(

     So with what I've got right now I can make a variable for every item in the game, and track how many of each item the player has. There's a catch though - each item uses a certain ‘inventory slot’ or container. Remember, you can only have 2 weapons, 50 gold crowns, 8 backpack items, and such. So before we let the player go and buy an item, or pick one up, we need to know if they have enough room for it. How to do that?
     Maybe we can use another of those <<switch>> macros,now that we're thinking of them?  Stay tuned for part 5...


Wednesday, August 9, 2017

Combat Capabilities Thoughts - Part 2 - The Duel

[Ed Note- My idea for the Combat Capabilities Map I posted before keeps expanding, the following came to me while I was just randomly thinking about the idea.  This is literally my stream-of-consciousness writing...]

    Shardavaren el'Meschal de Torrays expected this to be an easy assignment.  As a newly-elevated Queen's Own Shar, along with her mentor Eldavara el'Royans de Torrays, was sent to the neighboring Half-Ogre village of Slugfall (their quaint name for it) to escort home a Queen's Merchant.  The Half-Ogers were a warlike people, barbarians really, but they had been at peace with the Realm for as long as anyone could remember.  Lately Goblins had been spotted in the Shadow Forest near the village, so the Half-Ogers had been hunting their hated cousins in the woods - which left the roads open to bandits.  No one expected there to be any trouble, and certinly trouble would stay away from two of the Queen's Own.
    Of course, the road didn't turn out to be the problem - the village did.  Unbeknownst to the Merchant his son was Mageborn, and of course the boy's latent magic decided that the middle of a village of creatures who feared and hated magic would be the ideal place to manifest themselves.  The only sopt of fortune, if you could call it such, was that Sharn and Eldavara had arrived the evening after items had started moving on their own.  It took some very fast talking to try to soothe the Half-Ogers, and the final decision was not exactly ideal - at least as far as Sharn was concerned.
    The Half-Ogers killed any of their own with magic, which was what they wanted to do to the poor, frightened boy.  They knew that the Realm used magic though, so Eldavara set out to convince them that the boy would be taken back and safely contained.  That didn't quite work, there was some sort of behind-the-scenes maneuvering here that Sharn couldn't make out, and the Half-Ogers continued to press for killing the boy, and even started talking about adding his father for good measure.  Finally, Eldavara appealed to their belief in their gods, and managed to arrange a duel.  She argued that the gods (the Half-Oger's deities known for enjoying feats of prowess and contests of strength) must have brought the boy and the Queen's Own here at the same time to show the Half-Ogers that their allies could defeat any dark magic that might threaten both people.  It was clever, and it worked.
    Then, Eldavara sized up the Half-Oger's champion and declared that Sharn could handle the duel herself.
    Thus, Sharn now found herself stripping off her mail armor in the dawn's light, breath steaming in the chill of autumn, hoping that she didn't either embarrass herself or get an innocent boy killed - and wasn't a hundred percent sure which scared her more.  The fight itself was not going to be a problem, it was an honor-duel, to three touches and not blood.  Stepping into the circle (which the half-Ogers kept permanently for such occasions) and facing off against the tall, twisted brute of a man-thing she said a silent prayer to The Lady and started formulating a plan...


    The Combat Capabilities Map originally started as an idea for a party of characters - how to help show visually how each character fit into an overall strategy, and not just what specific actions they were taking.  But I wanted the capabilities to cover broad, almost "universal," types of combat actions; so it seemed logical that you could also apply the CCM to a single character.  Another thing was that I wanted this to be 'system neutral' at first, something that any game could use - but then I started thinking that most games are so focused on individual turn-based actions that it didn't seem like this was something you could just drop on top of an existing combat framework.  So, I started thinking about how to create a simple set of rules to go with the CCM.  I want something "rules-light" because most of the player's time should be spent considering what actions to take and not crunching numbers.
    Here, then, is the next evolution in the CCM concept.  It is still rough, horribly, embarrassingly rough - but I'm going to need to "think on paper" to develop this into something actually playable.  Along those lines, I'm going to describe our heroine, Sharn, and "play out" her duel described above.

Making A Character
    Sharn is going to be a new character, at a decent but lower power level.  She's a "smart" fighter, one who uses insight and speed more than brute strength.  So let's start making up some attributes and numbers and see what happens :)

Attributes
Physical:
  Power +1  Finesse +2
Emotional:
  Passion +2  Stability -1
Mental:
  Focus +2  Coherence 0

    Let's say that "average" is 0.  Power is like strength, it's the ability to generate and direct raw physical force.  Why not just call it 'strength'?  Because I want to make things sound different for now (which will likely change as the idea evolves, fancy terms for fancy terms' sake is not a good design principle).  At +1 Power Sharn is fit, athletic and in good shape.  Finesse is dexterity and reflexes, with +2 she's very nimble.
    I like the idea of separating emotional attributes from mental ones, heart and mind seem to be different forces on many people, and push them in different ways.  With a Passion of +2 she's very volatile, with Stability -1 she sometimes goes too passionate, and her strong feelings can lead her to make poor choices.
    Focus is mental power, the ability to concentrate and anaylze and deduce.  Coherence is a general awareness, and the ability to recognize and react to things around the character.  The high Focus means she has a laser-like awareness, but the average Coherence means she sometimes concentrates so much she gets blind-sided.

Capabilities
Fighting - 3 Combat Actions
  d8:  Tactician
  d6:  Protecting, Skirmishing
  d4:  Debuff, Striking
  +1/CA (stacking) for any action
 
    I'm thinking that we want default characters to be versatile, with at least a few capabilities.  I'd say that all characters get 3 Combat Capabilities, one at d6 and 2 at d4.  "Fighter" classes (or combat-focused characters) would get 5, 1 at d8, 2 at d6 and 2 at d4.  This way everybody has something they are best at, but also some other options to prevent (hopefully) the "I hit it with my axe" syndrome.
    Sharn is very much more a support character.  Her Striking, to directly damage in melee, is only a d4.  Skirmishing is about maneuver, getting in place to set up an attack or another action (like the Thief's iconic "sneak attack"), and at d6 it's respectable, so it can also be used offensively (I'm working on exactly how).  Her defense, Protecting,is also a solid d6.  Her best ability at d8 is Tactician, which helps her see how the battle is going to unfold.  And her last minor ability is Debuff at d4, letting her reduce an enemy's effectiveness.  Her blend of capabilities was meant to make a fighter who was not the stereotypical toe-to-toe slugger but someone who was smart and mobile.
    Each turn you spend Combat Actions (CA) on what capabilities you want to use.  1 CA = 1 die of that capability's type, or you can spend 1 CA to get a single +1 to any capability (or stack it with an existing die or itself).  The +1 default lets any character try anything, even though it might not be a lot (but hey, sometimes a fight comes down to just a point or two of difference).

Special Abilities
Passive:
  Master Parry - reduce 1 Striking die by 2 pts each turn
Active:
  Riposte - any Protection dice not countered become free attacks at -1 die type
Combo:
  Wave-Rider - spending only Skirmishing and Protection dice for one round gives a bonus Striking die the same type as the Skirmishing die on the next round.

    I was thinking there would be 3 kinds of abilities: Passive ones would be "always on," doing something each turn for free.  "Active" abilities change how the dice normally work, giving the fighter's capabilities different effects from the default anyone can use (and while Active abilities are supposed to always be better, a character could always choose to just do the default if needed).  "Combo" abilities would trigger something special if the dice were spent/used in a particular way.
    Sharn's "Master Parry" passive show's how she's defense-minded, always keeping her guard up.  The "Riposte" active ability means that if she has more Protection dice then the enemy's Striking attacks, she can turn the extras into attacks, but as smaller dice.  So her base d6 Protecting dice become only d4 Striking Ripostes.  "Wave-Rider" (from her 'Water-Form' school of fencing) let's her fall back, avoiding attacks and moving only, to gain an extra strike the next round (this bonus would be at d6 Striking, the same as her Skirmishing).

    With those three things we now have a character.  Let's play around with it and see what happens.  First though, we need an opponent if we're going to have a duel...


Sizing up the opposition
    Okay, so there's a big question in combat, and it is really important in a more tactical system like the one I'm trying to make here: how much is obvious and how much do you have to discover "in play"?
    A big part of tactics is not just in the choices that one can make - but also in the information one has to base those choices on.  If you knew everything you would have a huge tactical advantage, while knowing nothing makes every decision just a random throw of the dice (figuratively if not literally).  In-between somewhere is the balance line of what seems reasonable.  But how exactly to draw that line?
    I'm thinking that there should be 2 things that are "free" information: the Physical stats and the highest Capability.  Physically it doesn't seem to be unreasonable that you can look someone over and get a realistic feel for how powerful or nimble they are.  This would be for the "base stats" only, and special modifiers like magic or cybernetics might be hidden.  But I think each character should have at least a basic sense of other character's physical capabilities.  I also want to say that the highest combat capability would also be something that could be observed and deduced.  If a character's focus is Striking, well form follows function so they should have something about the way they stand, move, the weapons and armor and such they have, that would strongly suggest that.  If a character had more than one capability at the same die type, then the character would choose just one to reveal.
    These 2 things would also match the 2 points Sharn has in Focus, which matches with possibly making this Attribute-based, which I like the idea of - so let's see those 2 things about our enemy...

Half-Ogre Brute
Attributes                    
Physical:
  Power +3  Finesse +1
Capabilities 
  d8:  Striking

    Being Half-Orge it's not much of a surprise that he has a high Power, he still looks pretty nimble with +1 Finesse - he's no slow, hulking brute.  And his muscles and temperament make Striking a logical capability to be one of his highest.


Initiative
    So who goes first?  This is one of those foundational combat questions and sometimes a hard one to answer.  Well, it's always a hard one to answer.  There are so many ways to decide the turn order, and each adds a subtle to bold flavor to fighting.  I don't like the individual initiative roll that D&D/ Pathfinder uses.  I also don't really want to have different speeds for different weapons/ actions - that adds a lot of overhead tracking extra numbers.  Instead, I want to use the Combat Capabilities Map itself to track initiative.
    There are 2 types of initiative/ turn order, and they depend on how the fight starts.  If a fight starts at close-quarters (both parties within just a few feet of each other, close enough they could make it to the other side in 1 round) then combat goes from the inside-out.  First all Striking, Protecting and Grappling is resolved.  Next all Skirmishing, Buff and Debuff.  Last are Ranged, Leader, Tactician and Controller.  Then the next turn starts and repeats the same order.
    However, if a fight starts at a distance, or when both sides have time to see and prepare, then combat goes from the outside-in.  First are Ranged, Leader, Tactician, Controller.  Then Skirmishing, Buff and Debuff.  Last Striking, Protecting and Grappling.  Then the next turn goes in the same order.
    I do have some other weird ideas for how to do initiative - but let's stick with this system for our brainstorm session here.  And since this is a ritual fight between Sharn and the Brute, they both have plenty of time to size each other up so we're going to go from the outside-in.

Fight!
    Okay, let's begin round 1 of combat.
    First, everybody decides where they want to put their dice/ spend CAs.  Sharn decides to put 1 die in Tactician, 1 in Protecting and 1 in Striking.  She's hoping the Tactician re-rolls can let her lower the Brute's Striking or Protecting as needed.  Once she and the GM indicate they're ready, they put down their dice on the appropriate boxes.  The Brute is going to put 2 dice in Striking and 1 in Protecting.  Sharn also discovers that he has d6s for Protecting.  Placed dice have not been rolled, so they have no value yet.
    Going outside-in initiative means Sharn rolls her Tactician d8 first.  She gets a 3, and tactician uses her Focus, for a +2 and final score of 5.  Every 2 points gives her 1 re-roll, and she has to select one character to target - which is easy since she's only fighting the one Brute.
    Next, all the Striking and Protecting dice get rolled.  Sharn gets a 3 Protecting and 2 Striking - both are modified by her Finesse (Protecting always is and her Striking is because she's using a rapier, a light sword) for totals of 5 Striking and 4 Protecting.
    The Brute rolls 8 and 1 for Striking and 1 Protecting.  His Striking is modified by Power (for his large club) and Protecting by Finesse; so his final totals are  11 and 4 Striking, 2 Protecting.  Sharn decided to use one of her re-rolls on his highest Striking, which comes up a 6.  she uses the last re-roll on it again, but it comes up another 6.  So he has 9 and 4 Striking - then her Master Parry ability reduces those to 7 and 2.  Her 4 Protecting isn't enough to stop the 7, however everybody gets a base "Dodge" equal to their Finesse (so even if you don't use any Protecting dice you still have a chance not to get hit).  Shar's Finess of 2 matches the lower attack, so she'll Dodge it (have to roll over to hit).  Normally her Protection of 4 would reduce the 7 Striking to just 3 damage, but we're not counting hits (both are fighting for honor so it's assumed they're pulling their blows).  So Sharn is going to end up taking 1 hit, and the duel will end when someone takes 3.
    Sharn, however, gets in a hit herself since her Striking of 5 beats the Brute's Protecting of 2.  So they're tied at 1 hit each.

Round 2
    Tied with hits, Sharn decides to go on the defensive and use her Combo ability.  She's going to go 1 Skirmishing and 2 Protecting.  Both sides place dice and the Brute is using his Combo as well, his All-Out Attack let's him place 2 dice together in a single attack (normally each die is a separate action) but he has to do all Striking for that turn, so he's going 3 Striking dice, confident that he can get in at least 1 hit.
    Sharn's Skirmishing dice go first, she rolls a 5. Skirmishing dice work kind of like hybrid Protecting and Grappling dice, the number rolled is subtracted from any Striking dice, as evenly divided as possible across all the attacks.  Skirmishing uses Coherence, which is a 0 for Sharn.  Her Protection dice come up 1 and 4, with her finesse they're 3 and 6.
    The Brute's first attack is 2 dice together, but still just once for her Power bonus, for rolls of 3 and 5, plus 3 Power makes 11 total.  His second attack rolls a 7 for 10 total.
    Sharn's Master Parry lowers his attacks to 9 and 8.  Her Skirmishing of 5 divides into 3 and 2, lowering his attacks to 6 and 6.  her Protecting of 6 will stop one attack, but her Protection of 3 isn't enough to stop the other, so she takes a second hit - the Brute still has only 1 hit.

Round 3
    Sharn is now 1 hit away from losing, but after her last turn she gets a bonus Striking die at d6. She needs to get in 2 hits, and not take any, to win.  So does she go aggressive, perhaps 2 Striking and 1 Protecting hoping to get in the hits and with some luck avoiding his attacks?  Or play it more cautiously, 2 Protection to block his attacks and 1 Tactician to force some re-rolls to try and sneak in the bonus Striking?  Or play it down the middle and go Tactician, Protection, and 2 Striking - really hoping for some lucky rolls or re-rolls?
     In the end caution seems like her best bet, so she places 1 Tactician, 2 Protection and 1 Striking.  The Brute decides to try and overwhelm her defenses with 3 Striking, sure he can land at least 1 blow and finish the duel.
    Sharn's Tactician die comes up 3, for 5 total.  Her Protection dice total 6 and 8.  Her Striking totals 5.  The Brute's Striking totals are 7, 6 and 9.  She has him re-roll his highest Striking, but he rolls an 8 (11 total) and when she has him re-roll again it's another 8 (11).  So Sharn stops 2 of his attacks, and gets in one of her own, but one of his attacks gets through and she loses 3 touches to 2.

[Okay, so I was literally making up these "rules" while I was writing this.  It is a bad sketch, but there are a few things that came to me.  While I like the simplicity of only 1 die per action, and small numbers, that does make them very swingy.  I was actually rolling dice for all the examples, just to see how it would go.  Also, having individual actions / attacks made it too easy to 'dog-pile' actions to get around your opponent's defenses - need to re-work that.  In all I have to say that this is a mess (though I do like the random story and character that came from nowhere), but I still think there's something worthwhile in here.  I'm going to keep playing around with the idea, this was just a little window into the random way my head works :) ]

Music I Write To - Disturbed