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

Need some help optimizing an old System

Status
Not open for further replies.
It's been a while since I've done any coding, but I had made this system a looooong time ago and submitted it here, which got rejected. I kinda want to go back and make this worthy of being accepted but I'd like some help determining how to optimize the system as much as possible (aside from the obvious "GUI is like driving an old jalopy, vJass iz da shiz" comments people are going to make, I'm way too lazy to bother jassing this up).

Aside from the the other triggers which have no relevance to the system itself, I thought I had gotten this leak free, though I may be wrong though.


Important triggers:

  • Create Maze
    • Events
    • Conditions
    • Actions
      • -------- Init --------
      • Custom script: set udg_Reference = CreateUnitAtLoc( Player(PLAYER_NEUTRAL_PASSIVE), 'hfoo', udg_StartP, 90.00)
      • Unit Group - Add Reference to MazerGroup
      • Set MazInt = 1
      • Unit - Set the custom value of Reference to MazInt
      • Custom script: set udg_Reference = null
      • For each (Integer LoopInt) from 1 to 1500, do (Actions)
        • Loop - Actions
          • Unit Group - Pick every unit in MazerGroup and do (Actions)
            • Loop - Actions
              • Set P1 = (Position of (Picked unit))
              • -------- Randomness --------
              • Set Probability1 = (Random integer number between 1 and 2)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Probability1 Equal to 1
                • Then - Actions
                  • Set Prob4 = (Random integer number between 1 and (Complexity x 25))
                  • Set Prob5 = (Random integer number between 1 and (Complexity x 70))
                  • Set Probability2 = (Random integer number between 1 and Prob4)
                  • Set Probability3 = (Random integer number between 1 and Prob5)
                  • Set TurnsTurnProbability = (Random integer number between 1 and (Probability2 + Probability3))
                  • Set TurnProbability = (Random integer number between 1 and TurnsTurnProbability)
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Probability1 Equal to 2
                • Then - Actions
                  • Set Prob4 = (Random integer number between 1 and (Complexity x 10))
                  • Set Prob5 = (Random integer number between 70 and (Complexity x 50))
                  • Set Probability2 = (Random integer number between 1 and Prob4)
                  • Set Probability3 = (Random integer number between 1 and Prob5)
                  • Set TurnsTurnProbability = (Random integer number between 1 and (Probability2 - Probability3))
                  • Set TurnProbability = (Random integer number between 1 and TurnsTurnProbability)
                • Else - Actions
              • -------- Turns --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • TurnProbability Equal to 1
                • Then - Actions
                  • -------- Setting which way left or right --------
                  • Set WhichWay = (Random integer number between 1 and 2)
                  • -------- Adding on to the real which determines the angle the path is being carved at --------
                  • -------- It is possible to make mazes with diagnol paths if this is set with values like 45 --------
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • WhichWay Equal to 1
                    • Then - Actions
                      • Set Angle[(Custom value of (Picked unit))] = (Angle[(Custom value of (Picked unit))] + 90.00)
                    • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • WhichWay Equal to 2
                    • Then - Actions
                      • Set Angle[(Custom value of (Picked unit))] = (Angle[(Custom value of (Picked unit))] - 90.00)
                    • Else - Actions
                • Else - Actions
              • -------- Chance for Branch offs --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • TurnProbability Equal to 2
                • Then - Actions
                  • -------- Creating Unit for reference and setting up Dummies for branch offs --------
                  • Custom script: set udg_Reference = CreateUnitAtLoc( Player(PLAYER_NEUTRAL_PASSIVE), 'hfoo', udg_P2, 90.00)
                  • Unit Group - Add Reference to MazerGroup
                  • Set MazInt = (MazInt + 1)
                  • Unit - Set the custom value of Reference to MazInt
                  • Custom script: set udg_Reference = null
                • Else - Actions
              • Set P2 = (P1 offset by 80.00 towards Angle[(Custom value of (Picked unit))] degrees)
              • -------- ClearTrees/Check Pathing --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (MaxArea contains P2) Equal to True
                  • (Terrain pathing at P2 of type Flyability is off) Equal to False
                • Then - Actions
                  • -------- Moving dummy and checking for Trees (destructables) --------
                  • Unit - Move (Picked unit) instantly to P2
                  • Destructible - Pick every destructible within PathSize of P2 and do (Actions)
                    • Loop - Actions
                      • -------- Killing and hiding the corpse --------
                      • Destructible - Kill (Picked destructible)
                      • Destructible - Hide (Picked destructible)
                • Else - Actions
                  • -------- Turning maze if the current path is not pathable or out of limits --------
                  • Set Angle[(Custom value of (Picked unit))] = (Angle[(Custom value of (Picked unit))] - 180.00)
              • -------- An Example of Loot --------
              • -------- This first item creation example creates the flag or "endpoint" of the maze, this doesnt have to be an item but it needs to be something that allows the units in out (like stairways or something) --------
              • -------- This is made at the end of the maze, when the loop integer gets to its highest value --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • LoopInt Equal to 1500
                • Then - Actions
                  • Item - Create Flag at P2
                  • -------- Remove trees around the flag --------
                  • Destructible - Pick every destructible within 400.00 of P2 and do (Actions)
                    • Loop - Actions
                      • Destructible - Kill (Picked destructible)
                      • Destructible - Hide (Picked destructible)
                • Else - Actions
              • -------- Setting int for loot creation --------
              • Set ChanceForLoot = (Random integer number between 1 and (IntegerforLootSpawn x 40))
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • ChanceForLoot Equal to 1
                • Then - Actions
                  • -------- creating loot --------
                  • Item - Create LootType[1] at P2
                • Else - Actions
              • -------- Example of Enemies --------
              • -------- Setting int for enemies --------
              • Set ChanceForEnemies = (Random integer number between 1 and (EnemyDifficultyInt x 60))
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • ChanceForEnemies Less than or equal to 2
                • Then - Actions
                  • -------- Creating Enemies, Custom script to make it more efficiant --------
                  • Custom script: call CreateUnitAtLoc( udg_EnemyPlayer, udg_EnemyType[1], udg_P2, GetRandomDirectionDeg() )
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • ChanceForEnemies Equal to 3
                • Then - Actions
                  • -------- Creating enemies --------
                  • Custom script: call CreateUnitAtLoc( udg_EnemyPlayer, udg_EnemyType[2], udg_P2, GetRandomDirectionDeg() )
                  • Destructible - Pick every destructible within 200.00 of P2 and do (Actions)
                    • Loop - Actions
                      • Destructible - Kill (Picked destructible)
                      • Destructible - Hide (Picked destructible)
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • ChanceForEnemies Greater than or equal to 4
                  • ChanceForEnemies Less than or equal to 5
                • Then - Actions
                  • -------- Creating enemies --------
                  • Custom script: call CreateUnitAtLoc( Player(PLAYER_NEUTRAL_PASSIVE), udg_EnemyType[3], udg_P2, GetRandomDirectionDeg() )
                  • Destructible - Pick every destructible within 300.00 of P2 and do (Actions)
                    • Loop - Actions
                      • Destructible - Kill (Picked destructible)
                      • Destructible - Hide (Picked destructible)
                • Else - Actions
              • -------- Example of Terrain and other Doodads, since they cant be places via triggers, use special effects instead --------
              • -------- Setting int for special effects --------
              • Set SXProbability = (Random integer number between 1 and (ChanceForTerrain x 5))
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • SXProbability Equal to 1
                • Then - Actions
                  • -------- Setting int for which sx --------
                  • Set WhichSxtoMake = (Random integer number between 1 and 5)
                  • -------- Moving rect so special effects arent just placed only in the center of the path --------
                  • Region - Center RectForSXPlacement on P2
                  • -------- Setting point --------
                  • Set PForSxPlacement = (Random point in RectForSXPlacement)
                  • -------- Creating SX --------
                  • Special Effect - Create a special effect at PForSxPlacement using SpecialEffectTypes[WhichSxtoMake]
                  • -------- Setting variables --------
                  • Set NoofSx = (NoofSx + 1)
                  • Set MazeSx[NoofSx] = (Last created special effect)
                • Else - Actions
              • Custom script: call RemoveLocation(udg_P2)
              • Custom script: call RemoveLocation(udg_P1)
      • Wait 0.10 seconds
      • -------- Removing dummies --------
      • Unit Group - Pick every unit in MazerGroup and do (Actions)
        • Loop - Actions
          • Unit - Kill (Picked unit)
      • -------- Removing crap from group --------
      • Unit Group - Remove all units from MazerGroup
      • Wait 0.50 seconds
      • -------- Setting the ground terrain, change the size and shape so it fits your map --------
      • Environment - Change terrain type at (Center of MaxArea) to Tile using variation -1 in an area of size 29 and shape Square
      • -------- Next action not required --------
      • Trigger - Run Create Units <gen> (checking conditions)

The unit groups on this one leak, I'll have to fix that


  • Trigger CreateMaze
    • Events
      • Player - Player 1 (Red) types a chat message containing -Maze as An exact match
      • Player - Player 2 (Blue) types a chat message containing -Maze as An exact match
      • Player - Player 3 (Teal) types a chat message containing -Maze as An exact match
      • Player - Player 4 (Purple) types a chat message containing -Maze as An exact match
      • Player - Player 5 (Yellow) types a chat message containing -Maze as An exact match
      • Player - Player 6 (Orange) types a chat message containing -Maze as An exact match
    • Conditions
    • Actions
      • -------- Change the actions as needed, you could even have no Events and have this activated by another trigger --------
      • -------- Change depending on what you need, remove the vis creater if you dont want to see the maze reset --------
      • Visibility - Create an initially Enabled visibility modifier for Player 1 (Red) emitting Visibility across (Playable map area)
      • Visibility - Destroy (Last created visibility modifier)
      • -------- Required --------
      • For each (Integer A) from 1 to NoofSx, do (Actions)
        • Loop - Actions
          • Special Effect - Destroy MazeSx[(Integer A)]
      • Unit Group - Pick every unit in (Units of type Maze Man) and do (Actions)
        • Loop - Actions
          • Unit - Replace (Picked unit) with a Knight using The old unit's relative life and mana
      • Unit Group - Pick every unit in (Units of type ) and do (Actions)
        • Loop - Actions
          • Unit - Remove (Picked unit) from the game
      • -------- Change with themes you need --------
      • Destructible - Pick every destructible in MaxArea and do (Actions)
        • Loop - Actions
          • Set PointForMakeDestructables = (Position of (Picked destructible))
          • Destructible - Remove (Picked destructible)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • IntegerforTheme Equal to 1
            • Then - Actions
              • Destructible - Create a Ashenvale Tree Wall at PointForMakeDestructables facing (Random angle) with scale 1.00 and variation 0
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • IntegerforTheme Equal to 2
            • Then - Actions
              • Destructible - Create a Magic Box at PointForMakeDestructables facing (Random angle) with scale 1.00 and variation 0
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • IntegerforTheme Equal to 3
            • Then - Actions
              • Destructible - Create a Rock Chunks at PointForMakeDestructables facing (Random angle) with scale 1.00 and variation 0
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • IntegerforTheme Equal to 4
            • Then - Actions
              • Destructible - Create a Green Rock at PointForMakeDestructables facing (Random angle) with scale 1.00 and variation 0
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • IntegerforTheme Equal to 5
            • Then - Actions
              • Destructible - Create a Icecrown Tree Wall at PointForMakeDestructables facing (Random angle) with scale 1.00 and variation 0
            • Else - Actions
          • Custom script: call RemoveLocation(udg_PointForMakeDestructables)
      • -------- Alter as needed, the units will either have to be removed or moved somewhere --------
      • Unit Group - Pick every unit in (Units owned by Player 7 (Green)) and do (Actions)
        • Loop - Actions
          • Unit - Remove (Picked unit) from the game
      • Unit Group - Pick every unit in (Units owned by Neutral Passive) and do (Actions)
        • Loop - Actions
          • Unit - Remove (Picked unit) from the game
      • -------- Alter as needed, the items will either have to be removed or moved somewhere --------
      • Item - Pick every item in (Playable map area) and do (Item - Remove (Picked item))
      • -------- Alter as needed --------
      • Game - Display to (All players) the text: Randomizing...........
      • Wait 1.00 seconds
      • Visibility - Create an initially Enabled visibility modifier for Player 1 (Red) emitting Black mask across (Playable map area)
      • Visibility - Destroy (Last created visibility modifier)
      • Wait 1.50 seconds
      • Trigger - Run Create Maze <gen> (checking conditions)
 

Attachments

  • Wherewolfs Random Maze Generator v2.w3x
    54.7 KB · Views: 30

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,202
Set Probability1 = (Random integer number between 1 and 2)
If (All Conditions are True) then do (Then Actions) else do (Else Actions)

If - Conditions

Probability1 Equal to 1

Then - Actions

Set Prob4 = (Random integer number between 1 and (Complexity x 25))
Set Prob5 = (Random integer number between 1 and (Complexity x 70))
Set Probability2 = (Random integer number between 1 and Prob4)
Set Probability3 = (Random integer number between 1 and Prob5)
Set TurnsTurnProbability = (Random integer number between 1 and (Probability2 + Probability3))
Set TurnProbability = (Random integer number between 1 and TurnsTurnProbability)

Else - Actions

If (All Conditions are True) then do (Then Actions) else do (Else Actions)

If - Conditions

Probability1 Equal to 2

Then - Actions

Set Prob4 = (Random integer number between 1 and (Complexity x 10))
Set Prob5 = (Random integer number between 70 and (Complexity x 50))
Set Probability2 = (Random integer number between 1 and Prob4)
Set Probability3 = (Random integer number between 1 and Prob5)
Set TurnsTurnProbability = (Random integer number between 1 and (Probability2 - Probability3))
Set TurnProbability = (Random integer number between 1 and TurnsTurnProbability)

You could get rid of the conditional here by making the same code execute but getting the values from an integer array. The index for the array is governed by the output integer for probability.

If (All Conditions are True) then do (Then Actions) else do (Else Actions)

If - Conditions

TurnProbability Equal to 1

Then - Actions

-------- Setting which way left or right --------
Set WhichWay = (Random integer number between 1 and 2)
-------- Adding on to the real which determines the angle the path is being carved at --------
-------- It is possible to make mazes with diagnol paths if this is set with values like 45 --------
If (All Conditions are True) then do (Then Actions) else do (Else Actions)

If - Conditions

WhichWay Equal to 1

Then - Actions

Set Angle[(Custom value of (Picked unit))] = (Angle[(Custom value of (Picked unit))] + 90.00)

Else - Actions

If (All Conditions are True) then do (Then Actions) else do (Else Actions)

If - Conditions

WhichWay Equal to 2

Then - Actions

Set Angle[(Custom value of (Picked unit))] = (Angle[(Custom value of (Picked unit))] - 90.00)

Else - Actions

Else - Actions

Like wise here, you could use the same code with a table of values using probability as an index.
If (All Conditions are True) then do (Then Actions) else do (Else Actions)

If - Conditions

ChanceForEnemies Equal to 3

Then - Actions

-------- Creating enemies --------
Custom script: call CreateUnitAtLoc( udg_EnemyPlayer, udg_EnemyType[2], udg_P2, GetRandomDirectionDeg() )
Destructible - Pick every destructible within 200.00 of P2 and do (Actions)

Loop - Actions

Destructible - Kill (Picked destructible)
Destructible - Hide (Picked destructible)

Else - Actions

If (All Conditions are True) then do (Then Actions) else do (Else Actions)

If - Conditions

ChanceForEnemies Greater than or equal to 4
ChanceForEnemies Less than or equal to 5

Then - Actions

-------- Creating enemies --------
Custom script: call CreateUnitAtLoc( Player(PLAYER_NEUTRAL_PASSIVE), udg_EnemyType[3], udg_P2, GetRandomDirectionDeg() )
Destructible - Pick every destructible within 300.00 of P2 and do (Actions)

Loop - Actions

Destructible - Kill (Picked destructible)
Destructible - Hide (Picked destructible)

Else - Actions
And again here, these 2 conditional statements run prety much the same code buth with different values so you could probably merge the code using arrays.

Set WhichSxtoMake = (Random integer number between 1 and 5)
-------- Moving rect so special effects arent just placed only in the center of the path --------
Region - Center RectForSXPlacement on P2
-------- Setting point --------
Set PForSxPlacement = (Random point in RectForSXPlacement)
-------- Creating SX --------
Special Effect - Create a special effect at PForSxPlacement using SpecialEffectTypes[WhichSxtoMake]
-------- Setting variables --------
.........NOT the line that was here, the code here is not covered by this optimization.........
Set MazeSx[NoofSx] = (Last created special effect)
All this can be compacted to 1 line of code. The point can be referenced as X and Y representing the middle. Thus you basically create a special effect at an X of RandomReal(P2xcomponent-rectwidth/2,P2xcomponent+rectwidth/2) and Y of RandomReal(P2ycomponent-rectheight/2,P2ycomponent+rectheight/2)

As the rect size does not undergo any chagnes. This means it solves as a constant in the above so you get a cordinate component +/- a constant in the range of X and Y. As there is a native which takes X and Y components when making an effect and returns the created effect, you can set the variable instantly to the created special effect made at a random X and random Y cordinate (using method descibed above) all in 1 line. Even the random index can be thrown onto the line as it is not used elsewhere so there is no need to store it.

This would be a pretty good optimization, removing 1 location, a rect, several globals and reducing to 1 line of code. I am not however sure you can do this in GUI but for the gain I would strongly recommend doing this (even if you do it via a custom script action). It also fixes a location leak (you never removed the random location contained within the rect you created).

Unit Group - Pick every unit in MazerGroup and do (Actions)

Loop - Actions

Unit - Kill (Picked unit)
Apparently you must make units explode before killing them otherwise they leak, or so people say.

Environment - Change terrain type at (Center of MaxArea) to Tile using variation -1 in an area of size 29 and shape Square
Leaks a location "(Center of MaxArea)".
Destructible - Pick every destructible in MaxArea and do (Actions)

Loop - Actions

Set PointForMakeDestructables = (Position of (Picked destructible))
Destructible - Remove (Picked destructible)
If (All Conditions are True) then do (Then Actions) else do (Else Actions)

If - Conditions

IntegerforTheme Equal to 1

Then - Actions

Destructible - Create a Ashenvale Tree Wall at PointForMakeDestructables facing (Random angle) with scale 1.00 and variation 0

Else - Actions

If (All Conditions are True) then do (Then Actions) else do (Else Actions)

If - Conditions

IntegerforTheme Equal to 2

Then - Actions

Destructible - Create a Magic Box at PointForMakeDestructables facing (Random angle) with scale 1.00 and variation 0

Else - Actions

If (All Conditions are True) then do (Then Actions) else do (Else Actions)

If - Conditions

IntegerforTheme Equal to 3

Then - Actions

Destructible - Create a Rock Chunks at PointForMakeDestructables facing (Random angle) with scale 1.00 and variation 0

Else - Actions

If (All Conditions are True) then do (Then Actions) else do (Else Actions)

If - Conditions

IntegerforTheme Equal to 4

Then - Actions

Destructible - Create a Green Rock at PointForMakeDestructables facing (Random angle) with scale 1.00 and variation 0

Else - Actions

If (All Conditions are True) then do (Then Actions) else do (Else Actions)

If - Conditions

IntegerforTheme Equal to 5

Then - Actions

Destructible - Create a Icecrown Tree Wall at PointForMakeDestructables facing (Random angle) with scale 1.00 and variation 0

Else - Actions

Custom script: call RemoveLocation(udg_PointForMakeDestructables)
2 optimizations possible here. The first should be apparent now. Same code, low scope integer conditions and lots of branching. All the conditional testing could be removed and replaced with a 1 line of creating a destructable of type retreived from an integer array with index theme. This is prety much the same as the first few I described but to a much larger extent.

The second optimization would be to map all destrucables into an array with their accompanying locations and itterating through them (if under 2^13 in quantity). As the locations are static, no need for them to be removed (if you want you could use X and Y pairs) and also you can remove the destructables without having to do an area search. This is a rather padantic optimization which may bring its own problems (op limit) so you may wish to only perform the first one.
Unit Group - Pick every unit in (Units owned by Player 7 (Green)) and do (Actions)

Loop - Actions

Unit - Remove (Picked unit) from the game

Unit Group - Pick every unit in (Units owned by Neutral Passive) and do (Actions)

Loop - Actions

Unit - Remove (Picked unit) from the game
leaks 2 groups, also it may leak the units if all the talk about removing units leaking is correct. Use make explode and then kill instead.
 
Status
Not open for further replies.
Top