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

Combine Towers [2x2] problem

Status
Not open for further replies.
Level 6
Joined
Mar 27, 2019
Messages
51
Hey folks,

I have a Combine System that works pretty good for the most part, if you have 4 Towers adjacent to each other like this:

na.png

It will turn to a bigger Tower that takes the same amount of space. All working good, however if I intend to upgrade 12 Towers in a line like this simultaneously, they won't combine from Top Left to Bottom Right sometimes, depends on how they were built (atleast I think so).

Here is an example what I mean, the red one "-" should not have those normal Towers inbetween them, they should be like the green one "+"


nh.png

Any way to achieve this easily.

Example Map is downloadable. Here is also the Trigger

  • Tower l Mega Tower
    • Events
      • Unit - A unit Finishes an upgrade
    • Conditions
      • ((Triggering unit) is A town-hall-type unit) Equal to Falsch
    • Actions
      • Set VariableSet Temp_Type = Mega Tower
      • -------- Save Upgraded --------
      • Hashtable - Save upgraded as 12 of (Key (Triggering unit).) in Hashtable.
      • Set VariableSet Temp_Boolean = Falsch
      • Set VariableSet Temp_Point = (Position of (Triggering unit))
      • Set VariableSet Temp_Unit = (Triggering unit)
      • -------- Nil every Temp_Dummy --------
      • For each (Integer A) from 0 to 3, do (Actions)
        • Loop - Actions
          • Set VariableSet Temp_Dummy[(Integer A)] = No unit
      • -------- Top Left --------
      • Set VariableSet Temp_Real = -1.00
      • Set VariableSet Temp_Integer = 0
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Temp_Boolean Equal to Falsch
        • Then - Actions
          • For each (Integer A) from 1 to 2, do (Actions)
            • Loop - Actions
              • For each (Integer B) from 1 to 2, do (Actions)
                • Loop - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • Temp_Real Equal to -1.00
                    • Then - Actions
                      • -------- Find every Unit in specific Corner --------
                      • Set VariableSet Temp_X = ((Real(((Integer A) - 1))) x 128.00)
                      • Set VariableSet Temp_Y = ((Real(((Integer B) - 1))) x -128.00)
                      • Set VariableSet Temp_Point_2 = (Temp_Point offset by (Temp_X, Temp_Y))
                      • Set VariableSet Temp_Group = (Units within 8.00 of Temp_Point_2 matching ((((Matching unit) is alive) Equal to Wahr) and (((Unit-type of (Matching unit)) Equal to (Unit-type of (Triggering unit))) and ((Load 12 of (Key (Matching unit).) from Hashtable.) Equal to upgraded))).)
                      • Set VariableSet Temp_Dummy[(((Integer A) x 2) - (Integer B))] = (Random unit from Temp_Group)
                      • Set VariableSet Temp_Integer = (Temp_Integer + (Number of units in Temp_Group))
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Number of units in Temp_Group) Equal to 0
                        • Then - Actions
                          • -------- Cancel if no Unit was found early on --------
                          • Set VariableSet Temp_Real = 0.00
                        • Else - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • Temp_Integer Equal to 4
                        • Then - Actions
                          • -------- All Units found, proceeding to Create Structure --------
                          • Set VariableSet Temp_X = 64.00
                          • Set VariableSet Temp_Y = -64.00
                          • Set VariableSet Temp_Boolean = Wahr
                        • Else - Actions
                      • Custom script: call RemoveLocation(udg_Temp_Point_2)
                      • Custom script: call DestroyGroup(udg_Temp_Group)
                    • Else - Actions
        • Else - Actions
      • -------- Top Right --------
      • Set VariableSet Temp_Real = -1.00
      • Set VariableSet Temp_Integer = 0
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Temp_Boolean Equal to Falsch
        • Then - Actions
          • For each (Integer A) from 1 to 2, do (Actions)
            • Loop - Actions
              • For each (Integer B) from 1 to 2, do (Actions)
                • Loop - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • Temp_Real Equal to -1.00
                    • Then - Actions
                      • -------- Find every Unit in specific Corner --------
                      • Set VariableSet Temp_X = ((Real(((Integer A) - 1))) x -128.00)
                      • Set VariableSet Temp_Y = ((Real(((Integer B) - 1))) x -128.00)
                      • Set VariableSet Temp_Point_2 = (Temp_Point offset by (Temp_X, Temp_Y))
                      • Set VariableSet Temp_Group = (Units within 8.00 of Temp_Point_2 matching ((((Matching unit) is alive) Equal to Wahr) and (((Unit-type of (Matching unit)) Equal to (Unit-type of (Triggering unit))) and ((Load 12 of (Key (Matching unit).) from Hashtable.) Equal to upgraded))).)
                      • Set VariableSet Temp_Integer = (Temp_Integer + (Number of units in Temp_Group))
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Number of units in Temp_Group) Equal to 0
                        • Then - Actions
                          • -------- Cancel if no Unit was found early on --------
                          • Set VariableSet Temp_Real = 0.00
                        • Else - Actions
                      • Set VariableSet Temp_Dummy[(((Integer A) x 2) - (Integer B))] = (Random unit from Temp_Group)
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • Temp_X Equal to -128.00
                          • Temp_Y Equal to 0.00
                        • Then - Actions
                          • -------- Set Top Left Unit as Standard Unit --------
                          • Set VariableSet Temp_Unit = (Random unit from Temp_Group)
                        • Else - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • Temp_Integer Equal to 4
                        • Then - Actions
                          • -------- All Units found, proceeding to Create Structure --------
                          • Set VariableSet Temp_X = 64.00
                          • Set VariableSet Temp_Y = -64.00
                          • Set VariableSet Temp_Boolean = Wahr
                        • Else - Actions
                      • Custom script: call RemoveLocation(udg_Temp_Point_2)
                      • Custom script: call DestroyGroup(udg_Temp_Group)
                    • Else - Actions
        • Else - Actions
      • -------- Bot Left --------
      • Set VariableSet Temp_Real = -1.00
      • Set VariableSet Temp_Integer = 0
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Temp_Boolean Equal to Falsch
        • Then - Actions
          • For each (Integer A) from 1 to 2, do (Actions)
            • Loop - Actions
              • For each (Integer B) from 1 to 2, do (Actions)
                • Loop - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • Temp_Real Equal to -1.00
                    • Then - Actions
                      • -------- Find every Unit in specific Corner --------
                      • Set VariableSet Temp_X = ((Real(((Integer A) - 1))) x 128.00)
                      • Set VariableSet Temp_Y = ((Real(((Integer B) - 1))) x 128.00)
                      • Set VariableSet Temp_Point_2 = (Temp_Point offset by (Temp_X, Temp_Y))
                      • Set VariableSet Temp_Group = (Units within 8.00 of Temp_Point_2 matching ((((Matching unit) is alive) Equal to Wahr) and (((Unit-type of (Matching unit)) Equal to (Unit-type of (Triggering unit))) and ((Load 12 of (Key (Matching unit).) from Hashtable.) Equal to upgraded))).)
                      • Set VariableSet Temp_Integer = (Temp_Integer + (Number of units in Temp_Group))
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Number of units in Temp_Group) Equal to 0
                        • Then - Actions
                          • -------- Cancel if no Unit was found early on --------
                          • Set VariableSet Temp_Real = 0.00
                        • Else - Actions
                      • Set VariableSet Temp_Dummy[(((Integer A) x 2) - (Integer B))] = (Random unit from Temp_Group)
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • Temp_X Equal to 0.00
                          • Temp_Y Equal to 128.00
                        • Then - Actions
                          • -------- Set Top Left Unit as Standard Unit --------
                          • Set VariableSet Temp_Unit = (Random unit from Temp_Group)
                        • Else - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • Temp_Integer Equal to 4
                        • Then - Actions
                          • -------- All Units found, proceeding to Create Structure --------
                          • Set VariableSet Temp_X = 64.00
                          • Set VariableSet Temp_Y = -64.00
                          • Set VariableSet Temp_Boolean = Wahr
                        • Else - Actions
                      • Custom script: call RemoveLocation(udg_Temp_Point_2)
                      • Custom script: call DestroyGroup(udg_Temp_Group)
                    • Else - Actions
        • Else - Actions
      • -------- Bot Right --------
      • Set VariableSet Temp_Real = -1.00
      • Set VariableSet Temp_Integer = 0
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Temp_Boolean Equal to Falsch
        • Then - Actions
          • For each (Integer A) from 1 to 2, do (Actions)
            • Loop - Actions
              • For each (Integer B) from 1 to 2, do (Actions)
                • Loop - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • Temp_Real Equal to -1.00
                    • Then - Actions
                      • -------- Find every Unit in specific Corner --------
                      • Set VariableSet Temp_X = ((Real(((Integer A) - 1))) x -128.00)
                      • Set VariableSet Temp_Y = ((Real(((Integer B) - 1))) x 128.00)
                      • Set VariableSet Temp_Point_2 = (Temp_Point offset by (Temp_X, Temp_Y))
                      • Set VariableSet Temp_Group = (Units within 8.00 of Temp_Point_2 matching ((((Matching unit) is alive) Equal to Wahr) and (((Unit-type of (Matching unit)) Equal to (Unit-type of (Triggering unit))) and ((Load 12 of (Key (Matching unit).) from Hashtable.) Equal to upgraded))).)
                      • Set VariableSet Temp_Integer = (Temp_Integer + (Number of units in Temp_Group))
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Number of units in Temp_Group) Equal to 0
                        • Then - Actions
                          • -------- Cancel if no Unit was found early on --------
                          • Set VariableSet Temp_Real = 0.00
                        • Else - Actions
                      • Set VariableSet Temp_Dummy[(((Integer A) x 2) - (Integer B))] = (Random unit from Temp_Group)
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • Temp_X Equal to -128.00
                          • Temp_Y Equal to 128.00
                        • Then - Actions
                          • -------- Set Top Left Unit as Standard Unit --------
                          • Set VariableSet Temp_Unit = (Random unit from Temp_Group)
                        • Else - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • Temp_Integer Equal to 4
                        • Then - Actions
                          • -------- All Units found, proceeding to Create Structure --------
                          • Set VariableSet Temp_X = 64.00
                          • Set VariableSet Temp_Y = -64.00
                          • Set VariableSet Temp_Boolean = Wahr
                        • Else - Actions
                      • Custom script: call RemoveLocation(udg_Temp_Point_2)
                      • Custom script: call DestroyGroup(udg_Temp_Group)
                    • Else - Actions
        • Else - Actions
      • -------- - --------
      • -------- Create Structure --------
      • -------- - --------
      • Custom script: call RemoveLocation(udg_Temp_Point)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Temp_Boolean Equal to Wahr
        • Then - Actions
          • -------- Set Value if Unit is selected --------
          • For each (Integer A) from 0 to 3, do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Temp_Dummy[(Integer A)] is selected by (Owner of (Triggering unit)).) Equal to Wahr
                • Then - Actions
                  • Set VariableSet Temp_Real = -2.00
                  • Custom script: exitwhen true
                • Else - Actions
          • Set VariableSet Temp_Point = (Position of Temp_Unit)
          • Unit - Hide Temp_Unit
          • -------- Remove all 4x4 Units (except 1) --------
          • For each (Integer A) from 0 to 3, do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Temp_Unit Not equal to Temp_Dummy[(Integer A)]
                • Then - Actions
                  • Unit - Remove Temp_Dummy[(Integer A)] from the game
                • Else - Actions
          • Set VariableSet Temp_Point_2 = (Temp_Point offset by (Temp_X, Temp_Y))
          • Unit - Create 1 Temp_Type for (Owner of (Triggering unit)) at Temp_Point_2 facing Default building facing degrees
          • Unit - Set Name of (Last created unit) to ([Mega] + (Name of (Triggering unit)))
          • Unit - Set Unit Skin of (Last created unit) to (Skin ID of (Triggering unit))
          • Unit - Set Base Damage of (Last created unit) to (((Base Damage of (Triggering unit) for weapon index 0) x 4) + 3) for weapon index: 0
          • Animation - Change (Last created unit)'s size to (120.00%, 120.00%, 120.00%) of its original size
          • Set VariableSet Temp_Unit = (Last created unit)
          • Custom script: call UnitRemoveAbility(udg_Temp_Unit,'ARal')
          • Set VariableSet Temp_Unit = No unit
          • -------- Get Value if Unit was selected --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Temp_Real Equal to -2.00
            • Then - Actions
              • Selection - Add (Last created unit) to selection for (Owner of (Triggering unit))
            • Else - Actions
          • Unit - Remove Temp_Unit from the game
          • Custom script: call RemoveLocation(udg_Temp_Point)
          • Custom script: call RemoveLocation(udg_Temp_Point_2)
        • Else - Actions

  • Tower l ID Complete
    • Events
      • Unit - A unit Begins an upgrade
    • Conditions
    • Actions
      • Hashtable - Save upgrading as 12 of (Key (Triggering unit).) in Hashtable.

  • Tower l ID Cancel
    • Events
      • Unit - A unit Cancels an upgrade
    • Conditions
    • Actions
      • Hashtable - Save upgraded as 12 of (Key (Triggering unit).) in Hashtable.

I may just add an Decombine Ability to prevent this behaviour, to revert the Mega Tower to Normal ones.
(The Trigger is kinda whacky not really polished, just an prototype)

Any help is highly appreciated!!
 

Attachments

  • Combining Towers.w3m
    28.1 KB · Views: 6

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,534
Here's a potential design you could use.

Track the neighbors of each tower you build. So when you finish constructing a Farm you would check for adjacent and suitable towers in all 8 directions around it (north, south, east, west, ne, se, nw, sw). Then save those neighboring units to a Hashtable using the Farm as the parent key and each direction as the child key. Something like this:
  • Events
  • Map Initialization
  • Actions
  • Set Variable NORTH = 0
  • Set Variable SOUTH = 1
  • Set Variable EAST = 2
  • Set Variable WEST = 3
  • etc...
Saving a neighbor to a tower:
  • Hashtable - Save (NeighborTower) as NORTH of (CurrentTower) in YourHashtable
Then if a tower is removed from the game you can loop over it's neighbors and remove itself from their Hashtable data.

This should give you greater control and allow you to determine what's a corner.

Well, something like that could work, although I'd definitely not want to do it in GUI. Maybe someone else can help you to get your current triggers to work properly.
 
Last edited:
Level 6
Joined
Mar 27, 2019
Messages
51
Here's a potential design you could use.

Track the neighbors of each tower you build. So when you finish constructing a Farm you would check for adjacent and suitable towers in all 8 directions around it (north, south, east, west, ne, se, nw, sw). Then save those neighboring units to a Hashtable using the Farm as the parent key and each direction as the child key. Something like this:
  • Events
  • Map Initialization
  • Actions
  • Set Variable NORTH = 0
  • Set Variable SOUTH = 1
  • Set Variable EAST = 2
  • Set Variable WEST = 3
  • etc...
Saving a neighbor to a tower:
  • Hashtable - Save (NeighborTower) as NORTH of (CurrentTower) in YourHashtable
Then if a tower is removed from the game you can loop over it's neighbors and remove itself from their Hashtable data.

Well, something like that could work, although I'd definitely not want to do it in GUI. Maybe someone else can help you to get your current triggers to work properly.
The issue is that if you upgrade them at the same time the trigger runs at the same time. You could maybe try to check if there are other units next to the triggering unit and find the top left corner and start merging the units from there?
Thanks both of you, I may have a simple solution to it.

Maybe I can detect the Upper Left Tower through some sort of finish constructing and iteration and if the Top Left Structure is NORTH EAST reduce its upgrading time by 1% thus making it the last one to complete and finish it properly. Atleast in my mind this could work.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,534
Thanks both of you, I may have a simple solution to it.

Maybe I can detect the Upper Left Tower through some sort of finish constructing and iteration and if the Top Left Structure is NORTH EAST reduce its upgrading time by 1% thus making it the last one to complete and finish it properly. Atleast in my mind this could work.
You could probably use the Pause action to freeze the construction of the non-Upper Left towers. Then add a Condition to check if the towers are Paused to prevent them from firing the Actions again. Then Unpause them once the process is finished.
 
Status
Not open for further replies.
Top