• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

How does Legion remember building placement?

Status
Not open for further replies.
Level 8
Joined
Jan 17, 2019
Messages
163
So in Legion you place buildings that are turned into their corresponding units at the start of a round. They fight a wave and regardless if they die or not the buildings are right back where you left them in the next round. Anyone know how they did that? I'm scratching my head at how the game remembers the building placement, especially since you can also upgrade or sell the buildings so nothing is permanent.
 
Level 29
Joined
Sep 26, 2009
Messages
2,595
I don't know what Legion is, nor the way they handle selling buildings, but the triggers below may serve as a base for the system:


1619513080442.png



Simply indexes the given construction, its type, owner and location
  • Construction Finished
    • Events
      • Unit - A unit Finishes construction
    • Conditions
    • Actions
      • Set VariableSet BuildingIndex = (BuildingIndex + 1)
      • Set VariableSet BuildingCurrentStructure[BuildingIndex] = (Triggering unit)
      • Set VariableSet BuildingLoc[BuildingIndex] = (Position of (Triggering unit))
      • Set VariableSet BuildingType[BuildingIndex] = (Unit-type of (Triggering unit))
      • Set VariableSet BuildingOwner[BuildingIndex] = (Owner of (Triggering unit))


Loops over all indexed constructions to find which construction was updated, then changes the Unit-type that is stored in the array
  • Construction Upgraded
    • Events
      • Unit - A unit Finishes an upgrade
    • Conditions
    • Actions
      • For each (Integer loopInt) from 1 to BuildingIndex, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Triggering unit) Equal to BuildingCurrentStructure[loopInt]
            • Then - Actions
              • Set VariableSet BuildingType[loopInt] = (Unit-type of (Triggering unit))
              • -------- exit loop --------
              • Set VariableSet loopInt = BuildingIndex
            • Else - Actions


Checks if the building still exists - if not, recreates it.
There is no event here since I have no idea when round ends and new round starts
  • ReCreate Construction
    • Events
    • Conditions
    • Actions
      • For each (Integer loopInt) from 1 to BuildingIndex, 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
                  • BuildingCurrentStructure[loopInt] Equal to No unit
                  • (BuildingCurrentStructure[loopInt] is dead) Equal to True
            • Then - Actions
              • Unit - Create 1 BuildingType[loopInt] for BuildingOwner[loopInt] at BuildingLoc[loopInt] facing Default building facing degrees
              • Set VariableSet BuildingCurrentStructure[loopInt] = (Last created unit)
            • Else - Actions


Since I have no idea how buildings are sold in Legion, the trigger is missing events and conditions
  • Remove Construction
    • Events
    • Conditions
    • Actions
      • Set VariableSet SoldBuilding = (Triggering unit) //this should use something else, but it depends on how the building is sold
      • For each (Integer loopInt) from 1 to BuildingIndex, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • BuildingCurrentStructure[loopInt] Equal to SoldBuilding
            • Then - Actions
              • Custom script: call RemoveLocation(udg_BuildingLoc[udg_loopInt])
              • -------- deindex --------
              • Set VariableSet BuildingCurrentStructure[loopInt] = BuildingCurrentStructure[BuildingIndex]
              • Set VariableSet BuildingLoc[loopInt] = BuildingLoc[BuildingIndex]
              • Set VariableSet BuildingType[loopInt] = BuildingType[BuildingIndex]
              • Set VariableSet BuildingOwner[loopInt] = BuildingOwner[BuildingIndex]
              • Set VariableSet BuildingIndex = (BuildingIndex - 1)
              • -------- exit loop --------
              • Set VariableSet loopInt = BuildingIndex
            • Else - Actions
 
Level 8
Joined
Jan 17, 2019
Messages
163
Hmm I was hoping for something simpler, I def don't know how loopInt works. Maybe I can make the buildings invisible/untargetable during the round and just spawn the units on top of them?

Might try this: Remove Locust ability and make unit vulnerable

Also I'm pretty surprised you've never heard of Legion. Isn't it the most played custom map for years now? There are multiple lobbies up at 5am.
 
Level 29
Joined
Sep 26, 2009
Messages
2,595
Well, I like to fiddle with the editor, but don't really play the maps, so no idea what Legion is :D

Loops are a basic for most MUI spells, so if you plan on triggering some custom spells, it may be worth learning how loops work.
Actually, what I showed in the 'construction finished' and 'selling building' triggers is indexing and deindex that MUI spells use.

How loops work is very simple - the signature is: 'For each (Integet CURRENT) from START to END do (actions)'.
All loop does is the following:
  1. Assign value of START to CURRENT
  2. If value in CURRENT is greater than value in END, then end the loop, else continue with next step
  3. Execute loop actions
  4. Increase value of CURRENT by 1
  5. Go back to step 2

As for your solution via invisibility/locus, I am not sure how well this will work - for example when your building is destroyed, immediately hiding the unit may prevent players from seeing the building being destroyed. Creating new building on top of it may move the new building to some pathable terrain. Well, try and see how it works for you :)
 
I don't know what Legion is, nor the way they handle selling buildings, but the triggers below may serve as a base for the system:
He is referring to Legion TD or Legion Tower Defence, there's tons of videos on youtube and a few by Wtii in particular you could probably watch a couple of minutes of to see what he means.
 
Level 29
Joined
Sep 26, 2009
Messages
2,595
hmm, looking at the map, I don't think the buildings are actually fighting. Seems more like you build a tower (that looks like unit), but at round start those structures are hidden and at their place normal units are created.
That also resolves the issue with the structures being recreated at round end, because the structures themselves are never really destroyed, but rather hidden and later unhidden.

I think that is the case because there are still some fields in the object editor that cannot be set via triggers - for example the pathing map field. If those units were structures with pathing maps during the round when enemies attack, then the "towers" could not clutter as close to one another as standard units do.

So basically how I think it works is:
  • A unit-type is created and set up in object editor - this unit-type should represent the "tower" during enemy attack
  • A new unit-type is created, which is a copy of the previous one. This new unit-type is set up as a structure with all the additional things like the ability to sell this structure or upgrade it further, the pathing map. This is the "tower" that you build before each wave.
  • In triggers you create a hashmap where each structure-version of the tower is mapped to the unit-version of the tower
  • During game you place the structure version of the tower
  • When round starts, you go over each structure-version of the tower, hide it, then find its unit-version in the hashmap and create it at the location of the original structure.
  • When round ends, go over each structure-version of the tower and unhide it.
 
Level 8
Joined
Jan 17, 2019
Messages
163
YESSSS!!! The solution was so easy! I simply hide the buildings which removes pathing, spawn the corresponding units at their position, clear the units at the end of a wave and when I unhide the buildings their pathing returns so nobody can build in the same spot twice. It's working perfect! Thanks brahs
 
Status
Not open for further replies.
Top