GameMaker Trying to figure out pikmin style unit selection

In pikmin, You can either throw the next pikmin you have in line. Or you can press a button to only throw a specific type. I've been having a hell of a time how to implement this.



In it's basic form. I need to figure out how to select specific and any unit in a group.

ds_queue does work initially. But then you can't sort through units. you can only select the one at the head.

ds_priority queue only works at the beginning or end. you can select unit group 1 or 3, but not 2.

Right now I'm trying to figure out how to use ds_grid to map out the units. but now I can't get the size of the group easily.

ds_list doesn't work with objects.

create event
Code:
dragonline=ds_grid_create(10,100)

for(var i=1;i<101;i++)
{
    dragon=choose(oEarthdragon,oWaterdragon,oFiredragon)
 this= instance_create_layer(x,y,"instances",dragon)
this.position=i
ds_grid_add(dragonline,0,i,this)
}
step event
Code:
//throwing action
if    mouse_check_button_pressed(mb_left)
{  
        switch(hand)
        {
            case 0:
            //get the first dragon in the queque, doesn't matter what's there
            var thisdragon =dragonline[# 0, 1]
                   
            thisdragon.action=dragon_hold

            break;
            case 1:
            //only get earthdragons
            for(var i=1;i<101;i++)
            {
                if dragonline[# 0,i] = oEarthdragon
                {
                    dragonline[# 0,i].action=dragon_hold
                    //
                }
            }
            break;
        }
}
this is about as far I got with using grids. I can figure you can search for units within the grid.
But then you have to move down all the units to fill the space left. which I can't grasp.

this is just testing code for now.

What's the best way to do this?
 
R

robproctor83

Guest
That's pretty cool, I like the look of it so far!

Yes, you should be storing the ID's.

For the unit selection, you could have an array of priority queues, so dragons[0] are normal, dragons[1] are earth, and so on... But, it depends on what you want exactly. The problem you are going to run in with the grid is you will have to manually reshuffle things around after removing one from the grid, or keep track of the last position you were going from. Also, when adding new units the grid will need to be resynced properly. For this particular kind of thing a queue seems more appropriate, but it really just depends.
 
That's pretty cool, I like the look of it so far!

Yes, you should be storing the ID's.

For the unit selection, you could have an array of priority queues, so dragons[0] are normal, dragons[1] are earth, and so on... But, it depends on what you want exactly. The problem you are going to run in with the grid is you will have to manually reshuffle things around after removing one from the grid, or keep track of the last position you were going from. Also, when adding new units the grid will need to be resynced properly. For this particular kind of thing a queue seems more appropriate, but it really just depends.
This probably means I should find another way to command units around if it gets this complex.
I'll try to look deeper to how pikmin does this specifically.

Initially, the pikmin that are following the leader aren't in a precise order. The closest pikmin is the one that will be thrown. However once you throw them. the pikmin order themselves, with the type selected being the group that goes first. You can press a button, once they're in order to shift to the next type.

this is what happens in pikmin 1 and 2.

In pikmin 3. it seems the first pikmin that summoned, is the type that you throw first, you can't throw just any pikmin anymore. this is dynamic, as the group gains and loses pikmin. you get icons on your hud that appear in the order of the pikmin you whistle to your group. you can shuffle the order of the pikmin in your group if you need a specific type for the situation.

the swarm is doesn't actually keep track of the pikmin order, until you begin throwing one. or it's first come first serve in 3. the pikmin in either case just teleport to the leader's hand.
____________________

So What I need to do is.

when dragons are whistled to the leader. their order in the swarm is based on first come first serve. the first dragon that is summoned is also the first type to be thrown and so on..but this doesn't effect the swarm actively. when more dragons are whistled. they will take up the empty spots.

3 seperate queue will hold all dragon id's of the same type. That queue will be...put in a priority queue? is that possible?
Or maybe the queue can be put in an array. when the queue size is 0. it will move on to the next queue in the array. until all dragons are thrown.
If I need a different type, I can press a button to move up the array instead of the queue.
Am I thinking this correctly? or am I way off?
 

TheouAegis

Member
I would just use a list. Don't use queues. A normal old fashioned list will work just fine. It has all the sorting of a queue, but can be iterated through. For throwing the first instance in the list, you fetch index 0 and then delete it. That will cause everything else to move up. For picking the first of a specific unit, loop through the list starting with index 0, then for each element in the list, check it's object_index. If the object index is what you are looking for, then break the loop, fetch the ID from the list, then delete that element.
 
Last edited:
Top