RTS game help - selecting units

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
esaptonor
Posts: 145
Joined: Sat May 06, 2006 11:59 pm

RTS game help - selecting units

Post by esaptonor »

I have looked around and i am not sure how i am ment to do this.

i think i should have a unit class, and it looks after all data etc including its Scene node, but how should i 'select' it?
I so far think i should be getting the scene node with getSceneNodeFromScreenCoordinatesBB method, but how do i get the unit class from that so i can make its selected variable true?

i hope that was clear enough to understand,
esaptonor
Gatekeeper
Posts: 31
Joined: Fri Apr 21, 2006 12:00 am
Location: Australia

Post by Gatekeeper »

I've done something similar, although it was easier for me because I only have a few selectable "things".

Give each unit a unique ID. When you make a scene node, pass the units ID as the scene node ID.

Then when the user selects a unit, you can find out what node they are selecting (using getSceneNodeFromScreenCoordinatesBB() like you said). Get this node's ID, and then you can figure out what unit has been selected. I suggest you write a helper function like "getUnitFromNodeID()" that returns a pointer to the unit.

I guess because it's an RTS you would want to select a number of units, so you could use the same concept but put everything in linked lists or an array. I don't know how you would use getSceneNodeFromScreenCoordinatesBB to get all of the nodes over an area though.

One other thing, notice how you can apply a bitmask to the getSceneNodeFromScreenCoordinatesBB? Basically, I gave all of the nodes that can't be selected (trees, ground, cucumbers) an ID below 0xFF, and all selectable objects an ID above 0xFF, so that I could use this bitmask to just get back stuff from getSceneNodeFromScreenCoordinatesBB() that could be selected.

Hope this helps.
esaptonor
Posts: 145
Joined: Sat May 06, 2006 11:59 pm

Post by esaptonor »

thanks, that helps heaps, i was wondering what that bitmask was for!

what do you suggest occurs with finding out if the unit is an enemy or not? would i have to go all the way from the node to the unit class and check what side its on? or could it be done with the bitmask?
esaptonor
Posts: 145
Joined: Sat May 06, 2006 11:59 pm

Post by esaptonor »

I think i have most of it sorted out, but i have no idea how that bitmask works. If all my units have IDs between 5000 and 10000 how do i make it only able to select them?
tried various numbers, but since i dont know how it works, i dont know how to make it work.
jam
Posts: 409
Joined: Fri Nov 04, 2005 3:52 am

Post by jam »

Not sure if this will help you, but it was a good thread about bitmask's.

Link
system-independent, adj.:
Works equally poorly on all systems.
-- unknown
Post Reply