• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[AI] Removing unwanted units

Status
Not open for further replies.
Hey everyone

I made major changes to my AI by rebuilding the ITE order to improve speed and preformance. It is still far from finish though. I've found that after the AI killed a unit, it moves to the dying unit's location and stands there until it totally disappears. I assumed that it keeps 'attacking' the dead unit.

pCenter = Center of playable map area
gNatural[0] = weak animals
gNatural[1] = strong animals
AI_Count = number of Computer players
AI_Circle = base

  • Combat Copy Copy
    • Events
      • Time - Every 0.50 seconds of game time
    • Conditions
    • Actions
      • For each (Integer Temp_Int) from 1 to AI_Count, do (Actions)
        • Loop - Actions
          • -------- <<RETREAT>> --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Integer((Life of AI_Hero[Temp_Int]))) Less than or equal to ((Integer((Max life of AI_Hero[Temp_Int]))) / 3)
            • Then - Actions
              • Unit - Order AI_Hero[Temp_Int] to Move To ((Owner of AI_Hero[Temp_Int]) start location)
              • Unit Group - Add AI_Hero[Temp_Int] to gRetreat
              • Unit - Order AI_Circle[Temp_Int] to Human Paladin - Holy Light AI_Hero[Temp_Int]
              • Skip remaining actions
            • Else - Actions
          • -------- <<COMBAT>> --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Or - Any (Conditions) are true
                • Conditions
                  • (Current order of AI_Hero[Temp_Int]) Equal to (Order(stop))
                  • ((Current order of AI_Hero[Temp_Int]) Equal to (Order(move))) and ((AI_Hero[Temp_Int] is in gRetreat) Equal to False)
                  • (Current order of AI_Hero[Temp_Int]) Not equal to (Order(attack))
            • Then - Actions
              • -------- <<HEROS>> --------
              • Set Temp_Point = (Position of AI_Hero[Temp_Int])
              • Set Temp_Enemies = (Units within 750.00 of Temp_Point matching (((Owner of (Matching unit)) is an enemy of (Owner of AI_Hero[Temp_Int])) Equal to True))
              • Unit Group - Pick every unit in Temp_Enemies and do (Actions)
                • Loop - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • Or - Any (Conditions) are true
                        • Conditions
                          • ((Picked unit) is invisible to (Owner of AI_Hero[Temp_Int])) Equal to True
                          • ((AI_Hero[Temp_Int] is Able to attack flying units) Equal to False) and (((Picked unit) is A flying unit) Equal to True)
                          • ((Picked unit) is dead) Equal to True
                          • (Level of Locust for (Picked unit)) Equal to 1
                    • Then - Actions
                      • Unit Group - Remove (Picked unit) from Temp_Group
                    • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Temp_Enemies is empty) Equal to False
                • Then - Actions
                  • Unit - Order AI_Hero[Temp_Int] to Attack (Random unit from Temp_Enemies)
                  • Custom script: call DestroyGroup(udg_Temp_Enemies)
                  • Skip remaining actions
                • Else - Actions
                  • Custom script: call DestroyGroup(udg_Temp_Enemies)
                  • -------- <<ANIMALS>> --------
                  • Set Temp_Enemies = (Units within 750.00 of Temp_Point matching ((((Matching unit) is in gNatural[0]) Equal to True) or (((Matching unit) is in gNatural[1]) Equal to True)))
                  • Unit Group - Pick every unit in Temp_Enemies and do (Actions)
                    • Loop - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • Or - Any (Conditions) are true
                            • Conditions
                              • ((Picked unit) is invisible to (Owner of AI_Hero[Temp_Int])) Equal to True
                              • ((AI_Hero[Temp_Int] is Able to attack flying units) Equal to False) and (((Picked unit) is A flying unit) Equal to True)
                              • ((Picked unit) is dead) Equal to True
                              • (Level of Locust for (Picked unit)) Equal to 1
                              • (Level of (Picked unit)) Greater than ((Hero level of AI_Hero[Temp_Int]) + 1)
                        • Then - Actions
                          • Unit Group - Remove (Picked unit) from Temp_Enemies
                        • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Temp_Enemies is empty) Equal to False
                    • Then - Actions
                      • Unit - Order AI_Hero[Temp_Int] to Attack (Random unit from Temp_Enemies)
                      • Custom script: call RemoveLocation(udg_Temp_Point)
                      • Custom script: call DestroyGroup(udg_Temp_Enemies)
                      • Skip remaining actions
                    • Else - Actions
                      • Custom script: call RemoveLocation(udg_Temp_Point)
                      • Custom script: call DestroyGroup(udg_Temp_Enemies)
                      • Unit - Order AI_Hero[Temp_Int] to Move To (pCenter offset by (Random real number between 0.00 and 6000.00) towards (Random real number between 0.00 and 360.00) degrees)
            • Else - Actions
Help will be appreciated
 
Check if the unit is alive in your unit group filter.

"(Matching Unit) life Greater Than 0.405" or "(Matching Unit) is Alive"

  • Set Temp_Enemies = (Units within 750.00 of Temp_Point matching (((Owner of (Matching unit)) is an enemy of (Owner of AI_Hero[Temp_Int])) Equal to True) and (Matching Unit) life Greater Than 0.405)
 
Nice! that seems to slove it :)

I've also just found another problem: the hero keeps moving to a random point when all the conditions is false till the very last action. The hero IS moving and his health was never low enought to jump into the gRetreat gourp so:
  • ((Current order of AI_Hero[Temp_Int]) Equal to (Order(move))) and ((AI_Hero[Temp_Int] is in gRetreat) Equal to False)
Now why is the hero still moving around?

EDIT: 0.41 is low enough but thanks for the info :)
 
If you compare hero's life, why convert it in an integer? Just make a real comparrison.

And in upper part, dont use Skip remaining actions.. this will stop whole loop , so for all other units there wont be any actions, not only for this unit. Instead put the other actions into the Else - Actions so they won't be checked anymore.

In next block you use "order =! attack" in a multiple Or Conditions block.. I guess you have to rethink that, because actions will always run if unit has an order that not equals attack.

Next.. if,
  • (Temp_Enemies is empty) Equal to False
dont skip remaining actions again.. same reason as above. And you also forget to remove location in this case.

Then once more Skip remaining actions in next lines, remove it.

I dont understand the sense of the action, but you leak in this line
  • Unit - Order AI_Hero[Temp_Int] to Move To (pCenter offset by (Random real number between 0.00 and 6000.00) towards (Random real number between 0.00 and 360.00) degrees)
Set a tmp_point to to the point you wanna move your hero, move your hero to this variable, and remove location afterwerds.

Also store 'Picked unit' into an unit variable if you use it more often.
 
Status
Not open for further replies.
Top