TUTORIAL 1: Making a weapon
Coming up with an idea
New monsters are probably what we would like to have most in Kerkerkruip, but monsters are difficult. So we’ll start by doing something that is simpler: making a new weapon.
Now, before we start coding, we need to come up with a good idea. What we want to have is a weapon that is different from the weapons that are already in the game; and that is different in a way that creates interesting tactical choices. (Tactical choices are not the only reason to put something in the game, but it’s a very important one.)
I suggest we implement “the dagger of the double strike”, which has the following characteristics:
- It is a low-damage weapon. Without a special ability, it would be among the worst weapons in the game.
- If you miss with the dagger of the double strike, you immediately strike another blow at your enemy. (Once only; this second strike no longer benefits from any concentration bonus.)
This weapon would be bad against opponents with damage reduction, such as the ravenous armadillo; but it would be good in cases where hitting our opponent is more important than dealing a lot of damage, for instance because we need to break the opponent’s concentration.
The dagger kind
The best way to start coding a new item is by looking at the code of an existing item. All weapons, and in fact almost everything the player can carry around, is found in the extension called “Kerkerkruip Items”. So we open up this extenion, and search for a dagger. First, we’ll find the code that defines daggers in general, which reminds us that daggers get better attack and damage bonuses from tension. We also find this numerical information:
The damage die of a dagger is usually 3.
The weapon attack bonus of a dagger is usually -1.
The dodgability of a dagger is usually 3.
The passive parry max of a dagger is usually 1.
The active parry max of a dagger is usually 1.
The weapon damage bonus of a dagger is usually 0.
What does that mean? You can find all of this in the ATTACK manual, but let’s review it.
- The damage die is the size of the die that is rolled to determine damage. A damage die of 3 means that the basic damage is a random number between 1 and 3; a damage die of 6 that the basic damage is between 1 and 6, and so on.
- The weapon attack bonus is a bonus you receive to your attack roll.
- The dodgability is the attack penalty you will get when you attack with a weapon and the defender dodges.
- On the other hand, when your opponent parries, you will get an attack penalty equal to either the passive parry max of your weapon, or the active parry max of your opponent’s weapon, whichever is lower. For the example of the dagger: it’s easy to parry a dagger (so you could get up to a 3 attack penalty if the opponent parries), but it’s not easy to parry with a dagger (so someone using a dagger to parry will never give his opponent more than 1 attack penalty).
- The weapon damage bonus is a bonus to the damage you do.
It’s good to know this stuff, because we might want to tweak our dagger of the double strike.
A basic dagger
Looking further, we find the code for the gorgeous dagger, one of the simplest items in the game.
[code]Section - Gorgeous dagger
The gorgeous dagger is a minor dagger.
The gorgeous dagger is civilised.
The gorgeous dagger is iron.
The description of the gorgeous dagger is “Adorned with gold and a large emerald at the end of the hilt, this dagger is not only beautiful, but also perfect for precise attacks in tense situations. The decadence of its design proves it to be of Yahvinnean origin.”.[/code]
Here we see a couple of things. First, items should be declared as being either “minor”, “major”, “epic”, “special”, “unique”, or “non-treasure”. Non-treasure is the standard, and anything that is non-treasure will not be placed in the dungeon by the treasure generation rules. Special and unique aren’t really in use yet, so let’s not worry about them for now. This leaves us with minor, major, and epic. As the names suggest, minor items are the least powerful, while epic items are the most powerful. In addition, epic items should change your playstyle significantly when used. Examples of minor items are the essence of rage, the tormenting necklace, and the fearsome axe. Examples of major items are the executioner’s axe, the magical spade, and the boots of the war dance. Examples of epic items are the cloak of shadows, the glass cannon, and the essence of addiction.
Second, any item should have a “mood”. The moods are civilised, religious, barren, deathly, elemental, magical, alchemical and non-mood. Moods have no effect in play, but they ensure that items are more often placed in rooms with the same mood, that is, rooms where they thematically belong. For instance, Drakul’s lifeblood (a deahtly epic item) will be found in the Crypt (a deathly room) more often than in the Temple of Aite (a religious room).
Third, we should give the item a material. The materials are iron, silver, paper, cloth, wood, leather, flesh, glass, stone, dragon skin, radiance, adamant, and vapour. Materials are already used for a couple of things (for instance, calculating how fast something dissolves in the stomach of the armadillo), and I have bigger plans with them in the future.
Knowing this, we can now write down the basic definition of our dagger.
[code]Section - Dagger of the double strike
The dagger of the double strike is a major dagger.
The dagger of the double strike is civilised.
The dagger of the double strike is iron.
The damage die of the dagger of the double strike is 1.
The description of the dagger of the double strike is “The dagger looks dull and far from dangerous. But appearances deceive, for this weapon has been imbued with a dangerous magic.”.
The special weapon info of the dagger of the double strike is “; allows its wielder to strike again immediately if the first attack did no damage[run paragraph on]”.
[/code]
Our dagger has an atrocious damage output of 1 damage; though concentration and tension can increase this. This makes it perhaps the worst weapon in the game, except for the very powerful ability we haven’t programmed yet. That ability (a second chance to break your enemy’s concentration!) is probably so good that I have decided to make it a “major” item. If we find out in practice that it isn’t good enough, we can either lower it to a minor item or increase its usefulness in some other way.
I’ve also used the “special weapon info” property to explain the dagger’s power in more technical detail to the player.
Testing our dagger
We should now save the extension in which we put the code (this is crucial, otherwise Inform will use the unsaved version), start the game, and use the cheat command “purloin double strike”.
Well, the description looks good, and the dagger works! Of course, we haven’t programmed the most important part of the item yet, so it’s pretty useless right now. Let’s get on to that.
The special ability
Now we write the special ability:
[code]Making-double-strike is a truth state that varies. Making-double-strike is false.
Last after reporting an actor hitting (this is the hit again with the dagger of double strike rule):
if the global attacker weapon is the dagger of double strike:
if making-double-strike is false:
if the attack damage is 0:
if the global attacker is alive and the global defender is alive:
now making-double-strike is true;
say “The dagger of the double strike slashes out again!”;
try the global attacker hitting the global defender;
now making-double-strike is false.[/code]
If we are well acquainted with (the newest version of) ATTACK, we will know that a “last after reporting an actor hitting” rule is the very last thing that will run when someone hits someone. Which is exactly what we need here, of course.
The “global attacker weapon” is the weapon used to attack, and the “global attacker” and the “global defender” are the guy who attacks and the guy who defends respectively. The “attack damage” is the amount of damage that was dealt. The conditions should explain themselves; e.g., we don’t want to double strike if either the attacker or the defender is dead. (But how can either of them be dead if the previous attack missed? Well, there might be special rules that allow this to happen, for instance, a weapon that deals damage to the attacker whenever it is used. We need to be careful and take nothing for granted.) The making-double-strike variable ensures that only one double strike is made, not a series that terminates only once a hit is scored.
Having written this code, we run the game again and test the dagger. It turns out to be much more powerful than I originally thought, because the defender doesn’t get an extra turn to dodge or parry. This means that the second attack hits very often. In fact, it hits too often, so I decide to cripple the dagger a little more:
The weapon attack bonus of the dagger of double strike is -2.
That’s it. The dagger of double strike is ready to see some action. During play it might still turn out to be either too powerful or not powerful enough, in which case I’ll come back to tweak it; but for now, we have an interesting new addition to Kerkerkruip.