…or a Quest for my Kingdom.
After today’s update with the NPC shopkeeper routines, and with the minutes ticking away on Retrochallenge 2017/04, I still felt like something was missing: Quests. How can you have a CRPG without quests? So once I got back from my Sunday family dinner, I figured if I had time I would kludge in the simplest imaginable quest mechanic.
What I came up with was a trivial fetch quest. When you talk to the quest giver, she tells you that if you bring her two mammoth tusks, she’ll make you the king of the village. There are a pair of mammoths wandering around in the wilderness, and either one will supply the tusks.
What did I need to add to support that? Well, my combat system is really just a trivial hack put in place until I write a real combat system, but since it was junk code anyway I figured there wasn’t anything wrong with hardcoding it to give you mammoth tusks when you kill one.
Slightly more interesting is that the questgiver has to be able to notice that you’re carrying the mammoth tusks in your inventory. To handle this, I added a CONVERSE_IFITEM opcode, which makes a conditional jump depending on if you have some number of a particular item in the player inventory. There are no rewards from being declared king yet, but sometimes life is like that.
It seemed like a simple change to give me a satisfying endpoint for this project, so I was a little surprised when it broke the entire conversation engine. I had no one to blame but myself, though. I’ve been obsessed with using byte-sized variables in this project to save memory, and stupidly that included the offset addresses for jumps in the conversation file (which are all absolute offsets, just to make it worse).
In adding the questgiver text and the check for mammoth tusks, the total size of conversations in the village had shot past the 256 byte mark, and offsets into the end of the conversation data were messed up. Ooops.
So I quickly had to refactor the conversation engine and the bytecode compiler to use and generate 2-byte offsets for all the gotos and conditional jumps. This is more of a quick fix than a final solution; I don’t like the amount of wasted space. It’d be nice to replace some of those with 1-byte relative offsets where possible, though that might take a smarter compiler than my very trivial assembler. One of many things to consider for the future.
I think it took three tries to get the bytecode working with 2-byte offset addresses, and another to fix some typos in the conversation script. But as you can see below, I finally was declared King of the village.
That’s probably a good place to stop for this particular iteration of Retrochallenge, don’t you think?