I am engaged on a turn-based ways recreation in Unity3D/C# by which gamers management Detachments composed of a number of Models. Every Detachment occupies one hex on a map, and should include as much as one every of Troops, Equipment, Specialist, and/or Chief Models, which transfer and combat as one. When two detachments combat, their Models all generate and resolve assaults, which can kill issues within the different Detachment.
The implementation of that is cut up so that every one the game-mechanic logic for a fight is executed first, producing the outcomes of the fight, after which these outcomes are individually animated.
I’ve the underlying fight engine parts applied to my satisfaction: given two Detachments, it would make and resolve all of the assaults appropriately in accordance with the foundations of the fight system, and it information all the assaults made and their outcomes. The place I am caught is animating these leads to a approach that provides a participant legible visible suggestions on what occurred. (There’s a separate fight log that they’ll view, however I might just like the visuals to be the primary supply of suggestions.) It is not the precise animation that’s the drawback, however sequencing the essential occasions to be animated. From my perspective, the complicating elements are these:
- Troops might include as much as 20 particular person Troopers, however Equipment, Specialist, and Chief Models are single Troopers.
- The assaults happen in as much as 4 phases (Ranged, Assault, Pike, Melee) relying on the Models concerned, however, importantly, in every section, assaults are made “concurrently.” That’s, every Trooper on all sides makes all of its assaults for that section, and solely after all of the assaults are resolved do any Troopers get marked killed.
- A Unit that makes a number of assaults in a section might make them towards totally different goal Models. This may be as a result of they killed off their first goal and had extra assaults remaining, or as a result of they’ve two totally different weapons which might be optimum to make use of towards totally different targets.
My first try and animate the fight was to take the record of assaults made and assign every to an idle Trooper mannequin, having it animate that assault solely after the goal of the assault was executed attacking. I had assumed this could possibly be executed in a approach that leads to a series of kills: Trooper A1 is killed by D1, which is killed by A2, which is killed by D2, and so on., till all the deadly assaults have been animated. In observe, my implementation created loops the place assaults had been assigned such that A1 is killed by D1, which is killed by A2, which is killed by D2, which is killed by A1. Loops like this are in fact an issue, as a result of there isn’t a surviving Trooper who can finish the chain.
So the query I now face is: given lists of Unit-level assaults, how can these assaults be assigned to Trooper fashions and ordered such that there aren’t any loops of deadly assaults? I consider this drawback boils right down to the development of a directed graph with no cycles greater than 2 edges lengthy (since I can deal with mutual-kills the place two troopers kill one another), however my graph concept shouldn’t be adequate to make certain that that is potential, or to determine an algorithm to perform it.
The next abstractions are high quality, as I do not suppose they detract from the suggestions that the animation would offer:
- It doesn’t matter which Trooper in a Troops Unit is animated making an assault or being the goal of an assault.
- Non-lethal assaults do not should be animated, solely deadly ones. The final Trooper in a Unit will be killed as quickly as all of that Unit’s deadly assaults have been animated, even when a few of its non-lethal assaults haven’t.
- A Trooper will be animated making extra assaults than the sport mechanics would enable. That’s, a Trooper that per the foundations can solely make one assault could possibly be animated making a number of, if that is what it takes to keep away from cyclicality.
Issues I might desire to not budge on:
- Each killed Trooper ought to be animated being killed by an assault from the Unit that really killed it, within the section that it was killed.
- Every Trooper ought to be animated making assaults so as of section. It shouldn’t animate a Pike assault earlier than a Ranged assault, for instance.