Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm working in a group with 2 friends on our Gr. 12 final project for programming. We're making a multiplayer RTS game. I've been assigned to the networking section of the game, and none of us have any experience doing network programming.

We've established that we'll have the server process everything such as path finding, build queues etc. The client will receive packets from the server, which will contain information such as HP, x, y, etc of each unit/building (Well, the server will send a packet whenever a unit/building's state such as losing HP, movements etc is changed).

The problem is identifying which unit the packet contains information for. I've thought of generating a number as an ID for each unit/building, and storing the units in a map data structure, where the key is the ID. Is there a better way to do this? How do most RTS games do it?

share|improve this question

2 Answers 2

up vote 1 down vote accepted

Your technique will be sufficient. Since you seem to understand how to do it and what needs to be done, for this situation, it's the best way to go.

As it is with many decisions like this in programming, you'll have to consider your requirements and see what your budget allows. Your budget is the time you have to complete the project. You know your requirements better than anyone here would.

So if storing an integer for each unit and building meets your requirements, and you think you can do it in the time allowed, go for it. It's not a bad way of doing things, and I don't foresee any major problems with doing it that way.

share|improve this answer
    
Really? Wow. Usually when I come up with algorithms for important things, there's always a faster/better way to do it. Cool. Thanks for the help –  Alex Yan Dec 20 '12 at 19:22
    
Oh, there's undoubtedly a better/faster way of doing it. But it wouldn't be reasonable to put that much time into designing it and implementing it. When a simpler way works well enough, it's best to stick with it. –  Byte56 Dec 20 '12 at 19:32

Your approach isn't a bad one and there's a lot you can do with it. However, since you're a novice at network programming as you have stated I'm sure there's a lot of things you might not be aware of. The Age of Empires team was already down this road once and you could probably learn a lot from them. Check out this article. You'll be glad you did!

share|improve this answer
1  
I think the question was about applying incoming data to units/buildings. Not about how to transmit the data. –  Byte56 Dec 20 '12 at 21:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.