| 11-08-2007, 03:34 AM | #2 |
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 |
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 |
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. |
