How to store unit data
Moderator: Coders of Rage
-
- Chaos Rift Regular
- Posts: 101
- Joined: Thu Dec 09, 2010 2:13 am
How to store unit data
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!
- bbguimaraes
- Chaos Rift Junior
- Posts: 294
- Joined: Wed Apr 11, 2012 4:34 pm
- Programming Language of Choice: c++
- Location: Brazil
- Contact:
Re: How to store unit data
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.
-
- Chaos Rift Regular
- Posts: 101
- Joined: Thu Dec 09, 2010 2:13 am
Re: How to store unit data
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.
- bbguimaraes
- Chaos Rift Junior
- Posts: 294
- Joined: Wed Apr 11, 2012 4:34 pm
- Programming Language of Choice: c++
- Location: Brazil
- Contact:
Re: How to store unit data
Be sure to talk about your implementation when you finish it!
-
- Chaos Rift Regular
- Posts: 101
- Joined: Thu Dec 09, 2010 2:13 am
Re: How to store unit data
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
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?
-
- Chaos Rift Regular
- Posts: 101
- Joined: Thu Dec 09, 2010 2:13 am
Re: How to store unit data
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.
-
- Chaos Rift Regular
- Posts: 101
- Joined: Thu Dec 09, 2010 2:13 am
Re: How to store unit data
Code removed for privacy.
Last edited by like80ninjas on Mon Oct 01, 2012 8:40 pm, edited 1 time in total.
-
- Chaos Rift Regular
- Posts: 101
- Joined: Thu Dec 09, 2010 2:13 am
Re: How to store unit data
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.
-
- Respected Programmer
- Posts: 387
- Joined: Fri Dec 19, 2008 3:33 pm
- Location: Dallas
- Contact:
Re: How to store unit data
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.
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.