# RTS questions (unit system)

This topic is 4664 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Ok, this is a mock up of the object system that I currently have:
-CRenderable
+--CUnit (marine, tank, etc)
+--CBuilding (base, turret, etc)

-CObjectFactory

CRenderable* pObj = new CUnit;
//blah

pObj = new CUnit;
//blah
etc

My two questions are: 1)Am I going to have problems with my object factory when it comes to sorting (since CUnit and CBuilding will have different variables in them)? 2)Is this an okay (I'm not looking for perfect right now) object system (other than it needs to be expanded a little bit)? Thanks!

##### Share on other sites
Hypothetically, your CRenderable class should contain the coordinate data (x,y,w,h or whatever) for the unit, and you'll probably want to sort by (y+h), so you should be fine.

(assuming you want to sort them by y-value so they draw right without any depth testing)

##### Share on other sites
My CRenderable contains:
static CTextureManager*		m_pTextureMgr;static IDirect3DDevice9*	m_pDevice;D3DXVECTOR2			m_Position;dftge::CVertex			m_Vertices[4];dftge::CTexture*		m_pTexture;RECT				m_BoundingRect;float				m_fWidth, m_fHeight;

And they are sorted by Y+H.

##### Share on other sites
Well, I don't really see much of a problem beyond the fact that it might be a bit of a pain when you get down to gameplay programming and you have to identify the distinctions between a unit and a building.

A solution I would offer is to make a common interface for them - which may or may not be possible depending on how you've designed your game.

The way I designed my 4E4 crap (which was going to be an RTS) was to treat buildings and units exactly the same, except to give buildings a UNIT_IMMOBILE flag. This was primarily because there were quite a few units (pirate boats) which acted both as buildings and as units. But again, it was really a design decision.

In the end, you'll have to think out exactly what you'll need to do in terms of gameplay. I've coded myself into a paper bag *hundreds* of times because I didn't think of something I'd need, and not having it in there pretty much crippled everything else.

So yeah. You'll probably want to take the time to evaluate exactly what you want to do with your units, and if storing them using the factory method is the best idea or not. For me, it came down to "Why, exactly, makes a building different from a unit?" My answer, as mentioned, was that buildings couldn't move.

Granted, the 4E4 engine did implode on itself, so you might not want to trust my design advice (lol).

##### Share on other sites
Quote:
 Original post by MushuWell, I don't really see much of a problem beyond the fact that it might be a bit of a pain when you get down to gameplay programming and you have to identify the distinctions between a unit and a building.A solution I would offer is to make a common interface for them - which may or may not be possible depending on how you've designed your game.The way I designed my 4E4 crap (which was going to be an RTS) was to treat buildings and units exactly the same, except to give buildings a UNIT_IMMOBILE flag. This was primarily because there were quite a few units (pirate boats) which acted both as buildings and as units. But again, it was really a design decision.In the end, you'll have to think out exactly what you'll need to do in terms of gameplay. I've coded myself into a paper bag *hundreds* of times because I didn't think of something I'd need, and not having it in there pretty much crippled everything else.So yeah. You'll probably want to take the time to evaluate exactly what you want to do with your units, and if storing them using the factory method is the best idea or not. For me, it came down to "Why, exactly, makes a building different from a unit?" My answer, as mentioned, was that buildings couldn't move.Granted, the 4E4 engine did implode on itself, so you might not want to trust my design advice (lol).

lol

Thanks for all the help Mushu!

1. 1
Rutin
26
2. 2
3. 3
JoeJ
20
4. 4
5. 5

• 9
• 9
• 9
• 46
• 41
• ### Forum Statistics

• Total Topics
631750
• Total Posts
3002060
×