Hello everyone. I figured it might be a nice idea to write a little post about the mechanics of our combat system in Citizens: Far Lands. It has taken a little while to develop, and has gone through a major overhaul, so I think the lessons I've learned on it could be shared with a wider community for the greater good :) For those of you who are not into programming, I tried to keep it light. You might still find it interesting to see how it all works "on the inside". Initially the combat system in Citizens started as a turn based system. From the beginning it was written to be as reusable as possible. Although I'm not a good programmer, I try to make my systems like plugins: something I can just easily drop in and out of the program I'm working on. Initially the basic requirements were:
- A few soldiers (let's call them subunits) should move together as a unit. We will call these "Flags".
- Each Flag has statistics that are always the same, and some that grow or shrink with each subunit in the unit. For example damage should be increased when there are more subunits, and should shrink as they die.
- Each subunit has its own animator, they should be able to move, attack, die and stand idle
Here you can see an and result. This is how we define an "Archer". There are some additional optional parameters that are left empty (for example units can have unique banner carriers). If the unit throws missiles, we can specify those too (arrows, axes, giant chickens...). An important list to take not of is "Keywords". Stealing the idea from tabletop strategy games (Kings of War, Warhammer), we define what a unit is by giving it a bunch of strings. "Missile", "Infantry", "Cavalry" and so on. This way we can also add "defence" and "attack" modifiers which are based on said keywords. We'll discuss these later. Scriptable objects are nice because they provide a visual interface for the designer to change the unit stats quickly and easily. If we were trying to make the game moddable (so basically if we were writing it again :) ), I'd probably do something like this, but the end result would be converted to an XML file read from streaming assets. The next part is Sub Unit. Sub Unit is a prefab that defines an individual soldier. It has its mesh, animator and components needed for it to work.
SubUnit component contains mostly data and a few helper methods. A lot of it is populated at runtime by the battle manager (parent flag, troop, anchor and so on). It has some basic controls for animations such as "move", "idle", "die" and "attack". SoldierAnimation component is basically a wrapper for the animator. It provides a slightly more friendly interface.
How SoldierAnimation is useful:
The last and most important component is the "Flag" component. Flag component has all the methods and parameters that the battle manager is constantly interacting with. Because we're lazy, we use Unity's inbuilt Navmesh Agent to move the troops around. Flag detects its own movement and tells all its SubUnits "hey, I'm moving now, play the move animation". Flags can grow and shrink in the number of active subunits, so we need methods for these too. Each subunit we add increases health and damage, but leaves some other statistics such as movement speed or attack speed unchanged. Whenever a subunit dies, these are reduced.
Since we moved away from the turn based system, attacking is done in real time. There's a simple timer that ticks down, to check whether enough time has passed between attacks so that another can be carried out. When the timer is up, unit attempts to attack a selected target. There is some logic in selecting targets, but it would require its own long post.
So, attacks! Remember keywords I mentioned? Damage dealing itself is quite simple. At its core, we simply takeaway the amount of damage from flag's health, but there is damage reduction and amplification. Spearmen unit can have a 50% attack bonus against "Cavalry" keyword. Units that are standing in a forest can have a 50% defence bonus against "Missile" keyword. Terrain modifiers can also contribute a lot! We can effect range, unit speed, damage amplification, damage reduction, attack speed... all sorts of stuff. All in all, the system works quite well. If you have the right animations and meshes, a new, fully functioning unit can be setup by a designer in a few minutes. I hope you enjoyed this little dev diary, and perhaps it gave you some ideas if you're working on your own stuff. The system is no longer turn based, and a demo update is coming in a few days where you'll be able to try it yourself. Our next dev diary will deal with AI and battlefields themselves!
[ 2022-04-28 21:29:00 CET ] [ Original post ]
- [487.68 M]
Citizens is a turn-based hybrid of a city builder and strategic puzzler where you create beautiful cities, manage resources, plan long term investments, trade with foreign civilisations and look after your subjects. Explore beautiful islands, deal with difficult problems, and think about your next move very carefully, for it could be your undoing!
Our demo offers you a taste of what Citizens is like. It presents you with early-game mechanics and showcases the basics of combat and trade.
Citizens offers:
- New approach to city-building games
- Three campaigns with challenging quests and varying difficulty levels
- Over 50 buildings spread over numerous production chains
- Over 30 different resources to extract, process and manufacture
- Mechanics to spice up your experience such as plagues, fires and winters
- Combat and Trade
- Endless fun with random level generation
Meet various civilisations along the way. Sightsee ancient temples, trade with scattered outposts, and defend yourself from plunderous Vikings! Be mindful... Ravaging barbarians are not your only enemies. Fire and Plague can be dangerous too.
With all this doom and gloom above, just keep in mind one thing...
If all you want is a peaceful and soothing experience, then try out Free-Build mode! Place buildings without any restrictions on a randomly generated island, or try out economy mode for something more challenging: that's where anything can happen! You'll never run out of new lands to explore. Something will always be different.
[ 6132 ]
[ 2625 ]