• Advertisement
Sign in to follow this  

RTS questions (unit system)

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

If you intended to correct an error in the post then please contact us.

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
g_ObjFactory.AddObject(pObj);

pObj = new CUnit;
//blah
g_ObjFactory.AddObject(pObj);
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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by Mushu
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).


lol

I'll have to think about this, because some of my buildings will be able to move.

Thanks for all the help Mushu!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement