3
\$\begingroup\$

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?

\$\endgroup\$

2 Answers 2

1
\$\begingroup\$

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.

\$\endgroup\$
2
  • \$\begingroup\$ 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 \$\endgroup\$
    – Alex
    Dec 20, 2012 at 19:22
  • \$\begingroup\$ 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. \$\endgroup\$
    – House
    Dec 20, 2012 at 19:32
0
\$\begingroup\$

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!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ I think the question was about applying incoming data to units/buildings. Not about how to transmit the data. \$\endgroup\$
    – House
    Dec 20, 2012 at 21:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .