• 🏆 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!

[Trigger] Index Recycling

Status
Not open for further replies.
Level 16
Joined
Jun 24, 2009
Messages
1,409
I decided to make a new index recycling system because everyone says that the current one I use isn't the best. So I made a new one, how about it? Is it okay? Or is it better than the previous? (You can check the old in my uploaded spells)
  • Init
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Visibility - Disable fog of war
      • Visibility - Disable black mask
      • Set WMax = 20
      • Set WCount = 0
      • For each (Integer A) from 1 to WMax, do (Actions)
        • Loop - Actions
          • Set WRecycle[(Integer A)] = True
          • Custom script: set udg_WDummyGroup[GetForLoopIndexA()] = CreateGroup()
  • Windcutter
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Windcutter
    • Actions
      • Set WGet = False
      • For each (Integer A) from 1 to WMax, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • WGet Equal to False
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • WRecycle[(Integer A)] Equal to True
                • Then - Actions
                  • Set WIndex = (Integer A)
                  • Set WGet = True
                • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Integer A) Equal to WMax
                    • Then - Actions
                      • Set WMax = (WMax + 1)
                      • Set WRecycle[((Integer A) + 1)] = True
                    • Else - Actions
            • Else - Actions
      • Set WCaster[WIndex] = (Triggering unit)
      • Set WTargetPoint[WIndex] = (Target point of ability being cast)
      • Set WDamage[WIndex] = (Real((Level of Windcutter for WCaster[WIndex])))
      • Set WTimer[WIndex] = (2.00 + (Real((Level of Windcutter for WCaster[WIndex]))))
      • For each (Integer A) from 1 to 6, do (Actions)
        • Loop - Actions
          • Set TempPoint[1] = (WTargetPoint[WIndex] offset by 150.00 towards (60.00 x (Real((Integer A)))) degrees)
          • Unit - Create 1 Wind for (Owner of WCaster[WIndex]) at TempPoint[1] facing ((Angle from WTargetPoint[WIndex] to TempPoint[1]) + 90.00) degrees
          • Unit Group - Add (Last created unit) to WDummyGroup[WIndex]
          • Animation - Change (Last created unit)'s animation speed to (Random real number between 25.00 and 50.00)% of its original speed
          • Unit - Create 1 Windcutter for (Owner of WCaster[WIndex]) at TempPoint[1] facing ((Angle from WTargetPoint[WIndex] to TempPoint[1]) + 90.00) degrees
          • Unit Group - Add (Last created unit) to WDummyGroup[WIndex]
          • Custom script: call RemoveLocation (udg_TempPoint[1])
      • Set WHas[WIndex] = True
      • Set WRecycle[WIndex] = False
      • Set WCount = (WCount + 1)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Windcutter Loop <gen> is on) Equal to False
        • Then - Actions
          • Trigger - Turn on Windcutter Loop <gen>
          • Trigger - Turn on Crush Effect <gen>
        • Else - Actions
  • Windcutter Loop
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • For each (Integer WInteger) from 1 to WMax, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • WHas[WInteger] Equal to True
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • WTimer[WInteger] Greater than 0.00
                • Then - Actions
                  • Set WTimer[WInteger] = (WTimer[WInteger] - 0.03)
                  • Set TempGroup = (Units within 400.00 of WTargetPoint[WInteger] matching ((((Matching unit) is A structure) Equal to False) and ((((Matching unit) is Magic Immune) Equal to False) and ((((Matching unit) is alive) Equal to True) and (((Matching unit) belongs to an enemy of (Ow
                  • Unit Group - Pick every unit in TempGroup and do (Actions)
                    • Loop - Actions
                      • Unit - Cause WCaster[WInteger] to damage (Picked unit), dealing WDamage[WInteger] damage of attack type Spells and damage type Normal
                  • Unit Group - Pick every unit in WDummyGroup[WInteger] and do (Actions)
                    • Loop - Actions
                      • Set TempPoint[2] = (Position of (Picked unit))
                      • Set TempPoint[3] = (WTargetPoint[WInteger] offset by 150.00 towards ((Angle from WTargetPoint[WInteger] to TempPoint[2]) + 10.00) degrees)
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Unit-type of (Picked unit)) Equal to Wind
                        • Then - Actions
                          • Set TempPoint[4] = (WTargetPoint[WInteger] offset by (Random real number between 300.00 and 350.00) towards ((Angle from WTargetPoint[WInteger] to TempPoint[2]) + 10.00) degrees)
                          • Unit - Move (Picked unit) instantly to TempPoint[4], facing ((Angle from WTargetPoint[WInteger] to TempPoint[3]) + 90.00) degrees
                          • Custom script: call RemoveLocation (udg_TempPoint[4])
                        • Else - Actions
                          • Unit - Move (Picked unit) instantly to TempPoint[3], facing ((Angle from WTargetPoint[WInteger] to TempPoint[3]) + 90.00) degrees
                      • Custom script: call RemoveLocation (udg_TempPoint[2])
                      • Custom script: call RemoveLocation (udg_TempPoint[3])
                  • Custom script: call DestroyGroup(udg_TempGroup)
                • Else - Actions
                  • Unit Group - Pick every unit in WDummyGroup[WInteger] and do (Unit - Kill (Picked unit))
                  • Set WHas[WInteger] = False
                  • Set WCount = (WCount - 1)
                  • Custom script: call RemoveLocation (udg_WTargetPoint[udg_WInteger])
                  • Unit Group - Remove all units from WDummyGroup[WInteger]
            • Else - Actions
              • Set WRecycle[WInteger] = True
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • WCount Equal to 0
                • Then - Actions
                  • Trigger - Turn off (This trigger)
                  • Trigger - Turn off Crush Effect <gen>
                • Else - Actions
  • Crush Effect
    • Events
      • Time - Every 0.50 seconds of game time
    • Conditions
    • Actions
      • For each (Integer WInteger) from 1 to WMax, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • WHas[WInteger] Equal to True
            • Then - Actions
              • Set TempGroup = (Units within 400.00 of WTargetPoint[WInteger] matching ((((Matching unit) is A structure) Equal to False) and ((((Matching unit) is Magic Immune) Equal to False) and ((((Matching unit) is alive) Equal to True) and (((Matching unit) belongs to an enemy of (Ow
              • Unit Group - Pick every unit in TempGroup and do (Actions)
                • Loop - Actions
                  • Special Effect - Create a special effect attached to the origin of (Picked unit) using Abilities\Spells\Other\CrushingWave\CrushingWaveDamage.mdl
                  • Special Effect - Destroy (Last created special effect)
              • Custom script: call DestroyGroup(udg_TempGroup)
            • Else - Actions
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,468
For Crush Effect, I would rather do:

  • Crush Effect
    • Events
      • Time - Every 0.50 seconds of game time
    • Conditions
    • Actions
      • For each (Integer WInteger) from 1 to WMax, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • WHas[WInteger] Equal to True
            • Then - Actions
              • Custom script: set bj_wantDestroyGroup = true
              • Unit Group - Pick every unit in (Units within 400.00 of WTargetPoint[WInteger] matching ((((Matching unit) is A structure) Equal to False) and ((((Matching unit) is Magic Immune) Equal to False) and ((((Matching unit) is alive) Equal to True) and (((Matching unit) belongs to an enemy of (Ow and do (Actions)
                • Loop - Actions
                  • Special Effect - Create a special effect attached to the origin of (Picked unit) using Abilities\Spells\Other\CrushingWave\CrushingWaveDamage.mdl
                  • Special Effect - Destroy (Last created special effect)
            • Else - Actions
bj_wantDestroyGroup is a lot more convenient than setting a group variable followed by a custom script to destroy it.

Also, arrays start at 0, not 1, so you should do from 0 to WMax.
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,468
You loop through just to get the last-recycled index, which is totally unnecessary. So that you can understand the idea of strong recycling:

JASS:
// To create something:
if (lastRecycled == 0) then
    set stackSize = stackSize + 1
    set this = stackSize
else
    set this = lastRecycled
    set lastRecycled = recycleStack[lastRecycled]
endif

JASS:
// To destroy something
set recycleStack[this] = lastRecycled
set lastRecycled = this
 
Level 16
Joined
Jun 24, 2009
Messages
1,409
The Count variable only counts that how many instances are currently running. It just turns off the looping triggers if it gets 0 so it can't be "overwritten".
Edit:
It's not a big problem... Just tell me, better than the previous I used?
Edit2:
Hmm, I'll try this out when i'm back, thanks.
 
Status
Not open for further replies.
Top