J
JoeC
Nathan said:Managing "who's where" is best separated from the "combat routine."
Most games have some code (and data structures) dedicated to keeping
track of units on the map. This means that units know where they are,
and the map manager also knows which units are where. If your map is
just a 2D array of a fixed, "reasonable" size (under a million
entries), you can just make a 2D array of entries, and each entry is
just a linked list of all units in that cell. If you're working on
PCs, just burn some memory upfront, and work on optimizing it later--
plenty of data structures exist to manage sparse datasets.
You should also separate out code to to map manager so that you can
say "find all units within radius R of point X,Y" and it'll go do that
for you. That's code for the map manager, not a "combat routine," as
you'll probably want your UI code to be able to do the same thing--
clicking on a square selects all units in that square, or shift-drag
selects all units in a user-specified rectangle. If you're going to
use the same kinds of functionality in multiple places, then break it
out to a common place.
Nathan Mates
--
Thanks for the advice. I am not realy sure how to implement that into
my program. I would have to seem some kind of example of how to do
that. I hope my program is not too far along to impleent a map handler.