Hello there.
I'm trying to work on an attacking system for my map and I could use some help regarding letting a couple of events happen in a certain order.
I'll explain to you how the attacking works in the map:
Attacking goes in groups. So there's a group with 'attackers' and a group with 'defenders'. The maximum amount of units in a group is 16.
Every unit can do a couple of attacks equal to his strength. So a strength of 3 allows the unit to do 3 attacks. A full group of those units will attack in 3x 16 hits because a full group is 16 units. Clear? ;-)
But inbetween those 3*16 hits the defenders can also strike. The order is basically like this in a 16vs16 fight:
Attackers Strike (x16)-> Defenders Strike (x16 (if all 16 survived))-> Attackers Strike (x16 (if all survived...)) - Defenders Strike... etc
This will go on until both sides run out of attacks.
If, let's say, the attackers have 3 attacks and the defenders have only 1 it will work like this:
Attackers strike -> Defenders strike -> Attackers strike -> Attackers strike
Now there are also some exceptions:
There's an ability called 'First Strike' and an ability called 'Last Strike'. This can seriously make the order a bit more difficult.
If in a scenario the attackers have Last Strike and the Defenders are normal, and both sides have 2 attacks, it will go like this:
Defenders strike > Attackers Strike > Defender sstrike > Attackers strike...
The above outcome will be the same when the defenders have first strike and the attackers are normal.
Now the tricky part comes that a group of units can have some units in it with First Strike and some others without it. This could lead to something like this:
Defenders (with First Strike) strike -> Attackers strike -> Defenders (with First Strike + normal defenders) strike -> Attackers strike -> Defenders (without First Strike) strike.
The above result means that all units must've struck twice, but the 'First Strike Defenders' just started attacking a bit earlier.
Enough of that! Here's my question:
Would someone know a good way to create this kind of an order and execute it in a correct but efficient way? (Don't mind the BJ's and all I use at the bottom of the code. This is just to practise)
Here's the part of the code I have so far that creates the order.
There are some flaws with it.
I'm trying to work on an attacking system for my map and I could use some help regarding letting a couple of events happen in a certain order.
I'll explain to you how the attacking works in the map:
Attacking goes in groups. So there's a group with 'attackers' and a group with 'defenders'. The maximum amount of units in a group is 16.
Every unit can do a couple of attacks equal to his strength. So a strength of 3 allows the unit to do 3 attacks. A full group of those units will attack in 3x 16 hits because a full group is 16 units. Clear? ;-)
But inbetween those 3*16 hits the defenders can also strike. The order is basically like this in a 16vs16 fight:
Attackers Strike (x16)-> Defenders Strike (x16 (if all 16 survived))-> Attackers Strike (x16 (if all survived...)) - Defenders Strike... etc
This will go on until both sides run out of attacks.
If, let's say, the attackers have 3 attacks and the defenders have only 1 it will work like this:
Attackers strike -> Defenders strike -> Attackers strike -> Attackers strike
Now there are also some exceptions:
There's an ability called 'First Strike' and an ability called 'Last Strike'. This can seriously make the order a bit more difficult.
If in a scenario the attackers have Last Strike and the Defenders are normal, and both sides have 2 attacks, it will go like this:
Defenders strike > Attackers Strike > Defender sstrike > Attackers strike...
The above outcome will be the same when the defenders have first strike and the attackers are normal.
Now the tricky part comes that a group of units can have some units in it with First Strike and some others without it. This could lead to something like this:
Defenders (with First Strike) strike -> Attackers strike -> Defenders (with First Strike + normal defenders) strike -> Attackers strike -> Defenders (without First Strike) strike.
The above result means that all units must've struck twice, but the 'First Strike Defenders' just started attacking a bit earlier.
Enough of that! Here's my question:
Would someone know a good way to create this kind of an order and execute it in a correct but efficient way? (Don't mind the BJ's and all I use at the bottom of the code. This is just to practise)
Here's the part of the code I have so far that creates the order.
There are some flaws with it.
JASS:
call GroupEnumUnitsInRect(ATTACKERS, Field[ax][ay], null)
call GroupEnumUnitsInRect(DEFENDERS, Field[dx][dy], null)
///Adding First Strike Attackers first
call GroupEnumUnitsInRect(g, Field[ax][ay], null)
set t = FirstOfGroup(g)
loop
exitwhen t == null
if GetUnitAbilityLevel(t, FIRST_STRIKE) > 0 and GetUnitAbilityLevel(t, LAST_STRIKE) == 0 then
set AttackOrder[i] = t
set i = i + 1
call PauseUnit(t, true)
endif
call GroupRemoveUnit(g, t)
set t = FirstOfGroup(g)
endloop
call GroupClear(g)
///Adding First Strike Defenders second
call GroupEnumUnitsInRect(g, Field[dx][dy], null)
set t = FirstOfGroup(g)
loop
exitwhen t == null
if GetUnitAbilityLevel(t, FIRST_STRIKE) > 0 and GetUnitAbilityLevel(t, LAST_STRIKE) == 0 then
set AttackOrder[i] = t
set i = i + 1
call PauseUnit(t, true)
endif
call GroupRemoveUnit(g, t)
set t = FirstOfGroup(g)
endloop
call GroupClear(g)
///Adding Normal Attackers third
call GroupEnumUnitsInRect(g, Field[ax][ay], null)
set t = FirstOfGroup(g)
loop
exitwhen t == null
if GetUnitAbilityLevel(t, FIRST_STRIKE) == 0 and GetUnitAbilityLevel(t, LAST_STRIKE) == 0 then
set AttackOrder[i] = t
set i = i + 1
call PauseUnit(t, true)
elseif GetUnitAbilityLevel(t, FIRST_STRIKE) > 0 and GetUnitAbilityLevel(t, LAST_STRIKE) > 0 then
set AttackOrder[i] = t
set i = i + 1
call PauseUnit(t, true)
endif
call GroupRemoveUnit(g, t)
set t = FirstOfGroup(g)
endloop
call GroupClear(g)
///Adding Normal Defenders fourth
call GroupEnumUnitsInRect(g, Field[dx][dy], null)
set t = FirstOfGroup(g)
loop
exitwhen t == null
if GetUnitAbilityLevel(t, FIRST_STRIKE) == 0 and GetUnitAbilityLevel(t, LAST_STRIKE) == 0 then
set AttackOrder[i] = t
set i = i + 1
call PauseUnit(t, true)
elseif GetUnitAbilityLevel(t, FIRST_STRIKE) > 0 and GetUnitAbilityLevel(t, LAST_STRIKE) > 0 then
set AttackOrder[i] = t
set i = i + 1
call PauseUnit(t, true)
endif
call GroupRemoveUnit(g, t)
set t = FirstOfGroup(g)
endloop
call GroupClear(g)
///Adding Slow Attackers fifth
call GroupEnumUnitsInRect(g, Field[ax][ay], null)
set t = FirstOfGroup(g)
loop
exitwhen t == null
if GetUnitAbilityLevel(t, FIRST_STRIKE) == 0 and GetUnitAbilityLevel(t, LAST_STRIKE) > 0 then
set AttackOrder[i] = t
set i = i + 1
call PauseUnit(t, true)
endif
call GroupRemoveUnit(g, t)
set t = FirstOfGroup(g)
endloop
call GroupClear(g)
///Adding Slow Defenders fourth
call GroupEnumUnitsInRect(g, Field[dx][dy], null)
set t = FirstOfGroup(g)
loop
exitwhen t == null
if GetUnitAbilityLevel(t, FIRST_STRIKE) == 0 and GetUnitAbilityLevel(t, LAST_STRIKE) > 0 then
set AttackOrder[i] = t
set i = i + 1
call PauseUnit(t, true)
endif
call GroupRemoveUnit(g, t)
set t = FirstOfGroup(g)
endloop
call GroupClear(g)
loop
exitwhen f > i
if f <= i then
if IsUnitAliveBJ(AttackOrder[f]) == true then ///change later
set Attacks = GetHeroStr(AttackOrder[f], true)
loop
exitwhen Attacks <= 0
set id = GetUnitId(AttackOrder[f])
call SetUnitAnimation(AttackOrder[f], "attack")
call QueueUnitAnimation(AttackOrder[f], "stand")
if IsUnitInGroup(AttackOrder[f], ATTACKERS) == true then
set Target = GroupPickRandomUnit(DEFENDERS) ///change later
elseif IsUnitInGroup(AttackOrder[f], DEFENDERS) == true then
set Target = GroupPickRandomUnit(ATTACKERS) ///change later
endif
set Armor = Unit_Armor[GetUnitId(Target)]
set Damage = GetRandomInt(Unit_DamageMin[id], Unit_DamageMax[id])
set Attacks = Attacks - 1
endloop
set f = f + 1
else
set f = f + 1
endif
endif
endloop
set i = 0
set f = 0