HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Bunkers Revisited

04-04-2006, 09:58 PM#1
mmx2000
Trying to get bunkers to work in my map, but cannot for the love of god get it to function like the bunkers in starcraft.

Some notes:
1.) Each player in the game only has 1 bunker (and can only have 1).
2.) For simplicity's sake, I'm going to cut my code down to deal with only 1 type of unit, but bear in mind more than 1 unit-type can load into the bunker.
3.) I'm currently only working on Loading Units into a bunker and unloading a unit by clicking on its icon (not unloadall).
4.) I'm using the method of creating an invis/untargetable/zero-path unit on top of the bunker to track the different firing methods/etc.

How I handle loading:
Trigger:
Collapse Load
Collapse Events
Unit - A unit Is loaded into a transport
Collapse Conditions
(Unit-type of (Transporting unit)) Equal to Bunker
Collapse Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Unit-type of (Triggering unit)) Equal to Firebat
Collapse Then - Actions
Unit - Create 1 Firebat Bunkered for (Owner of (Triggering unit)) at (Position of (Transporting unit)) facing Default building facing (270.0) degrees
Unit - Set the custom value of (Last created unit) to (Integer(firebat))
Else - Actions
Unit Group - Add (Last created unit) to BunkeredUnitGroup[(Player number of (Owner of (Triggering unit)))]

And this is how I'm trying to unload them:
Note: I convert this trigger to JASS and then remove the comment tags to make the loop work.
Trigger:
Unit Leaves GUI
Collapse Events
Unit - A unit Is issued an order targeting an object
Collapse Conditions
(Issued order) Equal to (Order(unload))
Collapse Actions
Set TempUnitGroup = BunkeredUnitGroup[(Player number of (Owner of (Triggering unit)))]
Unit Group - Remove all units of BunkeredUnitGroup[(Player number of (Owner of (Triggering unit)))] from BunkeredUnitGroup[(Player number of (Owner of (Triggering unit)))]
-------- loop --------
-------- (exitwhen ((Custom value of (Targeted unit)) Equal to (Custom value of (First unit of group TempUnitGroup)))) --------
Unit Group - Add (First unit of group TempUnitGroup) to BunkeredUnitGroup[(Player number of (Owner of (Triggering unit)))]
Unit Group - Remove (First unit of group TempUnitGroup) from TempUnitGroup
-------- endloop --------
Unit - Remove (First unit of group TempUnitGroup) from the game
Unit Group - Add all units of TempUnitGroup to BunkeredUnitGroup[(Player number of (Owner of (Triggering unit)))]
Unit Group - Destroy unit group TempUnitGroup
04-04-2006, 10:32 PM#2
PipeDream
What is the problem?
04-04-2006, 10:36 PM#3
mmx2000
Lol sorry.
Problem is, the invis/locust/no-pathing units created aren't being removed from the game when the unit exits the bunker.
04-05-2006, 12:57 AM#4
Earth-Fury
Wouldnt modifying orc burrows get the desired effect?

And there are problems with removing locust units, arnt there? Or is that only for adding them to groups based on what rect they are in?
04-05-2006, 02:08 AM#5
mmx2000
Since they're getting created okay, I don't think the problem is with the transporting mechanism. Is it something with Locust, you think?
04-05-2006, 02:54 AM#6
MysticGeneral
Quote:
Wouldnt modifying orc burrows get the desired effect?

I dun believe so. I think it's the Orc Burrows who get their attack enabled and not the peons. And since this is so, he can only get 1 attack-type effect. I think that's why he's triggering in invisible units to make it appear as if there are multiple types of units inside the bunker attacking.
04-05-2006, 04:12 AM#7
FatalError
I think it has something to do with the Locust ability, though I'm not sure...

Oh, and by the way, you can still use loops in the GUI. Just use the custom script option.

Trigger:
Unit Leaves GUI
Collapse Events
Unit - A unit Is issued an order targeting an object
Collapse Conditions
(Issued order) Equal to (Order(unload))
Collapse Actions
Set TempUnitGroup = BunkeredUnitGroup[(Player number of (Owner of (Triggering unit)))]
Unit Group - Remove all units of BunkeredUnitGroup[(Player number of (Owner of (Triggering unit)))] from BunkeredUnitGroup[(Player number of (Owner of (Triggering unit)))]
Custom script: loop
Custom script: exitwhen ((Custom value of (Targeted unit)) Equal to (Custom value of (First unit of group TempUnitGroup)))
Unit Group - Add (First unit of group TempUnitGroup) to BunkeredUnitGroup[(Player number of (Owner of (Triggering unit)))]
Unit Group - Remove (First unit of group TempUnitGroup) from TempUnitGroup
Custom script: endloop
Unit - Remove (First unit of group TempUnitGroup) from the game
Unit Group - Add all units of TempUnitGroup to BunkeredUnitGroup[(Player number of (Owner of (Triggering unit)))]
Unit Group - Destroy unit group TempUnitGroup

I'm not 100% sure if that would work, but it should...
04-05-2006, 08:56 AM#8
Fulla
You cant pick a unit with locust
i.e. pick all units matching...

You can do last created unit etc.
04-05-2006, 01:07 PM#9
mmx2000
Hmmm. If I can't "Pick" the unit with locust, I guess that means I have to use an array of units rather than unit-groups? I just assumed the built-in unit-group function would be easier since its sort of a dynamically expanding/contracting array, but if I can't Pick locusted units that's kind of a stupid design flaw.
04-06-2006, 03:16 AM#10
mmx2000
Alright... I am seriously beyond frustrated with trying to get bunkers to work. I rewrote the code using arrays (its not pretty, but the loops and array management -seem- to work), and the invis units still dont get removed when a unit exits the bunker.
So I tried removing the Locust ability from them, and making the attempt to select them impossible via triggers.
Still not getting removed when the unit leaves the bunker.

Note: My array system is bizarre. It might be the problem and my error detection method might be deceiving me.
Basically, I'm trying to create a matrix of size 5x4; x coordinates = each players bunker, y coordinates = number of units currently inside the bunker.
Say you want to get the 2nd unit in Player 1's bunker. You would call BunkeredUnits[12]. I do this by a painful way of converting strings to integers.
Essentially to restate the code:
The 'X' coordinate = String(Player Number of Triggering Player))
The 'Y' coordinate = String(NumberOfUnitsInBunker(Player Number of Triggering Player)
Put together, the matrix location = Integer(X+Y) (con-cantenated)

I know there's better ways, but for the moment, it's working, and if it aint broke, I aint fixin it.


Here's all the relevant triggers:

Trigger to assign all normal, bunker-loadable units (marines, firebats, ghosts, medics) in the game specific custom values (These are used when to identify if an invis unit-type matches the appropriate unloading unit-type):
Trigger:
Unit Custom Values
Collapse Events
Unit - A unit enters (Entire map)
Player - Player 1 (Red) Selects a unit
Player - Player 2 (Blue) Selects a unit
Player - Player 3 (Teal) Selects a unit
Player - Player 4 (Purple) Selects a unit
Player - Player 5 (Yellow) Selects a unit
Conditions
Collapse Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
Collapse Or - Any (Conditions) are true
Collapse Conditions
(Unit-type of (Triggering unit)) Equal to Firebat Bunkered
(Unit-type of (Triggering unit)) Equal to Ghost Bunkered
(Unit-type of (Triggering unit)) Equal to Marine Bunkered
(Unit-type of (Triggering unit)) Equal to Medic Bunkered
Collapse Then - Actions
Selection - Remove (Triggering unit) from selection for (Triggering player)
Else - Actions
If ((Unit-type of (Triggering unit)) Equal to Firebat) then do (Unit - Set the custom value of (Triggering unit) to 1) else do (Do nothing)
If ((Unit-type of (Triggering unit)) Equal to Marine) then do (Unit - Set the custom value of (Triggering unit) to 2) else do (Do nothing)
If ((Unit-type of (Triggering unit)) Equal to Ghost) then do (Unit - Set the custom value of (Triggering unit) to 3) else do (Do nothing)
If ((Unit-type of (Triggering unit)) Equal to Medic) then do (Unit - Set the custom value of (Triggering unit) to 4) else do (Do nothing)
Game - Display to (All players) the text: ((Name of (Triggering unit)) + ('s custom value: + (String((Custom value of (Triggering unit))))))
Note: the last line is just a testing trigger I put in to check the custom values are working properly.


Next here's my trigger for when a unit is loaded into a bunker:
Trigger:
Load
Collapse Events
Unit - A unit Is loaded into a transport
Collapse Conditions
(Unit-type of (Transporting unit)) Equal to Bunker
Collapse Actions
-------- Custom Unit Value Table: --------
-------- Firebat = 1, Marine = 2, Ghost = 3, Medic = 4 --------
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Unit-type of (Triggering unit)) Equal to Firebat
Collapse Then - Actions
Unit - Create 1 Firebat Bunkered for (Owner of (Triggering unit)) at (Position of (Transporting unit)) facing Default building facing (270.0) degrees
Unit - Set the custom value of (Last created unit) to 1
Else - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Unit-type of (Triggering unit)) Equal to Marine
Collapse Then - Actions
Unit - Create 1 Marine Bunkered for (Owner of (Triggering unit)) at (Position of (Transporting unit)) facing Default building facing (270.0) degrees
Unit - Set the custom value of (Last created unit) to 2
Else - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Unit-type of (Triggering unit)) Equal to Ghost
Collapse Then - Actions
Unit - Create 1 Ghost Bunkered for (Owner of (Triggering unit)) at (Position of (Transporting unit)) facing Default building facing (270.0) degrees
Unit - Set the custom value of (Last created unit) to 3
Collapse Else - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Unit-type of (Triggering unit)) Equal to Medic
Collapse Then - Actions
Unit - Create 1 Medic Bunkered for (Owner of (Triggering unit)) at (Position of (Transporting unit)) facing Default building facing (270.0) degrees
Unit - Set the custom value of (Last created unit) to 4
Else - Actions
Set NumberOfUnitsInBunker[(Player number of (Owner of (Triggering unit)))] = (NumberOfUnitsInBunker[(Player number of (Owner of (Triggering unit)))] + 1)
Set BunkeredUnits[(Integer(((String((Player number of (Owner of (Triggering unit))))) + (String(NumberOfUnitsInBunker[(Player number of (Owner of (Triggering unit)))])))))] = (Last created unit)
Game - Display to (All players) the text: (NumberOfUnitsInBunker[ + (((String((Player number of (Owner of (Triggering unit))))) + ] ) + (is + (String(NumberOfUnitsInBunker[(Integer((String((Player number of (Owner of (Triggering unit)))))))])))))
Game - Display to (All players) the text: (((BunkeredUnits[ + (((String((Player number of (Owner of (Triggering unit))))) + (String(NumberOfUnitsInBunker[(Player number of (Owner of (Triggering unit)))]))) + ] )) + (= + ((Name of BunkeredUnits[(Integer(((String((Player number of (Owner of (Triggerin
Note: The last lines are just testing actions.


Last trigger - when a unit is unloaded by clicking on his portrait:
Trigger:
Unit Leaves
Collapse Events
Unit - A unit Is issued an order targeting an object
Collapse Conditions
(Issued order) Equal to (Order(unload))
Collapse Actions
Collapse For each (Integer A) from 1 to NumberOfUnitsInBunker[(Player number of (Owner of (Triggering unit)))], do (Actions)
Collapse Loop - Actions
Set TempUnitArray[(Integer A)] = BunkeredUnits[(Integer(((String((Player number of (Owner of (Triggering unit))))) + (String((Integer A))))))]
Collapse For each (Integer A) from 1 to NumberOfUnitsInBunker[(Player number of (Owner of (Triggering unit)))], do (Actions)
Collapse Loop - Actions
Set BunkeredUnits[(Integer(((String((Player number of (Owner of (Triggering unit))))) + (String((Integer A))))))] = No unit
Set counter = NumberOfUnitsInBunker[(Player number of (Owner of (Triggering unit)))]
Custom script: loop
Custom script: (exitwhen ((Custom value of (Target unit of issued order)) Equal to (Custom value of TempUnitArray[counter])))
Set counter = (counter - 1)
Custom script: endloop
Unit - Remove BunkeredUnits[(Integer(((String((Player number of (Owner of (Triggering unit))))) + (String(counter)))))] from the game
Set NumberOfUnitsInBunker[(Player number of (Owner of (Triggering unit)))] = (NumberOfUnitsInBunker[(Player number of (Owner of (Triggering unit)))] - 1)
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
NumberOfUnitsInBunker[(Player number of (Owner of (Triggering unit)))] Not equal to 0
Collapse Then - Actions
Collapse For each (Integer A) from 1 to NumberOfUnitsInBunker[(Player number of (Owner of (Triggering unit)))], do (Actions)
Collapse Loop - Actions
Set BunkeredUnits[(Integer(((String((Player number of (Owner of (Triggering unit))))) + (String((Integer A))))))] = TempUnitArray[(Integer A)]
Else - Actions


From testing with the text messages I made, it appears that my array handling via counters/loops/etc are working properly.
Ie:
1 unit is loaded to the bunker, printsout:
NumberOfBunkeredUnits[1] = 1
BunkeredUnit[11] = Marine with Custom Value: 2

2 units loaded to the bunker:
NumberOfBunkeredUnits[1] = 2
BunkeredUnit[12] = Marine with Custom Value: 2

1 marine is unloaded by clicking on portrait:
NumberOfBunkeredUnits[1] = 1
BunkeredUnit[11] = Marine with Custom Value: 2


In conclusion:
I have no f@$%$%cking idea why the invis Marine-Bunkered unit isn't getting deleted.

If anyone can figure out the error, I will worship you forever.
Just to clarify something, to: the Bunkered Units have Permanent Invisibility, but not Locust.
04-06-2006, 06:39 AM#11
Anitarf
Wait wait wait...
"Custom script: (exitwhen ((Custom value of (Target unit of issued order)) Equal to (Custom value of TempUnitArray[counter]))) "
This is not proper JASS syntax, and shouldn't work at all.
04-06-2006, 01:15 PM#12
Thunder_Eye
Also he doesnt need to use JASS to make a loop.
Just use the "ForEachLoop" function.
04-06-2006, 03:51 PM#13
mmx2000
And just so you don't think I'm a total retard I am planning on re-writing the array method to use something like Array[x*sizeofy+y-1] rather than the ridiculous string method.

Anyways... whats wrong with the JASS syntax of the exitwhen condition? Im a total JASS noob :/
04-06-2006, 08:05 PM#14
PipeDream
Collapse JASS:
(exitwhen ((Custom value of (Target unit of issued order)) Equal to (Custom value of TempUnitArray[counter])))
is not valid jass syntax. It is just a GUIism.
I believe custom value is Set/GetUnitUserData. So:
Collapse JASS:
exitwhen GetUnitUserData(GetOrderTargetUnit()) == GetUnitUserData(udg_TempUnitArray[udg_counter])
04-06-2006, 10:01 PM#15
mmx2000
Quote:
Originally Posted by PipeDream
Collapse JASS:
(exitwhen ((Custom value of (Target unit of issued order)) Equal to (Custom value of TempUnitArray[counter])))
is not valid jass syntax. It is just a GUIism.
I believe custom value is Set/GetUnitUserData. So:
Collapse JASS:
exitwhen GetUnitUserData(GetOrderTargetUnit()) == GetUnitUserData(udg_TempUnitArray[udg_counter])
Ahh... so obvious.
Although I didn't know the correct function, either.
Thanks a million... rep+ :D