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

Help with Unit Pool idea

Status
Not open for further replies.
Level 13
Joined
Oct 16, 2010
Messages
731
Hi,

I would like to try and add a unit pool system to my map. In my map you get 4 units to pick from in your shop per roll. At the moment the randomisation is done by a simple "if int = 1 , pick unit 1" etc etc

Teamfight Tactics and Auto Chess/Auto Battle all use a unit pool system that means players can't all use the same types of units, I would like to do something similar (or the same) to make my map a little less RNG.

At the moment I have created arrays for each rarity type and filled them with each unit type I want, my idea is that I can run each of these at the start of the map to define how many of each rarity will be available in the map. This bit I think will work fine.

One of the issues I've thought of is that you can't have 2 of the same unit in the shop at one time, I've got past this issue in my current setup by saving the units rolled and checking whether the type of the chosen unit matches any of the currently rolled units. If it matches then fire the trigger again, eventually this will pick a unit that hasn't already been picked.

If I use a unit pool however this could potentially lead to a crash? If the only units left in the pool are matching types I cannot keep rolling the trigger as this would cause an infinite loop?

I might be overthinking this and need to just go for it but at the moment I'm really not sure the best way of making a unit pool work easily and effectively!

Has anyone else done anything like this before and how would you recommend I make this system?
 
Level 39
Joined
Feb 27, 2007
Messages
5,010
You can adapt your approach to account for the problems you forsee. The first thing I would address is this:
If the only units left in the pool are matching types I cannot keep rolling the trigger as this would cause an infinite loop?
The only way to resolve this is to decide what behavior should happen when the remaining number of remaining unique unit types (call it T) is less than the number of shop slots (S). This could be simply impossible for T < S, if you do it right. Or perhaps the last S of the types always remain as pickable units. Or the 'empty' slots get filled with random units. Or... So you see you must decide.

When you have a list of T items from which you must pick S items, it's there's a simple way to 'remove' the picked options from the list temporarily. It's best shown by example:
  • -------- Set beforehand --------
  • Set T = (T + 1)
  • Set Type[T] = Footman
  • Set T = (T + 1)
  • Set Type[T] = Knight
  • Set T = (T + 1)
  • Set Type[T] = Tauren
  • ...
  • Set T_Max = T
  • -------- --------
  • Set Current_T = T_Max
  • Set S = 5
  • For each (Integer A) from 1 to S do (Actions)
    • Loop - Actions
      • Set RandomChoice = (Random number between 1 and Current_T)
      • Set Chosen[(Integer A)] = Type[T]
      • Set TempType = Type[Current_T]
      • Set Type[Current_T] = Type[RandomChoice]
      • Set Type[RandomChoice] = TempType
      • Set Current_T = (Current_T - 1)
  • -------- at this point Chosen[1] through Chosen[S] are assigned the S random choices from the list of T possibilities --------
  • -------- a new set of S possible immediately, but it's also possible to temporarily or permanently remove a type from the list arbitrarily (say you randomize S for a player, wait for them to pick one, and then remove it from the list) --------
  • -------- you must do the same swap process but using T_Max instead of Current_T --------
  • Set PickedType = (The unit type however you get it)
  • For each (Integer A) from 1 to T_Max do (Actions)
    • Loop - Actions
      • If (All conditions are true) then do (Then actions) else do (Else actions)
        • If - Conditions
          • Type[(Integer A)] equal to PickedType
        • Then - Actions
          • Set TempType = Type[T_Max]
          • Set Type[T_Max] = PickedType
          • Set Type[(Integer A)] = TempType
          • Set T_Max = (T_Max - 1)
          • Custom script: exitwhen true //exit loop early when we have found a match
  • -------- if you ever want it to become available again you must do the same find and replace but in the range [T_Max+1, T] and swap it into the T_Max+1th spot instead --------
  • Set PickedType = (The unit type however you get it)
  • For each (Integer A) from (T_Max + 1) to T do (Actions)
    • Loop - Actions
      • If (All conditions are true) then do (Then actions) else do (Else actions)
        • If - Conditions
          • Type[(Integer A)] equal to PickedType
        • Then - Actions
          • Set T_Max = (T_Max + 1) //simpler to do it first rather than after
          • Set TempType = Type[(T_Max)]
          • Set Type[(T_Max)] = PickedType
          • Set Type[(Integer A)] = TempType
          • Custom script: exitwhen true
 
Status
Not open for further replies.
Top