It's been over a year since I last posted here in this thread. Now that my wife is in the hospital awaiting the birth of my second son and the older one is asleep, I guess it's a good time to give you guys an update.
For those of you that haven't seen any of my previous posts, I have worked on a 4X strategy game for the past three years. It's basically a mix of Fall from Heaven and Master of Magic, with a little bit of HoMM3 thrown in as well. It fills a niche that I feel has been left empty for way too long - a fantasy 4X that depicts actual progress of your civilization in a non-linear fashion.
Here's a screenie from a few months back.
Planned features:
- You play as a Suzerain. A powerful being gifted with immortality. Either as a dragon, lich, demigod, vampire or powerful wizard, you seek to fulfill your ambitions and eventually become a Living God - the supreme ruler of this land.
- Pick a fantasy race and lead it through the ages. Each race will have a unique, branching, non-linear Culture Tree. Pick and choose the Traditions and shape your people as you see fit. Will they become peaceful forest dwellers, berserker pirates, nomadic beastmasters, seafaring traders or any combination of the above?
- Use an array of interesting spells and rituals that actually affect the world around you and make for interesting gameplay. Less of a "+20% fire resistance" and more of a "round up 20 pops of a certain religion and sacrifice them in a blasphemous ritual to kill a god" variety.
- Fight enemy armies in stack-based combat happening on the strategic map, that still allows for some tactical maneuvering. Some design decisions were made to mitigate the infamous stack of doom (e.g. soft cap on stack size - increasing the upkeep of units if they exceed your current stack limit).
- Employ heroes and send them across the land to perform different tasks - they can lead armies, become province governors, investigate problems in cities, spy on the enemy and go dungeon-delving. Once they level up enough they can be retired in one of your provinces granting huge bonuses. Be aware that they have some limited free will and will plot against you and eventually go into open rebellion if they don't agree with the way you rule.
- Explore a procedurally generated world full of wonders and monsters. Find unique places providing challenges and loot for your heroes. Learn the hard way that biomes and climate matter when you try to march your army through a desert or frozen wasteland. Each time a new world is generated it might also be assigned one or more World Modifiers making it a unique place. Perhaps this world experienced a dragon war in the past and now dragon bones litter the plains and it's more likely to find dragon-themed artifacts in your dungeon runs. Or maybe the moon orbiting this world is made of magical crystal and its phases decide how powerful magic is at a given time.
- I'll stop here before this post turns into a design document.
So what's been done this year? I was able to repurpose my heightmap generation algorithm from my 3D attempts to create varied, procedural coastlines. Thanks to compute shader magic it only takes a few milliseconds to redraw the whole map.
Other than that, nothing flashy nor worth showing in a screenshot form. Mostly I've been working on nuts and bolts that lie in the background and did a lot of refactoring. You see, when I started coding this game I came to it with a very naive mindset - "This is a Hex class. It will do everything related to a hex, return its neighbours, hold data about its features and vegetation, display it and so on". Things I watched along the way like
Quill's hex game tutorial lulled me into believing it was the right path. Soon, however, I realized that this approach was becoming unwieldy and I was going to paint myself into a corner unless I come up with some actual code structure and architecture. Thus began my research - I visited forums, dug into any 4X game code I could get my hands on to get some ideas. The only lesson I learned here is that most commercial game projects are monoliths, only maintainable through the sheer number of developers working on them.
Eventually, I decided to go with good ole' MVC pattern variation as it suited my needs the most. At this point all my game logic is neatly separated from the presentation layer, meaning I can easily go back to 3D or even switch to ASCII if I desired. Another benefit of this approach is that I'm going to be able to create separate 'logger' views and run the game in kind of a 'headless mode' for testing purposes. Definitely going to come in handy when I start implementing AI and decide to pit them against each other.
Another problem I'm quite proud of solving is the rule/modifier mechanism.
When I wasn't coding, I was working on the documentation, coming up with mechanics, rules and so on. Eventually, I had to wrap my head around modifiers and how they'll fit into the existing code. So I started coming up with some scenarios:
1. There's a spell that improves the attack by one - I guess I'll have to keep a list of modifiers on the unit which is accessible to the battle system, easy enough.
2. Maybe I want there to be a religious tenet that gives your units combat bonus if they're fighting units of another religion - okay, so now battle system and religion system need to be able to communicate somehow.
3. I came up with an idea for a spell. It summons the Avatar of Motherfucking Destruction. While the avatar is alive all demonic units on the map gain a significant combat bonus, all living units within three tiles of the Avatar receive fire damage every turn and also each turn that is a prime number all rivers turn into blood resulting in population growth maluses - how the fuck am I even going to approach it?
My main problem was that whenever I came up with an idea and it did something new, I had to pause, scratch my head and think how it fits with the rest of the systems. If there only was something like a Universal Rule System. So I took a break from the game and created just that. Nailed it at the third iteration. It's a separate system that I should be able to use in other games as well. At its core it's just a glorified Command pattern - I have Rule objects which encapsulate some method (which may contain some other Rules). The Rule class also contains all the plumbing that allows me to apply triggers and modifiers. The Rule also keeps track of which Rule it's been fired from, so it's easy to create an effect that, for example, increases the output of DealDamage rule only if it's been fired from CastSpell rule which has a certain spell in its parameters. Finally, the Rule caches its output and is only recalculated when needed. All conditional logic is contained to Modifier classes which query the game model and modify the rules accordingly. All in all, it's a pretty neat system that should allow me to focus on content creation instead of digging into the code. Cons? It requires some boilerplate code, as you can't just create a method that does what you want and call it a day, but the headaches that it will help me avoid in the future should more than make up for it. My only worry is the performance overhead it may cause, but I already took some steps to prevent it and it's promising so far. Below is a screenshot from my stress-test console app.
So that's it folks. Sorry for the wall of text, but I needed a place to vent my thoughts. I'll think of creating a blog once I'm a little closer to completion (I'm thinking three more years until it's somewhat playable).