• 🏆 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!

[Trigger] Random Distribution of abilites with a steadily smaller array

Status
Not open for further replies.
Level 2
Joined
Nov 12, 2017
Messages
8
Hello Boyz,

I am currently working on a Labyrinth type of map. Inside this Labyrinth there will be 6 shrines where the players can acquire a skill after praying to the gods. Each shrine can only give one ability to the first player who comes to visit it. After that the according shrine triggers will be disabled.

However, while the shrine locations are distinct, the ability a shrine will offer should be randomized each game. (at map initialisation)

And this is where I have issues implementing a working scheme.

My initial idea was to do following:

1. I create An Ability Array "ShrineAbilities" which is 6 slots large (from 0 - 5 )
2. I order each slot to one of my abilites.
3. I create An Integer "RandomNumber" that saves a random number (using the inbuild function for it).
4. I create another Ability Array "ShrineDefiniteAbilites" where the randomed abilites will be put in for later use.


Then I would start a loop:

For each integer X from 0 to 5 do
- set "RandomNumber" = (Random Integer Number between 0 and (5-X)
- set ShrineDefiniteAbilites(X) = (ShrineAbilites(RandomNumber) // I can realise it till this point

Next, since an ability has been assigned I want the variable "ShrineAbilites" become smaller by one.
Lets say the randomed number would be 2, then the second ability will be assigned to my first slot.
Now I want to remove the slot of the second ability from "ShrineAbilites" so I can restart the loop without assigning the same ability twice.

I tried to work with Booleans but I dont find anything really sufficient. And I think there should be a better possibility than writing down every possibility with "if and else" statements.

I use the GUI for 99% of my time.

Any Ideas? Maybe I am overlooking something.

If you want me to clarify things I will try to do that.
 
Level 13
Joined
Jul 15, 2007
Messages
763
There probably is a really simple way to do it, but i personally do this using unit groups because its simple and easy to understand. In this case i would:
  • Create 6 non-combat/locus units and put them into a unit group.
  • Assign each unit a unique integer (via its custom value), up to your maximum ability number (i.e., 1, 2, 3, 4, 5 and 6).
  • When a shrine is activated, pick 1 random unit from this group, and depending on its ID the appropiate ability is added.
  • Remove picked unit from group/game, preventing that ID from being repeated
Obviously not suitable for big ranges of numbers as it depends on making units in-game.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
Place all 6 abilities in an array from index 0 to 5 in a fixed order, where {n = 6}. Then when you need a shrine ability get the ability at index random integer between {0} and {n - 1}. After using the ability for the shrine, set the previously determined random index to the ability at array index {n - 1} and then decrement {n} by 1. This can be repeated 6 times for all 6 abilities given out in a random order.

No unit groups, no linked lists, only 2 global variables needed.
 
Level 22
Joined
Feb 6, 2014
Messages
2,466
Given that the order of abilities doesn't matter, dynamic indexing will work just as well. However, the bigger the list, Linked List will have the advantage of a less costly deallocation.
After not using dynamic indexing for so long, I failed to consider this. I think dynamic indexing is actually better than linked list because the abilities doesn't have that much "properties" to copy during deallocation.

For OP, here's a great tutorial
Visualize: Dynamic Indexing
 
Status
Not open for further replies.
Top