Combat Simulation

I used to work on this project where I mainly wanted to explore how I can let npc’s act intelligent in various circumstances. The original scope of the project was to let a group of npc’s build a town from scratch and maintain it, the player could then influence the growth of the town by either helping or hindering the npc’s. I also wanted to make the logic behind this game reusable. I noticed fairly quickly that the scope was too big for me alone, I scaled the project down to focus mainly on the combat logic, but after a while I didn't have time for that anymore as well.
Sprint 1 - Combat
Healthbars
I started quite early with the development of healtbars, because it made debugging a lot easier. In addition to visualising the current health of creatures I also wanted healtbars to visualise recently taken damage for a short duration. This makes is clear to the player how much damage attacks do, without the clutter of numbers next to the healthbars.
Npc Vision
I wanted the vision of npc’s to be easily adjustable, because I want to be able to give npc’s different kinds of vision. I wanted it to be possible to change the vision radius, angle and determine the type of vision. For example, some creatures could have multiple heads, giving them a wider vision angle. Other creatures could be deaf and perceive creatures when they’re making noise in a nearby location. For now, the focus was on visual vision, I calculated if an npc’s could see another npc’s by comparing their distance to the vision radius and then calculating if the angle between the npc’s was smaller than the max vision angle.
The percieved creatures are added to the following lists so the npc has references to them:
- Visible creatures
- Visible enemies
- Visible allies
Entering combat
Npc’s enter combat when at least one of the following conditions happen:
- An npc of their creature type is being attacked by a creature from a different creature type.
- An npc that is in their team is being attacked by an npc from a different team.
- The npc was attacked by a creature.
When an npc enters combat because they want to help someone the attacked creature signals all its attackers to the initial npc. The initial npc then adds those creatures to a known enemy list (provided that they weren’t already in the list).

Inventory and weapons
In order to make the combat feel more dynamic, I wanted npc’s to be able to change weapons or lose their weapons during combat. In order to support that I build a system where npc’s can carry multiple weapons and each of those weapons can. The weapon system supports the following:
- Weapons each have a unique move-set of different attacks that the wielder can use.
- Weapons can be assigned as loot if they can be dropped, for example a jaw that has a bite attack wouldn’t be droppable.
- Weapons can have an amount of charges before they are destroyed.
- Attacks can use resources upon use, the resources being the charges, stamina, mana or health of the user.
- Each attack has a specific damage type.
- Weapons can have an amount of charges before they are destroyed.
- Attacks can knock the target back depending on the knockback amount of the attack.

Which attack do I use?



Npc’s first calculate the distance to their target, based on that distance the npc will either do a close, mid or long-range action.
Long-range:
- Do a ranged attack.
- Dash towards their target (provided that the npc wasn’t disengaging).
Mid-range:
- Walk towards their target.
- Dash towards their target (depending on certain conditions).
Close-range:
- Do a melee attack.
- Do a step backwards.
- Start disengaging.
If an npc chooses to do an attacking action, they require a weapon for the provided range and they
need the minimum amount of resources to perform an attack with that weapon. If npc’s don’t fulfil
these
requirements, they pick a different action.
When npc’s have multiple suitable attacks to choose from, they pick a random one. I’m planning to
improve this in the future by influencing the choice of the attack on certain conditions.
Combat tactics
Enemy priority
Npc’s can prioritise certain enemies from their list of viable attack targets. Npc’s could for example prioritise not attacking targets that are already in battle with 2 people, to avoid getting hit by a stray sword attack.
Cooperative attacks
Flanking
When another npc is targeting the same target the npc’s will communicate and decide to flank their target. This way the attackers will not accidentally hit each other, and the target will be surrounded.
Future
In the future I would like to expand upon the cooperative attacks by adding environment-based combat tactics. Two npc’s could for example trap their opponent between them and a deadly pit, npc 1 could then try to kick the opponent into the pit while the other npc makes regular attacks. This example and a couple of other situations have been drawn out in the image below.

Disengaging
When an NPC is heavily outmatched by their opponent, they’ll run away from their attacker. When an npc is heavily outmatched depends on several factors:
- The percentage of hp that the npc has left compared to the percentage of hp that their opponent has left.
- The creature type of the npc.
- The braveness of the npc.
Sprint 2 - UI
Battle preperation screen


