• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Issues with random factors

Status
Not open for further replies.
Level 30
Joined
Jan 31, 2010
Messages
3,551
So I'm projectin' and I've encountered an issue.

Basically, I have 140 types of creeps a player can face in a game. There are 70 groups of creeps, which means that, there's a preset of one ranged and one melee creep per group, and the groups are always the same. Out of them all, a player can possibly encounter only 50 every game, meaning 20 will not be played at the time.

I've tried to trigger this via simple method: setting a variable to a random value between 1 and 70, and then doing the other things. However, this has a great flaw of making it possible to encounter same creep groups more than once per game. I've also tried to add conditions to the trigger whenever a group is selected, looping the trigger until it gets a value which is not played already, but this caused both lag and is not functional.

I'm kinda trapped in place, as I'm trying to get a random number from 1 to 70, which also removes the randomed value whenever it's played per run of the trigger.

Suggestions for random factor with exclusion of randomed numbers? Or a testmap, anything can do.
 
Level 25
Joined
Sep 26, 2009
Messages
2,378
The solution is actually quite similar to how deindexing works.

At map ini: Set MaxWaves = 70

When spawning creeps:
Set waveNumber = random number between 1 and MaxWaves
Spawn group[waveNumber]
Set group[waveNumber] = group[MaxWaves]
Set MaxWaves = MaxWaves - 1

---
In actual game
Let's say waveNumber will be number 59
After you spawn group number 59, you replace this group with the last indexed group - so new group[59] will consist of units from group[70].
The problem now, would be that group[59] and group[70] are the same group. So you decrease the index MaxWaves by 1 - now the maximum number of groups is 69.

Basically you replace the used group by last unused group.
 
Level 30
Joined
Jan 31, 2010
Messages
3,551
Wouldn't it mean that, let's go an example since I can't explain.

Set waveNumber = random number between 1 and MaxWaves
Out of 70 groups, number 32 is selected.
Spawn group[32]
Set group[32] = group[70]
Set MaxWaves = MaxWaves - 1


Wouldn't this mean that now you can get all the creeps from 1 to 69? Or the indexing discards the 32 instead of 70? Kinda confusing.
 
Level 12
Joined
Mar 24, 2011
Messages
1,082
You basicaly swap the last group and the picked group and lower the number of groups.

So if we have A B C D E F... X Y Z [26]
Pick random E
Swap E and LastOfRandomsGroup, which is Letter[MaxIndex]
Lower MaxIndex by 1
Now you have A B C D Z F... X Y [25]

Meaning that now you have no E to pick random, put some actions and a loop and you are done
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
I will not bring anything new to the table, but I just want to point out that you dont swap the groups, because group[32] now stores the same group as group[70], and the original group[32] is discarted(if you dont have it stored somewhere else, destroy it before the assignment, or you will leak)
 
Status
Not open for further replies.
Top