HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Running multiple units through a math formula.

11-08-2007, 03:17 AM#1
HexenLordX
Been a LONG time since I've posted here, but I'm getting very confused with a trigger in one of my maps. I can't seem to get it working right and I'm not very skilled in JASS which is my main problem.

Basically I'm trying to select all units in a region and divide them into groups according to who owns them. Then I'm giving each of them a percent chance to create a Token thats the same level as them. Rules are, only 1 token per player can be created at a time, and heroes don't count.

Here is what I have so far:

Trigger:
Actions
Collapse Player Group - Pick every player in (All players matching ((((Matching player) controller) Equal to User) and (((Matching player) slot status) Equal to Is playing))) and do (Actions)
Collapse Loop - Actions
Collapse Unit Group - Pick every unit in (Units in Boss Area <gen>((((Owner of (Matching unit)) controller) Equal to ((Picked player) controller)) and (((Level of (Matching unit)) Greater than or equal to 3) and (((Matching unit) is A Hero) Equal to False)))) and do (Actions)
Collapse Loop - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
PlayerDone[(Player number of (Picked player))] Equal to False
Collapse Then - Actions
Set UnitPercent[(Player number of (Picked player))] = ((100 / ((Level of (Picked unit)) x 2)) x ((BossLevel / 4) + ((DiffiicultyLevel / 3) + 2)))
Set RandomNumber = (Random integer number between 1 and 100)
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
RandomNumber Less than or equal to UnitPercent[(Player number of (Picked player))]
Collapse Then - Actions
Unit - Create 1 Token[(Level of (Picked unit))] for (Picked player) at (Center of StartRegionPlayer[(Player number of (Picked player))]) facing Default building facing (270.0) degrees
Set PlayerDone[(Player number of (Picked player))] = True
Set UnitPercent[(Player number of (Picked player))] = 0
Set RandomNumber = 0
Collapse Else - Actions
Set UnitPercent[(Player number of (Picked player))] = 0
Set RandomNumber = 0
Collapse Else - Actions
Do nothing
Set PlayerDone[(Player number of (Picked player))] = False

Does anyone see anything wrong with this? I'm having a hard time testing it by myself to see if its working correctly. I'm pretty good with GUI but not very much with JASS so I'm wondering if this will cause any problems.
11-08-2007, 03:34 AM#2
PipeDream
There's really no way to answer a question that contains a code fragment with 10 levels of indentation in a non snarky fashion.

My interpretation of what you want to do:
For each player, take all his units, assign a relative probability to that unit, then pick a single unit and give him a token. Outline:
Code:
For each player
    For each unit of the player, assign units to array slots
    For each array slot, assign weight of corresponding unit to another array slot and keep a running sum of the weights
    Compute a random number in [0,weightsum)
//    Find spot in array such that unit[i] < random < unit[i+1]
    For i in 1 .. nunits
        set random = random - weight[i]
        give the token to the first unit that satisfies random <= 0
11-08-2007, 03:59 AM#3
HexenLordX
Basically, yes. I just want each unit to give a probability to create a Token unit of the same level. It doesn't have to be guaranteed that the player gets one.

The main thing I left out. I'm not exactly sure how the Unit groups work, but is there anyway for the actions in the unit group loop to start at the lowest level units first and work their way up? I wouldn't know where to begin.
11-08-2007, 07:28 PM#4
Salbrismind
You said you wanted them to be divided into groups based on who owns them? So what?: player 1 units > group 1 Etc.?

is so then just make it Add all the units in the area to a group like regiongroup or something then go from there. In Jass its called Firstingroup or something, try to take one unit at a time out of the group and place it into the player groups. Then just run a for loop for all the units and randomize if they get the token or not.