Page 1 of 1

How to store unit data

Posted: Tue Sep 25, 2012 10:26 pm
by like80ninjas
Okay lets say i'm making an rts where you create an army out of units beforehand, and deploy them to the field. Think of the units almost like trading cards, where a player could have any combination of possible units in there deck. Would it be better to use a single unit class, and instance it, then set it's stats and model equal to the unit it's suppose to represent? or should I take the unit class and inherit it down into every single possible monster/unit in the game? The latter seems a bit tedious but would compartmentalize the code... I really need some suggestions on this one!

Re: How to store unit data

Posted: Wed Sep 26, 2012 6:13 am
by bbguimaraes
If you can, a good way to handle this situation is to make a single "entity engine" which can create different units from different configurations. Example: entities have a moving behaviour, which can be walking, swiming or flying. Each entity would then be configured to move in one of these ways. The entity knows it has to move, but you configure it on how to do it.

Re: How to store unit data

Posted: Wed Sep 26, 2012 11:20 am
by like80ninjas
After much googling I decided to use a header with a huge table of static unit descriptions and just have a single unit class pull all of it's data from the table when it is instanced.

Re: How to store unit data

Posted: Wed Sep 26, 2012 11:33 am
by bbguimaraes
Be sure to talk about your implementation when you finish it!

Re: How to store unit data

Posted: Wed Sep 26, 2012 8:49 pm
by like80ninjas
Now I need to figure out how to transfer my mouse coordinates to world coordinates. I only need an x and z axis ( y is my up axis, but units are locked to terrain so I don't need it projected ). I've been trying to use all the tutorials I can find on GLunProject but every time it seems to not work properly, it gives me coordinates way off from my view and mouse input. I'm not great with 3d math but if someone could explain how to do it, I could probably figure it out.

Re: How to store unit data

Posted: Sun Sep 30, 2012 11:36 am
by XianForce
Well I would need more information to accurately analyze how you need to do it, but assuming it's top-downish and you "ignore the y", the x,y of screen coordinates may directly translate to x,z world coordinates?

Re: How to store unit data

Posted: Mon Oct 01, 2012 7:25 pm
by like80ninjas
Well, I have the game at about a 45 degree angle facing down toward the units in the game, I've been trying to use gluUnProject but I haven't been successful so far.

Re: How to store unit data

Posted: Mon Oct 01, 2012 8:19 pm
by like80ninjas
Code removed for privacy.

Re: How to store unit data

Posted: Mon Oct 01, 2012 8:40 pm
by like80ninjas
Nevermind guys, I solved the problem, the SFML function I used to get the mouse coordinates was giving it relative to the screen, not the window. Stupid mistake, but I feel it wasn't very clear in the function, the default behavior should be window relative, at least in my opinion.

Re: How to store unit data

Posted: Mon Oct 01, 2012 10:16 pm
by qpHalcy0n
SFML is likely grabbing them directly from system calls. In this case they will always be screen relative.
EX: In Win32, you might use "GetCursorPos", it does not take a HWND (window handle) parameter. How would it know to which window the cursor is relative to??

Point being, except global relativity in all cases, to be contrary might be too presumptive.