[JASS] Bit complex combat system requires handling much data. Need help with the first steps

Status
Not open for further replies.
Level 19
Joined
Oct 12, 2007
Messages
1,821
Hey there.

I'm still struggling with the same problem for over half a year now, and decided to not look further for someone that wants to take over creating the system I need, but I'm going to give it a go again with my own approach.

I was wondering if there's anyone here that could give me info or thoughts about the following:

Given: There are 16 units owner by Player A and 16 units owner by Player B on the field. Every unit can attack for up to 3 hits, but a dead unit can (obviously) not attack anymore after dying.

- When 'combat' starts the first (as in unit with highest 'speed' stat) unit will randomly chose a target from the opponent's units and approach it to strike it once. Then that target can strike back if it still has one of the 3 hits left (cus any unit can only attack 3 times). Then they repeat this until both units have 0 strikes left.
- Then the unit with the 2nd highest speed will approach a randomly chosen enemy, and the same will happen. This will continue until all units have used their 3 strikes.

Now this scenario happens quite often in the map I'm working on, so I'm trying to think of a way to make this go faster. If unit A attacks unit B, and later on unit C attacks unit D. The outcomes of this fighting has no effect on eachother, so I thought I need a way to let these 2 battles happen simultaneously so that I save time and players don't have to watch an endless combat scene in slo-mo.

Is there a way to 'calculate' the outcome of all these mini battles beforehand so I can (after calculating) order units to move in waves and attack in groups. Imagine unit A attacking unit B and killing it, and then unit C has randomly selected unit A as its target and kills unit A. In this case I don't want unit A to die before unit B dies, else the whole kill order makes no sence. So I need a smart way of creating an order of events within this battle.


I hope its understandable, and I hope there's a smart guy out that that knows a good way to handle this in Jass. I don't have that much experience with Jass, so I would appreciate some more detailed information instead of answers like 'Use this', or check 'Hashtables' or whatever.

Thanks in advance!
 
Is there a way to 'calculate' the outcome of all these mini battles beforehand so I can (after calculating) order units to move in waves and attack in groups. Imagine unit A attacking unit B and killing it, and then unit C has randomly selected unit A as its target and kills unit A. In this case I don't want unit A to die before unit B dies, else the whole kill order makes no sence. So I need a smart way of creating an order of events within this battle.

The simplest way to deal with this would be to prevent a unit participating in two fights during any combat. E.g. Unit A attacks Unit B, both are removed from that player's list of combatants.

Make a unit group for each player's army.
Loop from 1 to (army size / 2):
pick a random unit from player a's army, pick a random target for it, order them to attack each other, remove both from their respective armies, and do the same for the other player.
Regarding the 3 attacks thing, you can resolve all of that using a nested loop after target picking.
 
Level 19
Joined
Oct 12, 2007
Messages
1,821
The simplest way to deal with this would be to prevent a unit participating in two fights during any combat. E.g. Unit A attacks Unit B, both are removed from that player's list of combatants.

Make a unit group for each player's army.
Loop from 1 to (army size / 2):
pick a random unit from player a's army, pick a random target for it, order them to attack each other, remove both from their respective armies, and do the same for the other player.
Regarding the 3 attacks thing, you can resolve all of that using a nested loop after target picking.

Unfortunately that doesn't work. I haven't been that clear about it, but in the map it's also possible that it's 16 vs 4 or let's even say 16 vs 1. In that case I want all the 16 attackers to hit the single defender (in case it survives for so long).
 
Then you'll need to add a timer for units involved in multiple fights.

So if a unit targets a unit that has already been in a fight, add it to a list (use a couple of arrays to save attacker, target, time). After initial combat phase, wait 1 second, then loop through all units in the list with a time value of 1, resolve them, go on to the next, etc.
 
Level 5
Joined
May 6, 2013
Messages
125
I don't have that much experience with Jass, so I would appreciate some more detailed information instead of answers like 'Use this', or check 'Hashtables' or whatever.

Sounds more like you are looking for an idea to implement this rather than Jass help. Jass should be the tool you implement your ideas with, not a hurdle you overcome. You might find that Jass stands in the way of your idea, but if that happens, you can still think about how to resolve that problem, only now you will at least know what you want to do and look for specific things and workarounds.

Is there a way to 'calculate' the outcome of all these mini battles beforehand so I can (after calculating) order units to move in waves and attack in groups.

When you have full controll over the battle, there surely is. From how it sounds, there is no user input involved, so this question will be decided by whether you use RNG-behavior you can't influence (like weapon damage rolls or critical strikes).
If you have full influence, you can make a list of moves with associated outcome, create some sort of dependency graph from it and work your way through that graph to do the actual animation. This will probably be the easier thing to do (in my experience, its easier to do things when you calculate all the data beforehands and then just work through them).
If not, there will be cases where you need to wait for the Result of the RNG before you can continue. E.g Unit A (fastest unit) might attack unit X, Unit B (second fastest unit) might want to attack X as well, but has to pick another target if A manages to kill X off in his round. B will then wait until the death of X to attack his alternative target Y, which might look imperfect (why does he sometimes attack Y after X has died and sometimes before X dies) (or it might look better if you think that magically knowing that X will die is unnatural). B would also have to announce his alternative target so that C can attack without waiting until B has decided on one in case where C attacks a unit other than X or Y. This will probably be harder to do since you need to mix calculation and action as part of your algorithm.

For a more concrete answer, we will need additional information anyway. Questions i still had while reading were:
If unit A has 1 hit left and attacks unit X who has 3 hits left, will A hit once and X 3 times, or does A return after having done 1 hit?
If unit A kills unit X and still has hits left, will it pick a different target until it has no hits left? (ive got a feeling that this would make the on-the-fly-method pretty darn complex)
RNG question from above
 
Status
Not open for further replies.
Top