selecting multiple entity and controling them

Community Forums/General Help/selecting multiple entity and controling them

NotAGamer(Posted 2016) [#1]
like in the age of empires,dota and such games.
what is the best way to do this?


Derron(Posted 2016) [#2]
global selectedUnits:TUnit[]

-> fill the array with the units you want to have selected

In your update/draw then list all units in the array etc.

controlling:
If you send one, send all (send the same command to all units in "selectedUnits" - eg. Move(x,y) or Attack(unitGUID).


bye
Ron


Kryzon(Posted 2016) [#3]
That's a complex question, involving several topics.
Probably the one that will cover most of what you want is 'finite state machines'.

There's plenty of material online, you need to search for it. Here's a start:
- http://iadbungler.free.fr/bcoder/cgi-bin/articles/Wcc022af96ec8c.htm
- http://gameprogrammingpatterns.com/state.html
- http://gamedevelopment.tutsplus.com/tutorials/finite-state-machines-theory-and-implementation--gamedev-11867

The reason why a state machine is relevant is because when you give one or more units a command, you are in fact changing their state from [whatever they are doing] to [follow this command].


Matty(Posted 2016) [#4]
Another way is to have a flag in your units object called 'selected' which gets set to true (in addition to creating a list of indexes to the array/object holding your units)

If the unit is marked as 'selected' draw a box around it or whatever other indicators you wish to use.

If the unit is marked as selected then apply commands to it depending on what is clicked.

Eg ground clicked with right mouse button - apply target movement position to selected units.

Eg enemy unit clicked with right mouse button - apply 'attack target id' to selected units.


NotAGamer(Posted 2016) [#5]
thank you guys this is very helpful..

im making a 3DTPOSRTSRPG ( 3D third person over the shoulder real time strategy Role playing game )

this is very helpful..thanks


RemiD(Posted 2016) [#6]
i see 2 ways to manage this :
-for each entity, have a variable "selectionstate" (true or false)
-have another list "selectedentities" where you store the handles/indexes (typelist, or dimarraylist) of the selected entities


Derron(Posted 2016) [#7]
The unit itself does not need to know of whether it is selected or not ... also imagine you have 1000.000 units on the map ... now you store "selected" as a field for each of them. Really a waste of memory.

So for information not needed for the unit, it is better to have it stored elsewhere.

Means: when selecting a unit, store that information like told in a special array/list/group-type/...
To allow special things (eg. you want to make the unit "salute" when getting selected): call a unit-method like "onSelect()" (so extended unit types _could_ itself have a "selected"-field...if they really desire).

When updating/drawing the interface, you could use your "selectedUnits"-thingy to draw avatars of all of them in a special area.


Now to break aboves thoughts again: if your units need to know about their state, than a flag ("selected") is good: so eg. you want to run code differently when selected or not.


Now to break this again: As "selected" is something the unit does not need to care about, you can always send that information to the unit if desired: "Method Update(isSelected:int = False)".


So do not get me wrong now, I do not say: do not have a "selected"-flag for each unit - but many roads lead to rome and it all depends on eg. the amount of units you want to simulate and about what information each unit needs to know about.
It is also a matter of "decoupling" things.



bye
Ron


NotAGamer(Posted 2016) [#8]
Thanks guys! i've got it now.. :)

this is a very good forum indeed :)

p.s. the gameplay has taken inspiration from shiny entertaiment's "sacrifice" but of course i-added my ideas:) thanks!