Staredit Network > Forums > SC1 UMS Mapmaking Assistance > Topic: Cycling through buildings
Cycling through buildings
Apr 2 2010, 5:11 pm
By: major  

Apr 2 2010, 5:11 pm major Post #1



Hi,

What I want to do:
If a player brings a unit type A near any Terran Barracks, that unit is changed into unit type B.

I created a location that is slightly bigger than Terran Barracks. Now, how do I cycle through all the barracks every player has?
I could do it with burowed units, but im afraid it's gonna create a lag. Any ideas?
Also, I could give barracks to another player and give them back later. But, an attacking unit stops to atack a building when it's given to another player.



None.

Apr 2 2010, 5:24 pm Apos Post #2

I order you to forgive yourself!

If there is only one unit type A for each player, then all you need to do is center a location for each player over their unit type A. Then detect when a barrack is brought to the location (meaning the unit type A is beside the barrack).




Apr 2 2010, 5:27 pm major Post #3



The problem is there are a lot of units type A, B and barracks.



None.

Apr 2 2010, 5:31 pm CecilSunkure Post #4



You center a location onto one of the bunkers, switch units, give that bunker to another player, and repeat. Once all bunkers are owned by that other player, give them back. You can create//copy a lot of triggers so this happens instantaneously.



None.

Apr 2 2010, 7:19 pm NudeRaider Post #5

We can't explain the universe, just describe it; and we don't know whether our theories are true, we just know they're not wrong. >Harald Lesch

It might create lag if you have a lot of Barracks to cycle through and do it all in 1 trigger loop, if it does just create less copies of the trigger. 10 should never be a problem.




Apr 3 2010, 9:23 am major Post #6



Quote
You center a location onto one of the bunkers, switch units, give that bunker to another player, and repeat. Once all bunkers are owned by that other player, give them back. You can create//copy a lot of triggers so this happens instantaneously.

Maybe I'm doing something wrong, but there still is an 'ownership' gap that prevents from selecting or attacking.
Here's my code:

Code
FOR a = 1 TO 7 BY 1 DO
    FOR i = 1 TO 5 BY 1 DO //5 - How many barracks can a player have
        TRIGGER
        OWNERS: @P(a)
        CONDITIONS:
            Command(@P(a), @AtLeast, 1, @U("Terran Barracks"))
        ACTIONS:
            PreserveTrigger()
            MoveLocation(@L("b1"), @U("Terran Barracks"), @P(a), @Anywhere)
        ENDT
   
        // Here was code for changing units. I removed it.
       
        TRIGGER
        OWNERS: @P(a)
        CONDITIONS:
            Command(@P(a), @AtLeast, 1, @U("Terran Barracks"))
            Bring(@P(a), @AtLeast, 1, @U("Terran Barracks"), @L("b1"))
        ACTIONS:
            PreserveTrigger()
            GiveUnits(1, @U("Terran Barracks"), @P(a), @L("b1"), @P(12))
            MoveLocation(@L("b1"), @U("Terran Barracks"), @P(a), @Anywhere)
        ENDT    
    ENDL    
    TRIGGER
    OWNERS: @P(a)
    CONDITIONS:
        Command(@P(12), @AtLeast, 1, @U("Terran Barracks"))
    ACTIONS:
        PreserveTrigger()
        GiveUnits(@All, @U("Terran Barracks"), @P(12), @Anywhere, @P(a))
    ENDT    
   
ENDL




None.

Apr 3 2010, 12:09 pm NudeRaider Post #7

We can't explain the universe, just describe it; and we don't know whether our theories are true, we just know they're not wrong. >Harald Lesch

You shouldn't give the barracks, but rather units stacked under them.
He recommended bunkers, but that only works for preplaced.
Use P11 Zerglings for dynamically created barracks.




Apr 3 2010, 12:38 pm major Post #8



Since Im not very good at this, I'm confused. It seems I need to cycle through all of them beforehand to cycle through them afterwards - for every dynamically created barracks, I would have to create one zergling for P11. Doesn't that require a cycle already? How do I do that? Is it possible to cycle through dynamic buildings that way?



None.

Apr 3 2010, 1:39 pm NudeRaider Post #9

We can't explain the universe, just describe it; and we don't know whether our theories are true, we just know they're not wrong. >Harald Lesch

Quote from major
Since Im not very good at this, I'm confused. It seems I need to cycle through all of them beforehand to cycle through them afterwards
Yes
Quote from major
- for every dynamically created barracks, I would have to create one zergling for P11. Doesn't that require a cycle already? How do I do that? Is it possible to cycle through dynamic buildings that way?

For now lets assume you already have the stacked units under the barracks.
Then it goes like this:
Center on P11 ling
Give ling to P10
If unit A at ling location convert unit A to B
-> repeat until P11 owns no lings
Give all P10 lings back to P11.
-> restart

Now for how you get those lings under the barracks? Well if they are all preplaced it's easy:
Use buildings instead (e.g. bunkers) or cycle though all the barracks at map start and recenter the lings. This is necessary because even burrowed lings will be pushed out of the buildings. If there's no room you'll get an unplaceable error.

If barracks can get created dynamically, things get ugly: there's several methods but which to choose depends on how the barracks are used/created.
Option A:
Once in a while you cycle through all barracks and check if they have a ling under it. This works very similar to the above method but causes a deselect. But since it's not very often it might be okay.

Option B:
You have triggers for every possible number of barracks in existence and just compare the current nr. of barracks with the nr. of barracks last trigger loop:
init (runs only at map start):
set dc 'rax now' to 0
set dc 'rax last' to 0

Player x brings exactly 1 barracks to anywhere
=> set deaths for 'rax now' to 1
Player x brings exactly 2 barracks to anywhere
=> set deaths for 'rax now' to 2
Player x brings exactly 3 barracks to anywhere
=> set deaths for 'rax now' to 3
... etc. until max nr. of barracks

Do binary countoff to subtract do 'rax now' - 'rax last'

If 'rax now' > 0
cycle through all the barracks until you found one without ling (again, dreaded deselect)
create the ling, recenter the ling.

After all that, set 'rax last'. That way it'll always lag 1 trigger loop behind 'rax now'.
Again, 1 trigger for each possible nr. of rax. Trigger duplicators are your friend. ;)

Option C:
Only possible if there's only 1 scv.
Uhh actually I just realized this might be difficult/very circumstantial/unreliable.
The idea is to detect when the scv is over the unfinished buildings. Because unfinished buildings can be used in actions (e.g. center location) but are not detected through conditions.
But this needs a long build time at least so the scv has time go through the building to another corner to build there.
If the detection fails the player can always land his building on the scv to trigger it. :P




Apr 3 2010, 1:45 pm major Post #10



Thanks a lot!

But since every option gonna deselect my barracks, I might as well just stick to my old method and just give barracks to another player.
Is my conclusion right: burrowed units are better only if buildings are preplaced?



None.

Apr 3 2010, 2:20 pm NudeRaider Post #11

We can't explain the universe, just describe it; and we don't know whether our theories are true, we just know they're not wrong. >Harald Lesch

No. Don't just neglect a method because you read deselect. Think about it:
Burrowed units allow you to only force the deselect when a new barracks has been built.
If the build time is near instant then the player won't have his barracks selected anyway because he just ordered his worker to build!
If it's long then you might want to consider option c although I haven't thought it through entirely.

If barracks are built by triggers, so the player might actually have a barracks selected this still is far better than always deselecting - which you'd have to do without stacked units.

Still it might be helpful to tell when you're doing what with the barracks and how often conversions should happen. We can only give proper advice when we understand your map mechanics. There might be solutions you're not even thinking about.




Options
  Back to forum
Please log in to reply to this topic or to report it.
Members in this topic: None.
[2026-4-18. : 3:57 am]
NudeRaider -- https://staredit.net/381600/ You have 5 minutes, then you can only edit your posts.
[2026-4-17. : 4:05 pm]
NudeRaider -- DarkenedFantasies
DarkenedFantasies shouted: you eat lots of beans
:lol:
[2026-4-17. : 11:30 am]
NudeRaider -- I would like 3000 minerals, please
[2026-4-16. : 7:32 pm]
Zoan -- I got $2000 bonus. I would like 2000 minerals, please
[2026-4-16. : 4:15 am]
DarkenedFantasies -- you eat lots of beans
[2026-4-16. : 3:46 am]
IskatuMesk -- how do i get gas
[2026-4-15. : 11:43 pm]
Moose -- you don't
[2026-4-15. : 10:06 pm]
Zoan -- how do i get minerals
[2026-4-14. : 11:45 pm]
ClansAreForGays -- Anyone wanna played Skewed StarCraft?
[2026-4-14. : 12:07 am]
Vrael -- NudeRaider
NudeRaider shouted: Vrael ranting still is though
you're a gentleman and a scholar, thank you
Please log in to shout.


Members Online: JohnnyTheWolf