Ready, Aim, Fire!

 Real life has been super busy and complicated lately, but I found some time to hammer out and get the ranged combat system fully functional.

The big addition was adding sprite movement to the FX engine. I wrote up a small model in Extended BASIC to test moving one point to another, and implemented that in assembly code. Unfortunately, I found out my design was flawed… steep angles weren’t lining up right. I had to go back and implement Bresenham’s algorithm closer to the standard to get it right.

A complicated bit of code was calculating the correct pattern to use for ranged missiles. There’s basically five types:

  1. No direction, just single pattern
  2. 8 direction pattern, cardinals and diagonals
  3. 4 direction pattern, cardinals
  4. 4 direction but either left/right or up/down only, cardinals
  5. 8 direction but either up/down, left/right/, NW/SE, NE/SW

The code to determine what pattern to use based on the slope to the target was tricky to figure out, but it turned out to only require a single data array and some clever bit-masking for the different types. It’s by no means PERFECT, but it’s good enough for the effect.

I found a host of small bugs on the way, many on the design side. I had implemented a lot of the work at different periods, and what the code was doing and what the data was set to was in places two different things. For example, I had in my spreadsheets that a set color of 0 meant to rotate through all colors, but this wasn’t done in the actual animation code.

So, now that ranged combat is finished, I can move on to spells. I just finished re-writing my spreadsheets of spells and types to accommodate the changes to the combat system. Now I can do the work of implementing it in code. Unlike ranged combat, spells also can affect multiple targets. The affected unit determination code is written and in use for single targets, but how it will work with multiple remains to be seen…

Ranged Combat (Video)

After spells comes monster A.I. I was doodling up some ideas here today on paper, and have a good idea of what I want to do here. Testing it will be a pain, though, since much of the action will be determined behind the scenes. I may have to model it in Extended BASIC as well…

Posted in Coding, CRPG, Screenshots, Video | Leave a comment

Things I Have Learned from Writing a Vintage CRPG

As I am now going into year 8 of creating my vintage CRPG, It’s time to take a look back at things and share what I’ve learned from the experience of having a hobby programming project. Or, you know, I’m just looking to write something in my blog today.

Know your Platform and Resources

Before you start out, you need to know what you can do, and what kind of tools you have.

Programming on your ACTUAL vintage computer sounds like fun at first. But the truth is, nostalgia has made you forget some of the little problems with that old hardware…

For one thing, old computers ran HOT. Even modern computers can warm the room, but your old computer would get hot enough to make that funny heated plastic smell. Could be a little alarming after all these years to smell it, it starts you thinking about whether or not you should keep a fire extinguisher close by.

On that note, old hardware is old hardware, after all. You don’t know how much longer you have on a given chip or device before it dies on you. Fixing it or finding replacements could prove time-consuming and costly; vintage hardware is not that much cheaper than modern-day due to rarity. And finally, old computers lock up a lot. My old TI was particularly sensitive around the side-port, one bump and goodbye to hours of work.

Obviously, an emulator is the way to go. There are a large variety of emulators available nowadays that do a great job of emulating the original hardware. Plus you have the added bonus of being able to write up your code in a text editor on your PC and just paste it into the emulator. AND emulators can usually be ran at much higher speeds for compiling purposes.

Some other useful tools:

  • Microsoft Excel. Spreadsheets are excellent to use to track data structures, graphics, and other aspects of your work
  • Hex Editor. You can find a number of commercial and freeware hex editing software which will let you directly alter your emulator’s data files
  • Paint Programs. Useful for creating graphics for your game

Engine First, Content Later

This particular issue happens a lot with game design. Namely, you get so excited about the end product that you start doing the content work before you’ve even written a single line of code.

For myself, I’ve wasted a LOT of 8-10 square per inch graph paper designing maps for my CRPG that was, in the end, a lot of wasted effort. I got so caught up in the story ideas I had that I just had to design the maps for it. I told myself it was important research work for the game engine of course… I had to know how much flexibility the engine needed, after all.

Of course, while you’re doing all this, you’re not actually doing any work on getting the game engine done. If you did things in the reverse manner, then at least you could update your story to match what the engine can do, and you have something substantial to keep working on.

Funny enough, I’ve seen the opposite as well. I read an interview of a programmer for an arcade clone on the TRS-80 Color Computer. He showed a remarkable degree of coding awareness and understanding of the platform and how to get the best performance out of it. But when he was asked about game design or what he thought of other games, he seemed lost and confused. He knew how to copy the game rules to an existing game and make it work on the platform, but creating his OWN rules or game was completely beyond him.

Commit to a Design and Stick With It

There is no way I would have finished this game as a teenager. The amount of compiling, debugging, and hunting down bugs would have bored me to tears. Plus, my disk drives would have burned out with all the compiling work I was doing.

The truth, though, is that any sizable programming project should be planned out WELL in advance, and almost written away from the computer entirely. With modern tools, it’s too easy to fall into the pattern of cowboy coding: Put something together and see if it works.

This also helps with another issue: Redesign. Software is never a step-by-step process. You often end up going back and changing something later, which affects your current work, which requires redesign and recoding, and so forth.

But the problem is made even worse when you change your mind about fundamental aspects of the project itself. For myself, I’ve altered the design of the game engine (as in, the rules by which the game is played) four times. Each time required a massive reorganization and updating of data, code changes, and even design alterations.

I could have avoided this problem had I sat down with a pad of paper or two and just wrote out my design and made sure it worked on paper first. Some redesign was inevitable; since I was discovering the capabilities of my computer in the process, some ideas proved to be too burdensome or grandiose to follow through on. But it’s almost better to finish something sooner than get stuck in a constant cycle of redesign.

Use Source Control

This one is a major requirement of modern-day software engineering. Source Control lets you maintain version history of your files, lock files so that multiple programmers can edit the same files but not overwrite one another, etc. You read stories about companies and teams who refused to jump on this bandwagon for years, but sorry, this is totally necessary.

But why for vintage game programming? And when you’re the only one on the team?

Well, the main value is the version history. If you have data sheets that are undergoing a lot of changes, it’s good to be able to refer to a past one. It also helps you consolidate changes easier. Truthfully, I still don’t have a source control system going for my CRPG, and I really should get one so it’s easier to sync up files between locations.

Comment Your Code

Yeah, you’re the only one writing it, right? And real programmers don’t need comments, they just figure out what the code does at a glance right?

No. Comment your code. Trust me.

If you’re working on a hobby project, you’re going to have a lot of other things that are going to interfere with it and make you stop it for long periods of time. Commenting your code will save you a lot of grief and time trying to figure out what you were doing.

Also, commenting can help you lay out the logic path of your code. Often in assembly language, you don’t have a lot of context as to what register is storing what value. Using comments to remind yourself of what this code is intended to do can help you find bugs later when you look at the logic and say “Hey, wait, that’s not right.”

Document Your Progress

Creating and maintaining a blog or website on your hobby project is very good to keep you motivated. You often create in a vacuum with no feedback on what you’re doing. Having a forum to share your work and experiences can do a lot to encourage you to keep going.

Take caution, though. If you’re the type to start and stop your project a lot, your support group may end up going into a “put up or shut up” mode of thinking. They will be waiting for you to deliver something rather than offer praise and encouragement with no return.

Posted in Blog, CRPG, Design, Gaming, Personal, TI-99/4a | 4 Comments

Debug Blues

Debugging the combat engine continues… it is really good to do so, though, since now it’s actually working and the bugs aren’t completely derailing it. Well, most of the time.

A simple register shift being one off caused all the problems with other characters not being able to hit without crashing the game. I was also adding health instead of wounds when striking monsters, meaning they actually got STRONGER with every hit… now monsters are dying correctly.

Currently, I have a few more bugs I want to fix up before I try and add any new FX, like ranged weapons:

  • The wrong monster graphics are periodically loading, and I can’t figure out why. It seems consistent for certain monster types, so I will statically fix it to one and debug into it to find out what’s going on
  • You can move about the entire map now easily enough, but moving OFF the edge doesn’t end the character’s turn, and actually do some funky stuff with the interface
  • You can’t actually end combat, there’s nothing tracking that all monsters are dead at present. If I get this wired up, then I need to test and debug the combat ending routines, including treasure and updating travel mode so the monster you fought is gone
  • Syncing up FX and their timing is needed. The regular hit graphic disappears long before control returns to the character, making it seem a little lagged. Part of this is also having a set amount of time always pass at minimum (Say, 1/2 second) so that you can see the combat update of a hit, miss, or critical hit, and also take longer if a FX lingers longer than that

 

Posted in Coding, CRPG, Design | Leave a comment

Premature Exultation

Ha ha! I got the FX to work! And it is beautiful…

Well, it WAS beautiful, until I discovered a horde of bugs around it, such as:

  • Monster graphics are correct, but once in awhile the wrong file loads for a given monster
  • The timing on the effects appearing and disappearing along with the combat maps and updates needs to be better synced
  • Attack mapping seems broken, but ONLY with the rogue? It gets into a massive CPU over-write in the routine
  • At one interval that hasn’t repeated, I couldn’t Guard on the first turn with the wizard. It didn’t repro on subsequent turns

Obviously, the graphics and sound effects take a back-seat to the process of getting them on the screen. I got a lot of work ahead to clean up the code…

Posted in Coding, CRPG, Screenshots | Leave a comment

Bug Extermination

Okay, I spent several hours on code fixing, building, re-building, file editing, spreadsheet updates… all aimed at getting the game back on a (sort of) running basis. I also thought some new screenshots would be nice to splash around the blog.

I updated the travel screen to remove numerical references to health, wounds, stamina and fatigue. I thought it was unnecessarily cluttering things up. I’m well aware that as the game designer, I know exactly how the statistics work. Because of that, I think “Why not just show all the values all the time? I need to see them for debugging after all…”

It’s an easy trap to fall into to just display everything, because there’s no mystery to ME how it works. But part of a game is for the player to figure out how things work.

I wrote a Trek game once that included a torpedo course calculator. But I realized that it more or less ruined the gameplay because it would tell you exactly what angle to use, and any guess work was removed. What fun is that?

No worries, though, I won’t forget to show the numbers on the statistics screens. I’ve updated those to show the new reduced statistics. The party overview is also a quick way to see exact values if needed.

My real focus of the debugging was to get the combat engine back to a state where I could start debugging what was going wrong with the visual displays. (Which internally is called the FX code.)

Fortunately, it turned out to be pretty easy to convert the engine to an “act immediately” state rather than save actions up. I also recovered several hundred bytes of memory that was being used for action processing, although I’ll have to back later to figure out how best to make use of that.

I’ve found the easiest way for me to debug and fix issues is to keep a notepad and pencil by my side as I run through the code. Any bug I see is written down on the list. Once I have a substantial number, or the program crashes, I go to the source to find the causes for each bug. As I fix them, I cross them off the list. Then I recompile and re-run the code, and validate that each bug got fixed.

Once I got movement working, the engine felt MUCH more playable and enjoyable. I really like the effect that actions have as well; you’re left with a real tactical challenge. Do you move into position but cost yourself some fatigue? Or do you wait a turn to let the opponents come to you, and enjoy a little defensive bonus?

Guarding and movement was easy. Attacking, though, proved to be extremely buggy. I finally had to find a decent breakpoint in my code (Classic99 is awesome, but Visual Studio it is not…) and halt the action to step through. And that means going through ALL the code, including the incredibly long and painful disk routines to load data.

I found several issues in the FX code, including an annoying one with Unit ID’s. Each “character” on screen, both players and monsters, have a unit ID in a byte form. This lets me determine on the battle map who is where. Unfortunately, the ‘0’ value is used to indicate a movable space, but the various indexes are also zero-based. Which means every time I need to convert Unit ID to some other array, I have to subtract one from it first. And I forgot to do that in two places.

This actually explains why behavior was so inconsistent before with hitting creatures; it wasn’t finding the creature in the expected location on the left, so the game continued, but if I attacked upwards it DID find a creature, and moved into the buggier code. Which you can see in this screenshot….

Any 99’er programmer in assembly should immediately recognize what this screen means: seriously bad mojo with your video manipulation. Usually this is caused by a counter value being way off. Your routines end up overwriting all of VDP memory, which makes sound, graphics, and sprites all go haywire.

At least now I know where the bugs are occurring, I just have to step through the code and find the bad values that are causing the problem. It will probably be something VERY simple. After I get basic melee attacks working, I’m moving on to ranged attacks, then spells. I also have a lot of commented out or hard-coded values for setting up the battle map and unit placement; this all needs to be replaced with working code and tested too.

Oh, and at this time, I’m hovering right below 20,095 bytes of space used in the 32k memory expansion. I converted my program to use the CPU RAM space in the cartridge (located at >6000) for RAM space, so that I can spill over into the lower 8k with code. I’m pretty confident I have enough memory to complete the game.

Posted in Blog, Coding, CRPG, Design, Screenshots | Leave a comment

A Static Situation

So, I’ve done a further bit of change to how weapons and armor work… now all base types (sword, dagger, leather armor, etc.) have fixed amounts for ALL statistics, read from CPU memory. (I could push it out to disk somewhere, but why bother? We’re talking 42 bytes here…)

Why? Well, as I was going over some of my old item lists, I noticed how many items were just fancier names for “more damage, more accuracy”. From a “rusty blade” to “heroic sword of awesomeness”. That really bugs me because I didn’t want the equipment system to be a constant “move up” to the next bigger better item.

I’m not the only one to get tired of this. The latest beta version of D&D Next has magical items limited to a +1 bonus standard… special items have a higher bonus only in specific circumstances. They also have removed the notion that a creature may require a “more powerful” weapon to be hit with, so that magic items always have value.

I was already using half of my four bytes for a “special” property, which is essentially an index and value in the player array. That lets me have weapons that have special properties. A rapier, for example, is a sword designed for defense, so it may also grant a +1 defense bonus. A dagger designed for a wizard may offer a +1 casting bonus when wielded. And so forth… The only change I’ve made is to move the static values off into memory and have those two bytes serve as a second modifier.

The main change this has is that damage should be far more predictable. I really want the game to be “explore-friendly” so a player can go anywhere he chooses to and not get wiped out by a group of monsters too strong for him. At least not without plenty of warning of what they’re getting into…

Posted in Coding, CRPG, Design, Gaming | Leave a comment

Eating on the Run

The code and spreadsheets are a’changing… so far, I’m really looking forward to how the changes work. With simpler math, the combat engine should be much easier to balance out.

As usual, changing some spells was in order. I had several that affected defensive bonuses that no longer exist, so I removed them. A big challenge is with damage; while hit and defense numbers are fairly static and a +1 is ALWAYS good, damage will scale up a bit more. So I decided to have all damage effects be things like 1/2 or double. This means changing the bonus calculations slightly to account for changes of this nature instead of adding/subtracting.

One major addition is that I’ve added party rations as a game factor. I don’t intend for food to be a major pain like it is in Ultima, where running out of it effectively kills your party in short order. Instead, rations serve the same purpose as they do in Tunnels of Doom; you periodically consume rations on the world map and heal fatigue and possibly wounds. Rations also serve as a money sink.

I’ve removed some of the more lame spells and added new ones to replace them. A corrosion spell now exists that halves normal damage resistance, while protection doubles it. Like many spells that have counter-effects, one will remove the other if cast upon a target. A spell to create rations also seemed like a good idea.

One bit of caution I’m taking is to not make ranged weapons too overwhelmingly powerful. The first step to this is to make sure hit bonuses for ranged weapons are lower than melee weapons. Another is that spells that increase damage potential will only work on melee. That way, melee attacks still have good value at the expense of range.

My final step, before I try to start compiling and running the changes and looking for regressions, is to update the combat movement system. Before, you had to press the M key and then indicate a direction. I want to scrap this and have you be able to use the arrow keys immediately to move and attack. This will speed up combat considerably.

Posted in Coding, CRPG, Design | Leave a comment

A Farewell to Arms

The refactoring continues… part of which is the redesign of how weapons and armor work.

Playing World of Warcraft in the last few years has really made me recognize the serious problem of high-scaling. Basically, if you create a system in which bonuses continue to rise at a steady rate, eventually you make a system where more experienced characters just wipe the floor with lower-level encounters. In WoW, since the Cataclysm expansions, the attribute bonuses on items got so ludicrously high that a maxed-out character could solo heroic dungeons from the prior expansion with ease.

Dungeons & Dragons suffered a similar problem, although not quite as extreme, with the 3rd edition. Although it was better than most at higher levels, the 15-20 level range had characters overloaded with magical items that boosted their skill and attacks to extremely high bonuses.. so much so that the 1-20 random range became a non-factor. The epic level rules (which clearly had never been play-tested) made things even worse.

I’ve addressed some of this already in my designs by dropping levels as an abstract measure of power, and experience gained from monster slaying. However, I still had items featuring steadily increasing power levels, to the point that an item could make a significant difference in power level, plus a monster with high statistics could easily overpower a low-level party.

On my re-design, I took it one step further by redesigning weapons and armor to have static values for attack/defense bonus based on type. So a sword always has +4 to hit, and a cost of 2 action points to use. A suit of mail armor has a defensive bonus of +3, and a move cost of 3 action points. And so on. I also removed all the other defensive options such as dodge, parry, and block. (Too bad, since I already had some sound effects for them.)

So how are weapons different? Well, their potential damage (measured as a base amount and a range) is different for each weapon, as is the regular and magical damage reduction of armor. In addition, the last two bytes of the weapon/armor array serve as a generic index modifier. Basically, an item can adjust another statistic in the array. A rapier, for example, may give you a +1 defensive bonus.

The nice thing with this change is that it stabilizes your ability to hit to a static amount. So a high defensive score remains high, no matter how powerful the characters are. Damage will vary, but I plan on keeping that curve very slow. This means a higher strength encounter won’t automatically wipe the party out, although they may get reduced to doing only 1 point of damage per hit.

I didn’t remove QUITE as much code as I thought I would, removing the pre-processed action system. The refactoring of the attack routine did reveal quite a few small little bugs, though. Some of them were straight values used as addresses, which was probably what caused the increasing instability in my combat engine. So hopefully this will help debug and get the FX engine rolling.

Posted in Coding, CRPG, Design | Leave a comment

Ready, set, action!

Okay, I got my new system figured out in my mind… actually re-configuring the code base to use it is a long arduous process I probably won’t start for awhile, but at least I know what I’m going to do.

All the pre-processing of actions is going away. When you move your characters in combat, you take all your actions then and there. Just like Tunnels of Doom. But how to track things like haste and speed? How does fatigue figure in? I was wracking my brains on a solution when it came to me unexpectedly.

Each character has “action points” which renew every turn. These points are used to take actions, such as move, attack, fire a bow, cast a spell, use an item, etc. Once all your action points are gone, your turn automatically ends.

So, here’s how it works: If you take an action that takes you to negative action points, you take that difference in fatigue damage. Fatigue serves as the first kind of “damage” you take, which recovers over time outside of combat, or through use of potions. If you are at maximum fatigue, any additional action damage becomes wounds instead. Maxed out wounds renders your character unable to do anything. Guarding takes any remaining action points as a defensive bonus and ends your turn.

Example: Eric Seablade has 5 action points. He’s wearing mail armor, which makes movement cost 3 points. He has a sword, which he can swing for 2 action points. So he can move once and attack for 5 points, ending his turn. Alternatively, he could move twice for 6 action points but he would also take 1 fatigue. If he moved once and then just guarded himself, he would end his turn with a +2 bonus to defense.

When I had this epiphany, it just worked across the board for everything. Weapon attacks, heavy armor slowing you down, expensive spell casting? All covered! There’s a slight bit of confusion with spells that can be cast in both combat and travel mode… the high cost of them should technically be less outside of combat. I may have to subtract standard action points from spell costs to reflect this difference.

The nice thing is this will greatly simplify the code as well. It may reduce the combat code base by as much of a kilobyte, which will be much more efficient. Processing actions immediately instead of storing them up for later solves other issues as well, such as tracking item types used.

Unfortunately, the retcon of the code will be murderously difficult, as many things in many places have to change. On the plus side, it would serve as a quasi review of the code for me to refresh my memory about what’s all in there.

Posted in Coding, CRPG, Design | 3 Comments

Moving Forward

Okay, so the debugging has started again… and it is a pain. If there was one major downside to vintage programming, it’s that the debugging tools are either absent or lousy.

But, I’ll report more on that when I have something to report. In the mean while, not surprisingly, I’m finding that I have a great deal of dissatisfaction with the combat engine.

I had originally designed it to operate much like the idealistic version of 1st Edition Advanced Dungeons & Dragons did… with players deciding their moves, and their initiative roll and speed factors playing into the order of actions afterwards. It wasn’t something I’d ever seen happen in a CRPG before, so I thought it would make my game unique.

And so it does. But it also makes it boring and slow. A lot of code and data space is sacrificed to track actions ahead of time, and process them in one giant workflow. As part of my debugging efforts, I’ve had to move one of the characters up close to a monster to try and make a hit. So I’ve quickly become frustrated with the system. After playing Ultima IV for awhile, which had much quicker and easier tactical combat, I’d like to step back and re-think this system.

Another factor is the design of the classes themselves. I had originally omitted the idea of a “hit roll” separated from a “damage roll”. But now I’m thinking I’d like to re-add that. Maybe even put attributes back in the game? Mulling that one over… I have no interest in adding levels to the game again; I hate level and XP grinding. My plan is to have the game’s story advance your characters, not the number of bogeymen you slaughter on the way.

To be honest, what I should do is just take out ANY complicated combat engine stuff for the moment, and incrementally add new features as I go along. Re-tooling the engine (yet again) will take awhile though, and I really want to solve the FX problems first.

Posted in Coding, CRPG | 1 Comment